-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add grantee signer client and related updates (#44)
* Add grantee signer client and related updates * granteeSigner testing flow; fix lint errors * fix MsgExec encoding issue; clean up demo app --------- Co-authored-by: Burnt Val <[email protected]>
- Loading branch information
1 parent
b38f8dc
commit 56b9f87
Showing
10 changed files
with
276 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@burnt-labs/abstraxion": minor | ||
--- | ||
|
||
Add grantee signer client to seamlessly handle grantor/grantee relationships |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { | ||
DeliverTxResponse, | ||
SigningCosmWasmClient, | ||
SigningCosmWasmClientOptions, | ||
} from "@cosmjs/cosmwasm-stargate"; | ||
import { EncodeObject, OfflineSigner } from "@cosmjs/proto-signing"; | ||
import { SignerData, StdFee } from "@cosmjs/stargate"; | ||
import type { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx"; | ||
import { MsgExec } from "cosmjs-types/cosmos/authz/v1beta1/tx"; | ||
import { | ||
HttpEndpoint, | ||
Tendermint37Client, | ||
TendermintClient, | ||
} from "@cosmjs/tendermint-rpc"; | ||
|
||
interface GranteeSignerOptions { | ||
readonly grantorAddress: string; | ||
readonly granteeAddress: string; | ||
} | ||
|
||
export class GranteeSignerClient extends SigningCosmWasmClient { | ||
protected readonly grantorAddress: string; | ||
protected readonly granteeAddress: string; | ||
|
||
public static async connectWithSigner( | ||
endpoint: string | HttpEndpoint, | ||
signer: OfflineSigner, | ||
options: SigningCosmWasmClientOptions & GranteeSignerOptions, | ||
): Promise<GranteeSignerClient> { | ||
const tmClient = await Tendermint37Client.connect(endpoint); | ||
return GranteeSignerClient.createWithSigner(tmClient, signer, options); | ||
} | ||
|
||
public static async createWithSigner( | ||
cometClient: TendermintClient, | ||
signer: OfflineSigner, | ||
options: SigningCosmWasmClientOptions & GranteeSignerOptions, | ||
): Promise<GranteeSignerClient> { | ||
return new GranteeSignerClient(cometClient, signer, options); | ||
} | ||
|
||
protected constructor( | ||
cometClient: TendermintClient | undefined, | ||
signer: OfflineSigner, | ||
{ | ||
grantorAddress, | ||
granteeAddress, | ||
...options | ||
}: SigningCosmWasmClientOptions & GranteeSignerOptions, | ||
) { | ||
super(cometClient, signer, options); | ||
if (grantorAddress === undefined) { | ||
throw new Error("grantorAddress is required"); | ||
} | ||
this.grantorAddress = grantorAddress; | ||
|
||
if (granteeAddress === undefined) { | ||
throw new Error("granteeAddress is required"); | ||
} | ||
this.granteeAddress = granteeAddress; | ||
} | ||
|
||
public async signAndBroadcast( | ||
signerAddress: string, | ||
messages: readonly EncodeObject[], | ||
fee: StdFee | "auto" | number, | ||
memo = "", | ||
): Promise<DeliverTxResponse> { | ||
// Figure out if the signerAddress is a grantor | ||
if (signerAddress === this.grantorAddress) { | ||
signerAddress = this.granteeAddress; | ||
// Wrap the signerAddress in a MsgExec | ||
messages = [ | ||
{ | ||
typeUrl: "/cosmos.authz.v1beta1.MsgExec", | ||
value: MsgExec.fromPartial({ | ||
grantee: this.granteeAddress, | ||
msgs: messages.map((msg) => this.registry.encodeAsAny(msg)), | ||
}), | ||
}, | ||
]; | ||
} | ||
|
||
return super.signAndBroadcast(signerAddress, messages, fee, memo); | ||
} | ||
|
||
public async sign( | ||
signerAddress: string, | ||
messages: readonly EncodeObject[], | ||
fee: StdFee, | ||
memo: string, | ||
explicitSignerData?: SignerData, | ||
): Promise<TxRaw> { | ||
// Figure out if the signerAddress is a grantor | ||
if (signerAddress === this.grantorAddress) { | ||
signerAddress = this.granteeAddress; | ||
// Wrap the signerAddress in a MsgExec | ||
messages = [ | ||
{ | ||
typeUrl: "/cosmos.authz.v1beta1.MsgExec", | ||
value: MsgExec.fromPartial({ | ||
grantee: signerAddress, | ||
msgs: messages.map((msg) => this.registry.encodeAsAny(msg)), | ||
}), | ||
}, | ||
]; | ||
} | ||
|
||
return super.sign(signerAddress, messages, fee, memo, explicitSignerData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
56b9f87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
xion-js-abstraxion-dashboard – ./apps/abstraxion-dashboard
xion-js-abstraxion-dashboard-burntfinance.vercel.app
xion-js-abstraxion-dashboard.vercel.app
xion-js-abstraxion-dashboard-git-main-burntfinance.vercel.app
dashboard.burnt.com