From fd126a4403d48795c6e1076e7d656f3de8e3091c Mon Sep 17 00:00:00 2001 From: Fabrice Bascoulergue Date: Thu, 2 Dec 2021 14:29:59 +0100 Subject: [PATCH 1/5] Update auto generated doc --- docs/lib/classes/lumclient.md | 2 +- docs/lib/classes/lumpaperwallet.md | 8 +-- docs/lib/classes/lumwalletfactory.md | 38 +++++++-------- docs/lib/interfaces/lumtypes.account.md | 42 ++++++++++++++++ docs/lib/interfaces/lumtypes.log.md | 2 +- docs/lib/modules/lummessages.md | 30 +++++++++++- docs/lib/modules/lumutils.md | 65 ++++++++++++++++++++++--- 7 files changed, 153 insertions(+), 34 deletions(-) diff --git a/docs/lib/classes/lumclient.md b/docs/lib/classes/lumclient.md index ac9d458..a861593 100644 --- a/docs/lib/classes/lumclient.md +++ b/docs/lib/classes/lumclient.md @@ -56,7 +56,7 @@ ___ ### queryClient -• `Readonly` **queryClient**: `QueryClient` & `AuthExtension` & `AuthzExtension` & `BankExtension` & `BeamExtension` & `DistributionExtension` & `GovExtension` & `IbcExtension` & `MintExtension` & `StakingExtension` & `SlashingExtension` & `FeegrantExtension` +• `Readonly` **queryClient**: `QueryClient` & `AuthExtension` & `AuthzExtension` & `BankExtension` & `BeamExtension` & `DistributionExtension` & `GovExtension` & `IbcExtension` & `MintExtension` & `StakingExtension` & `SlashingExtension` & `FeegrantExtension` & `AirdropExtension` ___ diff --git a/docs/lib/classes/lumpaperwallet.md b/docs/lib/classes/lumpaperwallet.md index c4def32..87f8a80 100644 --- a/docs/lib/classes/lumpaperwallet.md +++ b/docs/lib/classes/lumpaperwallet.md @@ -233,10 +233,10 @@ Change the wallet to use #### Parameters -| Name | Type | -| :------ | :------ | -| `hdPath` | `string` | -| `addressPrefix` | `string` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `hdPath` | `string` | `undefined` | +| `addressPrefix` | `string` | `LumConstants.LumBech32PrefixAccAddr` | #### Returns diff --git a/docs/lib/classes/lumwalletfactory.md b/docs/lib/classes/lumwalletfactory.md index df257ee..1deb755 100644 --- a/docs/lib/classes/lumwalletfactory.md +++ b/docs/lib/classes/lumwalletfactory.md @@ -30,11 +30,11 @@ Create a LumWallet instance based on a keystore #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `keystore` | `string` \| [`KeyStore`](../interfaces/LumUtils.KeyStore.md) | keystore used to decypher the private key | -| `password` | `string` | keystore password | -| `addressPrefix` | `string` | prefix to use to derive the address from the public key (ex: lum) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `keystore` | `string` \| [`KeyStore`](../interfaces/LumUtils.KeyStore.md) | `undefined` | keystore used to decypher the private key | +| `password` | `string` | `undefined` | keystore password | +| `addressPrefix` | `string` | `LumConstants.LumBech32PrefixAccAddr` | prefix to use to derive the address from the public key (ex: lum) | #### Returns @@ -50,11 +50,11 @@ Create a LumWallet instance based on a ledger transport #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `transport` | `default` | Ledger transport to use (https://github.com/LedgerHQ/ledgerjs) | -| `hdPath` | `string` | BIP44 derivation path | -| `addressPrefix` | `string` | prefix to use to derive the address from the public key (ex: lum) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `transport` | `default` | `undefined` | Ledger transport to use (https://github.com/LedgerHQ/ledgerjs) | +| `hdPath` | `string` | `undefined` | BIP44 derivation path | +| `addressPrefix` | `string` | `LumConstants.LumBech32PrefixAccAddr` | prefix to use to derive the address from the public key (ex: lum) | #### Returns @@ -70,11 +70,11 @@ Create a LumWallet instance based on a mnemonic and a derivation path #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `mnemonic` | `string` | mnemonic used to derive the private key | -| `hdPath` | `string` | BIP44 derivation path | -| `addressPrefix` | `string` | prefix to use to derive the address from the public key (ex: lum) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `mnemonic` | `string` | `undefined` | mnemonic used to derive the private key | +| `hdPath` | `string` | `undefined` | BIP44 derivation path | +| `addressPrefix` | `string` | `LumConstants.LumBech32PrefixAccAddr` | prefix to use to derive the address from the public key (ex: lum) | #### Returns @@ -108,10 +108,10 @@ Create a LumWallet instance based on a private key (secp256k1) #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `privateKey` | `Uint8Array` | wallet private key (secp256k1) | -| `addressPrefix` | `string` | prefix to use to derive the address from the public key (ex: lum) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `privateKey` | `Uint8Array` | `undefined` | wallet private key (secp256k1) | +| `addressPrefix` | `string` | `LumConstants.LumBech32PrefixAccAddr` | prefix to use to derive the address from the public key (ex: lum) | #### Returns diff --git a/docs/lib/interfaces/lumtypes.account.md b/docs/lib/interfaces/lumtypes.account.md index ac8346e..52b997f 100644 --- a/docs/lib/interfaces/lumtypes.account.md +++ b/docs/lib/interfaces/lumtypes.account.md @@ -6,12 +6,48 @@ ### Properties +- [\_baseVestingAccount](LumTypes.Account.md#_basevestingaccount) +- [\_continuousVestingAccount](LumTypes.Account.md#_continuousvestingaccount) +- [\_delayedVestingAccount](LumTypes.Account.md#_delayedvestingaccount) +- [\_moduleAccount](LumTypes.Account.md#_moduleaccount) +- [\_periodicVestingAccount](LumTypes.Account.md#_periodicvestingaccount) - [accountNumber](LumTypes.Account.md#accountnumber) - [address](LumTypes.Account.md#address) +- [pubkey](LumTypes.Account.md#pubkey) - [sequence](LumTypes.Account.md#sequence) ## Properties +### \_baseVestingAccount + +• `Optional` `Readonly` **\_baseVestingAccount**: `BaseVestingAccount` + +___ + +### \_continuousVestingAccount + +• `Optional` `Readonly` **\_continuousVestingAccount**: `ContinuousVestingAccount` + +___ + +### \_delayedVestingAccount + +• `Optional` `Readonly` **\_delayedVestingAccount**: `DelayedVestingAccount` + +___ + +### \_moduleAccount + +• `Optional` `Readonly` **\_moduleAccount**: `ModuleAccount` + +___ + +### \_periodicVestingAccount + +• `Optional` `Readonly` **\_periodicVestingAccount**: `PeriodicVestingAccount` + +___ + ### accountNumber • `Readonly` **accountNumber**: `number` @@ -24,6 +60,12 @@ ___ ___ +### pubkey + +• `Readonly` **pubkey**: ``null`` \| `Pubkey` + +___ + ### sequence • `Readonly` **sequence**: `number` diff --git a/docs/lib/interfaces/lumtypes.log.md b/docs/lib/interfaces/lumtypes.log.md index 6fe0b95..6e8feb0 100644 --- a/docs/lib/interfaces/lumtypes.log.md +++ b/docs/lib/interfaces/lumtypes.log.md @@ -8,7 +8,7 @@ - [events](LumTypes.Log.md#events) - [log](LumTypes.Log.md#log) -- [msg_index](LumTypes.Log.md#msg_index) +- [msg\_index](LumTypes.Log.md#msg_index) ## Properties diff --git a/docs/lib/modules/lummessages.md b/docs/lib/modules/lummessages.md index f451948..a557fe3 100644 --- a/docs/lib/modules/lummessages.md +++ b/docs/lib/modules/lummessages.md @@ -11,6 +11,7 @@ - [MsgBeginRedelegateUrl](LumMessages.md#msgbeginredelegateurl) - [MsgClaimBeamUrl](LumMessages.md#msgclaimbeamurl) - [MsgCreateValidatorUrl](LumMessages.md#msgcreatevalidatorurl) +- [MsgCreateVestingAccountUrl](LumMessages.md#msgcreatevestingaccounturl) - [MsgDelegateUrl](LumMessages.md#msgdelegateurl) - [MsgDepositUrl](LumMessages.md#msgdepositurl) - [MsgEditValidatorUrl](LumMessages.md#msgeditvalidatorurl) @@ -37,6 +38,7 @@ - [BuildMsgBeginRedelegate](LumMessages.md#buildmsgbeginredelegate) - [BuildMsgClaimBeam](LumMessages.md#buildmsgclaimbeam) - [BuildMsgCreateValidator](LumMessages.md#buildmsgcreatevalidator) +- [BuildMsgCreateVestingAccount](LumMessages.md#buildmsgcreatevestingaccount) - [BuildMsgDelegate](LumMessages.md#buildmsgdelegate) - [BuildMsgDeposit](LumMessages.md#buildmsgdeposit) - [BuildMsgEditValidator](LumMessages.md#buildmsgeditvalidator) @@ -78,6 +80,12 @@ ___ ___ +### MsgCreateVestingAccountUrl + +• **MsgCreateVestingAccountUrl**: ``"/cosmos.vesting.v1beta1.MsgCreateVestingAccount"`` + +___ + ### MsgDelegateUrl • **MsgDelegateUrl**: ``"/cosmos.staking.v1beta1.MsgDelegate"`` @@ -194,7 +202,7 @@ ___ ### MsgWithdrawValidatorCommissionUrl -• **MsgWithdrawValidatorCommissionUrl**: ``"/cosmos.bank.v1beta1.MsgSend"`` +• **MsgWithdrawValidatorCommissionUrl**: ``"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"`` ## Functions @@ -257,6 +265,26 @@ ___ ___ +### BuildMsgCreateVestingAccount + +▸ `Const` **BuildMsgCreateVestingAccount**(`fromAddress`, `toAddress`, `amount`, `endTime`, `delayed`): [`Message`](../interfaces/LumMessages.Message.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `fromAddress` | `string` | +| `toAddress` | `string` | +| `amount` | [`Coin`](../interfaces/LumTypes.Coin.md)[] | +| `endTime` | `Long` | +| `delayed` | `boolean` | + +#### Returns + +[`Message`](../interfaces/LumMessages.Message.md) + +___ + ### BuildMsgDelegate ▸ `Const` **BuildMsgDelegate**(`delegatorAddress`, `validatorAddress`, `amount?`): [`Message`](../interfaces/LumMessages.Message.md) diff --git a/docs/lib/modules/lumutils.md b/docs/lib/modules/lumutils.md index b8c19bc..bf47b64 100644 --- a/docs/lib/modules/lumutils.md +++ b/docs/lib/modules/lumutils.md @@ -8,9 +8,11 @@ ### Functions +- [accountFromAny](LumUtils.md#accountfromany) - [broadcastTxCommitSuccess](LumUtils.md#broadcasttxcommitsuccess) - [broadcastTxSyncSuccess](LumUtils.md#broadcasttxsyncsuccess) - [convertUnit](LumUtils.md#convertunit) +- [estimatedVesting](LumUtils.md#estimatedvesting) - [generateAuthInfoBytes](LumUtils.md#generateauthinfobytes) - [generateKeyStore](LumUtils.md#generatekeystore) - [generateMnemonic](LumUtils.md#generatemnemonic) @@ -47,6 +49,22 @@ ## Functions +### accountFromAny + +▸ `Const` **accountFromAny**(`input`): [`Account`](../interfaces/LumTypes.Account.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `input` | `Any` | + +#### Returns + +[`Account`](../interfaces/LumTypes.Account.md) + +___ + ### broadcastTxCommitSuccess ▸ `Const` **broadcastTxCommitSuccess**(`response`): `boolean` @@ -108,6 +126,37 @@ the amount converted ___ +### estimatedVesting + +▸ `Const` **estimatedVesting**(`account`, `t?`, `denom?`): `Object` + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `account` | [`Account`](../interfaces/LumTypes.Account.md) | `undefined` | +| `t?` | `Date` | `undefined` | +| `denom` | `string` | `LumConstants.MicroLumDenom` | + +#### Returns + +`Object` + +| Name | Type | +| :------ | :------ | +| `endsAt` | `Date` | +| `lockedBankCoins` | [`Coin`](../interfaces/LumTypes.Coin.md) | +| `lockedCoins` | [`Coin`](../interfaces/LumTypes.Coin.md) | +| `lockedDelegatedCoins` | [`Coin`](../interfaces/LumTypes.Coin.md) | +| `lockedPercentage` | `number` | +| `startsAt` | `Date` | +| `time` | `Date` | +| `totalCoins` | [`Coin`](../interfaces/LumTypes.Coin.md) | +| `unlockedCoins` | [`Coin`](../interfaces/LumTypes.Coin.md) | +| `unlockedPercentage` | `number` | + +___ + ### generateAuthInfoBytes ▸ `Const` **generateAuthInfoBytes**(`docSigners`, `fee`, `signMode`): `Uint8Array` @@ -263,10 +312,10 @@ Derives a bech32 wallet address from a public key (secp256k1) #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `publicKey` | `Uint8Array` | public key to derive the address from | -| `prefix` | `string` | address prefix to use (ex: lum) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `publicKey` | `Uint8Array` | `undefined` | public key to derive the address from | +| `prefix` | `string` | `LumBech32PrefixAccAddr` | address prefix to use (ex: lum) | #### Returns @@ -377,10 +426,10 @@ Verify that a wallet address is valid #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `address` | `string` | address to check | -| `prefix` | `undefined` \| `string` | prefix to check (will not be checked if not provided) | +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `address` | `string` | `undefined` | address to check | +| `prefix` | `undefined` \| `string` | `LumBech32PrefixAccAddr` | prefix to check (will not be checked if not provided) | #### Returns From f4380ace3ed17411356402294d5e9d63180b229c Mon Sep 17 00:00:00 2001 From: Fabrice Bascoulergue <3663159+lebascou@users.noreply.github.com> Date: Mon, 3 Jan 2022 19:00:17 +0100 Subject: [PATCH 2/5] Implement full offline signer capability (#37) * Improve abstraction to handle amino offline signer * Bump version to 0.7.2 * Remove useless double check which might cause reflection issues * Fix offline signing Co-authored-by: Fabrice Bascoulergue --- docs/lib/classes/lumwalletfactory.md | 2 +- package.json | 2 +- src/wallet/LumOfflineSignerWallet.ts | 67 ++++++++++++++++++-------- src/wallet/LumWalletFactory.ts | 4 +- tests/wallet.test.ts | 70 ++++++++++++++++++++++++---- 5 files changed, 114 insertions(+), 31 deletions(-) diff --git a/docs/lib/classes/lumwalletfactory.md b/docs/lib/classes/lumwalletfactory.md index 1deb755..ef19490 100644 --- a/docs/lib/classes/lumwalletfactory.md +++ b/docs/lib/classes/lumwalletfactory.md @@ -92,7 +92,7 @@ Create a LumWallet instance based on an OfflineDirectSigner instance compatible | Name | Type | Description | | :------ | :------ | :------ | -| `offlineSigner` | `OfflineDirectSigner` | OfflineDirectSigner instance compatible with Comsjs based implementations | +| `offlineSigner` | `OfflineSigner` | OfflineDirectSigner instance compatible with Comsjs based implementations | #### Returns diff --git a/package.json b/package.json index 2c32d8b..ccdf3e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lum-network/sdk-javascript", - "version": "0.7.1", + "version": "0.7.2", "license": "Apache-2.0", "description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.", "homepage": "https://github.com/lum-network/sdk-javascript#readme", diff --git a/src/wallet/LumOfflineSignerWallet.ts b/src/wallet/LumOfflineSignerWallet.ts index 74a9e0c..9127798 100644 --- a/src/wallet/LumOfflineSignerWallet.ts +++ b/src/wallet/LumOfflineSignerWallet.ts @@ -1,27 +1,33 @@ -import { OfflineDirectSigner } from '@cosmjs/proto-signing'; +import Long from 'long'; +import { OfflineAminoSigner } from '@cosmjs/amino'; +import { OfflineSigner, OfflineDirectSigner } from '@cosmjs/proto-signing'; import { SignMode } from '../codec/cosmos/tx/signing/v1beta1/signing'; -import { LumUtils, LumTypes, LumConstants } from '..'; +import { LumUtils, LumTypes, LumConstants, LumAminoRegistry } from '..'; import { LumWallet } from '.'; -import Long from 'long'; export class LumOfflineSignerWallet extends LumWallet { - private readonly offlineSigner: OfflineDirectSigner; + private readonly offlineSigner: OfflineSigner; /** - * Create a LumOfflineSignerWallet instance based on an OfflineDirectSigner instance compatible with Comsjs based + * Create a LumOfflineSignerWallet instance based on an OfflineSigner instance compatible with Comsjs based * implementations. * This constructor is not intended to be used directly as it does not initialize the underlying key pair * Better use the provided static LumPaperWallet builders * * @param mnemonicOrPrivateKey mnemonic (string) used to derive the private key or private key (Uint8Array) */ - constructor(offlineSigner: OfflineDirectSigner) { + constructor(offlineSigner: OfflineSigner) { super(); this.offlineSigner = offlineSigner; } signingMode = (): SignMode => { - return SignMode.SIGN_MODE_DIRECT; + if (typeof (this.offlineSigner as OfflineAminoSigner).signAmino === 'function') { + return SignMode.SIGN_MODE_LEGACY_AMINO_JSON; + } else if (typeof (this.offlineSigner as OfflineDirectSigner).signDirect === 'function') { + return SignMode.SIGN_MODE_DIRECT; + } + throw 'Unknown offline signer mode'; }; canChangeAccount = (): boolean => { @@ -53,9 +59,27 @@ export class LumOfflineSignerWallet extends LumWallet { if (signerIndex === -1) { throw new Error('Signer not found in document'); } - const signDoc = LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()); - const response = await this.offlineSigner.signDirect(this.address, signDoc); - return [response.signed, LumUtils.fromBase64(response.signature.signature)]; + if (this.signingMode() === SignMode.SIGN_MODE_DIRECT) { + const signDoc = LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()); + const response = await (this.offlineSigner as OfflineDirectSigner).signDirect(this.address, signDoc); + return [response.signed, LumUtils.fromBase64(response.signature.signature)]; + } else if (this.signingMode() === SignMode.SIGN_MODE_LEGACY_AMINO_JSON) { + const response = await (this.offlineSigner as OfflineAminoSigner).signAmino(this.address, { + 'account_number': doc.signers[signerIndex].accountNumber.toString(), + 'chain_id': doc.chainId, + 'fee': doc.fee, + 'memo': doc.memo || '', + 'msgs': doc.messages.map((msg) => LumAminoRegistry.toAmino(msg)), + 'sequence': doc.signers[signerIndex].sequence.toString(), + }); + if (response.signed) { + // Fees and memo could have been edited by the offline signer + doc.fee = response.signed.fee; + doc.memo = response.signed.memo; + } + return [LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()), LumUtils.fromBase64(response.signature.signature)]; + } + throw 'Unknown offline signer mode'; }; signMessage = async (msg: string): Promise => { @@ -68,14 +92,19 @@ export class LumOfflineSignerWallet extends LumWallet { chainId: LumConstants.LumSignOnlyChainId, accountNumber: Long.fromNumber(0), }; - const response = await this.offlineSigner.signDirect(this.address, signDoc); - return { - address: this.getAddress(), - publicKey: this.getPublicKey(), - msg: msg, - sig: LumUtils.fromBase64(response.signature.signature), - version: LumConstants.LumWalletSigningVersion, - signer: LumConstants.LumMessageSigner.OFFLINE, - }; + if (this.signingMode() === SignMode.SIGN_MODE_DIRECT) { + const response = await (this.offlineSigner as OfflineDirectSigner).signDirect(this.address, signDoc); + return { + address: this.getAddress(), + publicKey: this.getPublicKey(), + msg: msg, + sig: LumUtils.fromBase64(response.signature.signature), + version: LumConstants.LumWalletSigningVersion, + signer: LumConstants.LumMessageSigner.OFFLINE, + }; + } else if (typeof (this.offlineSigner as OfflineAminoSigner).signAmino === 'function') { + throw 'Feature not available for amino signers'; + } + throw 'Unknown offline signer mode'; }; } diff --git a/src/wallet/LumWalletFactory.ts b/src/wallet/LumWalletFactory.ts index da2ae69..cd23da9 100644 --- a/src/wallet/LumWalletFactory.ts +++ b/src/wallet/LumWalletFactory.ts @@ -1,5 +1,5 @@ import Transport from '@ledgerhq/hw-transport'; -import { OfflineDirectSigner } from '@cosmjs/proto-signing'; +import { OfflineSigner } from '@cosmjs/proto-signing'; import { LumWallet } from './LumWallet'; import { LumLedgerWallet } from './LumLedgerWallet'; @@ -52,7 +52,7 @@ export class LumWalletFactory { * * @param offlineSigner OfflineDirectSigner instance compatible with Comsjs based implementations */ - static fromOfflineSigner = async (offlineSigner: OfflineDirectSigner): Promise => { + static fromOfflineSigner = async (offlineSigner: OfflineSigner): Promise => { const wallet = new LumOfflineSignerWallet(offlineSigner); await wallet.useAccount(); return wallet; diff --git a/tests/wallet.test.ts b/tests/wallet.test.ts index c88c8d1..a3a9753 100644 --- a/tests/wallet.test.ts +++ b/tests/wallet.test.ts @@ -1,10 +1,11 @@ import { AccountData, DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing'; import { SignDoc } from '../src/codec/cosmos/tx/v1beta1/tx'; -import { LumWallet, LumWalletFactory, LumUtils, LumConstants, LumMessages } from '../src'; -import { encodeSecp256k1Signature } from '@cosmjs/amino'; +import { LumWallet, LumWalletFactory, LumUtils, LumConstants, LumMessages, LumRegistry, LumAminoRegistry } from '../src'; +import { AminoSignResponse, encodeSecp256k1Signature, OfflineAminoSigner, StdSignDoc } from '@cosmjs/amino'; +import { SignMode } from '../src/codec/cosmos/tx/signing/v1beta1/signing'; -class FakeOfflineSigner implements OfflineDirectSigner { +class FakeOfflineDirectSigner implements OfflineDirectSigner { private readonly privateKey: Uint8Array; constructor(privateKey: Uint8Array) { @@ -35,6 +36,48 @@ class FakeOfflineSigner implements OfflineDirectSigner { }; } +class FakeOfflineAminoSigner implements OfflineAminoSigner { + private readonly privateKey: Uint8Array; + + constructor(privateKey: Uint8Array) { + this.privateKey = privateKey; + } + + getAccounts = async (): Promise => { + const publicKey = await LumUtils.getPublicKeyFromPrivateKey(this.privateKey); + return [ + { + pubkey: publicKey, + address: LumUtils.getAddressFromPublicKey(publicKey), + algo: 'secp256k1', + }, + ]; + }; + + signAmino = async (signerAddress: string, stdSignDoc: StdSignDoc): Promise => { + const publicKey = await LumUtils.getPublicKeyFromPrivateKey(this.privateKey); + const signDoc = LumUtils.generateSignDoc( + { + chainId: stdSignDoc.chain_id, + fee: stdSignDoc.fee, + memo: stdSignDoc.memo, + messages: stdSignDoc.msgs.map((aminoMsg) => LumAminoRegistry.fromAmino(aminoMsg)), + signers: [{ accountNumber: parseInt(stdSignDoc.account_number), sequence: parseInt(stdSignDoc.sequence), publicKey: publicKey }], + }, + 0, + SignMode.SIGN_MODE_DIRECT, // Simulated to enable signature comparison during tests + ); + const signBytes = LumUtils.generateSignDocBytes(signDoc); + const hashedMessage = LumUtils.sha256(signBytes); + const signature = await LumUtils.generateSignature(hashedMessage, this.privateKey); + const stdSig = encodeSecp256k1Signature(publicKey, signature); + return { + signed: stdSignDoc, + signature: stdSig, + }; + }; +} + describe('LumWallet', () => { it('Should be identical from mnemonic, privatekey and keystore recovery', async () => { const mnemonic = 'surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put'; @@ -45,7 +88,8 @@ describe('LumWallet', () => { const w1 = await LumWalletFactory.fromMnemonic(mnemonic, `m/44'/837'/0'/0/0`); const w2 = await LumWalletFactory.fromPrivateKey(LumUtils.keyFromHex(privateKey)); const w3 = await LumWalletFactory.fromKeyStore(keystore, 'lumiere'); - const w4 = await LumWalletFactory.fromOfflineSigner(new FakeOfflineSigner(LumUtils.keyFromHex(privateKey))); + const w4 = await LumWalletFactory.fromOfflineSigner(new FakeOfflineDirectSigner(LumUtils.keyFromHex(privateKey))); + const w5 = await LumWalletFactory.fromOfflineSigner(new FakeOfflineAminoSigner(LumUtils.keyFromHex(privateKey))); expect(LumUtils.isAddressValid(w1.getAddress())).toBe(true); expect(LumUtils.isAddressValid(w1.getAddress(), LumConstants.LumBech32PrefixAccAddr)).toBe(true); @@ -71,17 +115,27 @@ describe('LumWallet', () => { ], }; + const w1Response = await w1.signTransaction(doc); + expect(LumUtils.verifySignature(w1Response[1], LumUtils.sha256(LumUtils.generateSignDocBytes(w1Response[0])), w5.getPublicKey())); + expect(w1.getAddress()).toEqual(w2.getAddress()); expect(w1.getPublicKey()).toEqual(w2.getPublicKey()); - expect(await w1.signTransaction(doc)).toEqual(await w2.signTransaction(doc)); + expect(w1Response).toEqual(await w2.signTransaction(doc)); expect(w1.getAddress()).toEqual(w3.getAddress()); expect(w1.getPublicKey()).toEqual(w3.getPublicKey()); - expect(await w1.signTransaction(doc)).toEqual(await w3.signTransaction(doc)); + expect(w1Response).toEqual(await w3.signTransaction(doc)); expect(w1.getAddress()).toEqual(w4.getAddress()); expect(w1.getPublicKey()).toEqual(w4.getPublicKey()); - expect(await w1.signTransaction(doc)).toEqual(await w4.signTransaction(doc)); + expect(w1Response).toEqual(await w4.signTransaction(doc)); + + expect(w1.getAddress()).toEqual(w5.getAddress()); + expect(w1.getPublicKey()).toEqual(w5.getPublicKey()); + // Signature will differ due to the SignMode use but should still be valid + const w5Response = await w5.signTransaction(doc); + expect(w1Response).not.toEqual(w5Response); + expect(LumUtils.verifySignature(w5Response[1], LumUtils.sha256(LumUtils.generateSignDocBytes(w5Response[0])), w5.getPublicKey())); const randomPrivateKey = LumUtils.generatePrivateKey(); expect(randomPrivateKey).toHaveLength(LumConstants.PrivateKeyLength); @@ -101,7 +155,7 @@ describe('LumWallet', () => { const w1 = await LumWalletFactory.fromMnemonic(mnemonic); const w2 = await LumWalletFactory.fromMnemonic(LumUtils.generateMnemonic()); - const w3 = await LumWalletFactory.fromOfflineSigner(new FakeOfflineSigner(LumUtils.keyFromHex(privateKey))); + const w3 = await LumWalletFactory.fromOfflineSigner(new FakeOfflineDirectSigner(LumUtils.keyFromHex(privateKey))); const signedW1 = await w1.signMessage(message); expect(signedW1.signer).toEqual(LumConstants.LumMessageSigner.PAPER); From 28be5b43266703d0cbadf9bd2d86e5d437027964 Mon Sep 17 00:00:00 2001 From: Thibault Jaillard Date: Wed, 26 Jan 2022 13:30:33 +0100 Subject: [PATCH 3/5] [LUM-215] Add all IBC Messages (#40) * Add MsgTimeout and MsgUpdateClient * Add MsgAcknowledgement * Add MsgTransfer * Add MsgChannelOpenInit * Add MsgChannelOpenTry * Add MsgChannelOpenAck * Add MsgChannelOpenConfirm * Add MsgChannelCloseInit * Add MsgChannelCloseConfirm * Add MsgRecvPacket * Add MsgTimeoutOnClose * Add MsgCreateClient * Add MsgUpgradeClient * Add MsgSubmitMisbehaviour * Add MsgConnectionOpenInit * Add MsgConnectionOpenTry * Add MsgConnectionOpenAck * Add MsgConnectionOpenConfirm * Bump version to 0.7.4 --- package.json | 2 +- src/messages/ibc/MsgAcknowledgement.ts | 19 +++++++++ src/messages/ibc/MsgChannelCloseConfirm.ts | 18 +++++++++ src/messages/ibc/MsgChannelCloseInit.ts | 15 +++++++ src/messages/ibc/MsgChannelOpenAck.ts | 28 +++++++++++++ src/messages/ibc/MsgChannelOpenConfirm.ts | 18 +++++++++ src/messages/ibc/MsgChannelOpenInit.ts | 16 ++++++++ src/messages/ibc/MsgChannelOpenTry.ts | 29 ++++++++++++++ src/messages/ibc/MsgConnectionOpenAck.ts | 36 +++++++++++++++++ src/messages/ibc/MsgConnectionOpenConfirm.ts | 17 ++++++++ src/messages/ibc/MsgConnectionOpenInit.ts | 19 +++++++++ src/messages/ibc/MsgConnectionOpenTry.ts | 41 ++++++++++++++++++++ src/messages/ibc/MsgCreateClient.ts | 16 ++++++++ src/messages/ibc/MsgRecvPacket.ts | 18 +++++++++ src/messages/ibc/MsgSubmitMisbehaviour.ts | 16 ++++++++ src/messages/ibc/MsgTimeout.ts | 20 ++++++++++ src/messages/ibc/MsgTimeoutOnClose.ts | 21 ++++++++++ src/messages/ibc/MsgTransfer.ts | 22 +++++++++++ src/messages/ibc/MsgUpdateClient.ts | 16 ++++++++ src/messages/ibc/MsgUpgradeClient.ts | 19 +++++++++ src/messages/ibc/index.ts | 19 +++++++++ src/messages/index.ts | 1 + 22 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 src/messages/ibc/MsgAcknowledgement.ts create mode 100644 src/messages/ibc/MsgChannelCloseConfirm.ts create mode 100644 src/messages/ibc/MsgChannelCloseInit.ts create mode 100644 src/messages/ibc/MsgChannelOpenAck.ts create mode 100644 src/messages/ibc/MsgChannelOpenConfirm.ts create mode 100644 src/messages/ibc/MsgChannelOpenInit.ts create mode 100644 src/messages/ibc/MsgChannelOpenTry.ts create mode 100644 src/messages/ibc/MsgConnectionOpenAck.ts create mode 100644 src/messages/ibc/MsgConnectionOpenConfirm.ts create mode 100644 src/messages/ibc/MsgConnectionOpenInit.ts create mode 100644 src/messages/ibc/MsgConnectionOpenTry.ts create mode 100644 src/messages/ibc/MsgCreateClient.ts create mode 100644 src/messages/ibc/MsgRecvPacket.ts create mode 100644 src/messages/ibc/MsgSubmitMisbehaviour.ts create mode 100644 src/messages/ibc/MsgTimeout.ts create mode 100644 src/messages/ibc/MsgTimeoutOnClose.ts create mode 100644 src/messages/ibc/MsgTransfer.ts create mode 100644 src/messages/ibc/MsgUpdateClient.ts create mode 100644 src/messages/ibc/MsgUpgradeClient.ts create mode 100644 src/messages/ibc/index.ts diff --git a/package.json b/package.json index 507b9a6..93fb6c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lum-network/sdk-javascript", - "version": "0.7.3", + "version": "0.7.4", "license": "Apache-2.0", "description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.", "homepage": "https://github.com/lum-network/sdk-javascript#readme", diff --git a/src/messages/ibc/MsgAcknowledgement.ts b/src/messages/ibc/MsgAcknowledgement.ts new file mode 100644 index 0000000..de8057b --- /dev/null +++ b/src/messages/ibc/MsgAcknowledgement.ts @@ -0,0 +1,19 @@ +import { Message } from '../Message'; +import { MsgAcknowledgement } from '../../codec/ibc/core/channel/v1/tx'; +import { Packet } from '../../codec/ibc/core/channel/v1/channel'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgAcknowledgementUrl = '/ibc.core.channel.v1.MsgAcknowledgement'; + +export const BuildMsgAcknowledgement = (acknowledgement: Uint8Array, proofAcked: Uint8Array, signer: string, packet?: Packet, proofHeight?: Height): Message => { + return { + typeUrl: MsgAcknowledgementUrl, + value: { + acknowledgement, + proofAcked, + signer, + packet, + proofHeight, + } as MsgAcknowledgement, + }; +}; diff --git a/src/messages/ibc/MsgChannelCloseConfirm.ts b/src/messages/ibc/MsgChannelCloseConfirm.ts new file mode 100644 index 0000000..ca99f1a --- /dev/null +++ b/src/messages/ibc/MsgChannelCloseConfirm.ts @@ -0,0 +1,18 @@ +import { Message } from '../Message'; +import { MsgChannelCloseConfirm } from '../../codec/ibc/core/channel/v1/tx'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgChannelCloseConfirmUrl = '/ibc.core.channel.v1.MsgChannelCloseConfirm'; + +export const BuildMsgChannelCloseConfirm = (channelId: string, portId: string, signer: string, proofInit: Uint8Array, proofHeight?: Height): Message => { + return { + typeUrl: MsgChannelCloseConfirmUrl, + value: { + channelId, + portId, + signer, + proofInit, + proofHeight, + } as MsgChannelCloseConfirm, + }; +}; diff --git a/src/messages/ibc/MsgChannelCloseInit.ts b/src/messages/ibc/MsgChannelCloseInit.ts new file mode 100644 index 0000000..a0b6893 --- /dev/null +++ b/src/messages/ibc/MsgChannelCloseInit.ts @@ -0,0 +1,15 @@ +import { Message } from '../Message'; +import { MsgChannelCloseInit } from '../../codec/ibc/core/channel/v1/tx'; + +export const MsgChannelCloseInitUrl = '/ibc.core.channel.v1.MsgChannelCloseInit'; + +export const BuildMsgChannelCloseInit = (channelId: string, signer: string, portId: string): Message => { + return { + typeUrl: MsgChannelCloseInitUrl, + value: { + channelId, + signer, + portId, + } as MsgChannelCloseInit, + }; +}; diff --git a/src/messages/ibc/MsgChannelOpenAck.ts b/src/messages/ibc/MsgChannelOpenAck.ts new file mode 100644 index 0000000..a5550c6 --- /dev/null +++ b/src/messages/ibc/MsgChannelOpenAck.ts @@ -0,0 +1,28 @@ +import { Message } from '../Message'; +import { MsgChannelOpenAck } from '../../codec/ibc/core/channel/v1/tx'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgChannelOpenAckUrl = '/ibc.core.channel.v1.MsgChannelOpenAck'; + +export const BuildMsgChannelOpenAck = ( + portId: string, + channelId: string, + counterpartyChannelId: string, + counterpartyVersion: string, + signer: string, + proofTry: Uint8Array, + proofHeight?: Height, +): Message => { + return { + typeUrl: MsgChannelOpenAckUrl, + value: { + portId, + channelId, + counterpartyChannelId, + counterpartyVersion, + signer, + proofTry, + proofHeight, + } as MsgChannelOpenAck, + }; +}; diff --git a/src/messages/ibc/MsgChannelOpenConfirm.ts b/src/messages/ibc/MsgChannelOpenConfirm.ts new file mode 100644 index 0000000..09a9b3c --- /dev/null +++ b/src/messages/ibc/MsgChannelOpenConfirm.ts @@ -0,0 +1,18 @@ +import { Message } from '../Message'; +import { MsgChannelOpenConfirm } from '../../codec/ibc/core/channel/v1/tx'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgChannelOpenConfirmUrl = '/ibc.core.channel.v1.MsgChannelOpenConfirm'; + +export const BuildMsgChannelOpenConfirm = (channelId: string, portId: string, signer: string, proofAck: Uint8Array, proofHeight?: Height): Message => { + return { + typeUrl: MsgChannelOpenConfirmUrl, + value: { + channelId, + portId, + signer, + proofAck, + proofHeight, + } as MsgChannelOpenConfirm, + }; +}; diff --git a/src/messages/ibc/MsgChannelOpenInit.ts b/src/messages/ibc/MsgChannelOpenInit.ts new file mode 100644 index 0000000..9320f76 --- /dev/null +++ b/src/messages/ibc/MsgChannelOpenInit.ts @@ -0,0 +1,16 @@ +import { Message } from '../Message'; +import { MsgChannelOpenInit } from '../../codec/ibc/core/channel/v1/tx'; +import { Channel } from '../../codec/ibc/core/channel/v1/channel'; + +export const MsgChannelOpenInitUrl = '/ibc.core.channel.v1.MsgChannelOpenInit'; + +export const BuildMsgChannelOpenInit = (portId: string, signer: string, channel?: Channel): Message => { + return { + typeUrl: MsgChannelOpenInitUrl, + value: { + portId, + signer, + channel, + } as MsgChannelOpenInit, + }; +}; diff --git a/src/messages/ibc/MsgChannelOpenTry.ts b/src/messages/ibc/MsgChannelOpenTry.ts new file mode 100644 index 0000000..4e11450 --- /dev/null +++ b/src/messages/ibc/MsgChannelOpenTry.ts @@ -0,0 +1,29 @@ +import { Message } from '../Message'; +import { MsgChannelOpenTry } from '../../codec/ibc/core/channel/v1/tx'; +import { Channel } from '../../codec/ibc/core/channel/v1/channel'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgChannelOpenTryUrl = '/ibc.core.channel.v1.MsgChannelOpenTry'; + +export const BuildMsgChannelOpenTry = ( + portId: string, + previousChannelId: string, + counterpartyVersion: string, + signer: string, + proofInit: Uint8Array, + channel?: Channel, + proofHeight?: Height, +): Message => { + return { + typeUrl: MsgChannelOpenTryUrl, + value: { + portId, + previousChannelId, + counterpartyVersion, + signer, + proofInit, + channel, + proofHeight, + } as MsgChannelOpenTry, + }; +}; diff --git a/src/messages/ibc/MsgConnectionOpenAck.ts b/src/messages/ibc/MsgConnectionOpenAck.ts new file mode 100644 index 0000000..e32dcc8 --- /dev/null +++ b/src/messages/ibc/MsgConnectionOpenAck.ts @@ -0,0 +1,36 @@ +import { Message } from '../Message'; +import { MsgConnectionOpenAck } from '../../codec/ibc/core/connection/v1/tx'; +import { Any } from '../../codec/google/protobuf/any'; +import { Height } from '../../codec/ibc/core/client/v1/client'; +import { Version } from '../../codec/ibc/core/connection/v1/connection'; + +export const MsgConnectionOpenAckUrl = '/ibc.core.connection.v1.MsgConnectionOpenAck'; + +export const BuildMsgConnectionOpenAck = ( + connectionId: string, + signer: string, + counterpartyConnectionId: string, + proofClient: Uint8Array, + proofConsensus: Uint8Array, + proofTry: Uint8Array, + clientState?: Any, + proofHeight?: Height, + consensusHeight?: Height, + version?: Version, +): Message => { + return { + typeUrl: MsgConnectionOpenAckUrl, + value: { + connectionId, + signer, + counterpartyConnectionId, + proofClient, + proofConsensus, + proofTry, + clientState, + proofHeight, + consensusHeight, + version, + } as MsgConnectionOpenAck, + }; +}; diff --git a/src/messages/ibc/MsgConnectionOpenConfirm.ts b/src/messages/ibc/MsgConnectionOpenConfirm.ts new file mode 100644 index 0000000..7a90dfd --- /dev/null +++ b/src/messages/ibc/MsgConnectionOpenConfirm.ts @@ -0,0 +1,17 @@ +import { Message } from '../Message'; +import { MsgConnectionOpenConfirm } from '../../codec/ibc/core/connection/v1/tx'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgConnectionOpenConfirmUrl = '/ibc.core.connection.v1.MsgConnectionOpenConfirm'; + +export const BuildMsgConnectionOpenConfirm = (connectionId: string, signer: string, proofAck: Uint8Array, proofHeight?: Height): Message => { + return { + typeUrl: MsgConnectionOpenConfirmUrl, + value: { + connectionId, + signer, + proofAck, + proofHeight, + } as MsgConnectionOpenConfirm, + }; +}; diff --git a/src/messages/ibc/MsgConnectionOpenInit.ts b/src/messages/ibc/MsgConnectionOpenInit.ts new file mode 100644 index 0000000..085a022 --- /dev/null +++ b/src/messages/ibc/MsgConnectionOpenInit.ts @@ -0,0 +1,19 @@ +import { Message } from '../Message'; +import { MsgConnectionOpenInit } from '../../codec/ibc/core/connection/v1/tx'; +import Long from 'long'; +import { Version, Counterparty } from '../../codec/ibc/core/connection/v1/connection'; + +export const MsgConnectionOpenInitUrl = '/ibc.core.connection.v1.MsgConnectionOpenInit'; + +export const BuildMsgConnectionOpenInit = (clientId: string, signer: string, delayPeriod: Long.Long, counterparty?: Counterparty, version?: Version): Message => { + return { + typeUrl: MsgConnectionOpenInitUrl, + value: { + clientId, + signer, + delayPeriod, + counterparty, + version, + } as MsgConnectionOpenInit, + }; +}; diff --git a/src/messages/ibc/MsgConnectionOpenTry.ts b/src/messages/ibc/MsgConnectionOpenTry.ts new file mode 100644 index 0000000..9ff28fb --- /dev/null +++ b/src/messages/ibc/MsgConnectionOpenTry.ts @@ -0,0 +1,41 @@ +import { Message } from '../Message'; +import { MsgConnectionOpenTry } from '../../codec/ibc/core/connection/v1/tx'; +import Long from 'long'; +import { Counterparty, Version } from '../../codec/ibc/core/connection/v1/connection'; +import { Any } from '../../codec/google/protobuf/any'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgConnectionOpenTryUrl = '/ibc.core.connection.v1.MsgConnectionOpenTry'; + +export const BuildMsgConnectionOpenTry = ( + signer: string, + clientId: string, + previousConnectionId: string, + delayPeriod: Long.Long, + counterpartyVersions: Version[], + proofClient: Uint8Array, + proofConsensus: Uint8Array, + proofInit: Uint8Array, + clientState?: Any, + proofHeight?: Height, + consensusHeight?: Height, + counterparty?: Counterparty, +): Message => { + return { + typeUrl: MsgConnectionOpenTryUrl, + value: { + signer, + clientId, + previousConnectionId, + delayPeriod, + counterpartyVersions, + proofClient, + proofConsensus, + proofInit, + clientState, + proofHeight, + consensusHeight, + counterparty, + } as MsgConnectionOpenTry, + }; +}; diff --git a/src/messages/ibc/MsgCreateClient.ts b/src/messages/ibc/MsgCreateClient.ts new file mode 100644 index 0000000..2b3aef6 --- /dev/null +++ b/src/messages/ibc/MsgCreateClient.ts @@ -0,0 +1,16 @@ +import { Message } from '../Message'; +import { MsgCreateClient } from '../../codec/ibc/core/client/v1/tx'; +import { Any } from '../../codec/google/protobuf/any'; + +export const MsgCreateClientUrl = '/ibc.core.client.v1.MsgCreateClient'; + +export const BuildMsgCreateClient = (signer: string, clientState?: Any, consensusState?: Any): Message => { + return { + typeUrl: MsgCreateClientUrl, + value: { + signer, + clientState, + consensusState, + } as MsgCreateClient, + }; +}; diff --git a/src/messages/ibc/MsgRecvPacket.ts b/src/messages/ibc/MsgRecvPacket.ts new file mode 100644 index 0000000..229a4d6 --- /dev/null +++ b/src/messages/ibc/MsgRecvPacket.ts @@ -0,0 +1,18 @@ +import { Message } from '../Message'; +import { MsgRecvPacket } from '../../codec/ibc/core/channel/v1/tx'; +import { Packet } from '../../codec/ibc/core/channel/v1/channel'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgRecvPacketUrl = '/ibc.core.channel.v1.MsgRecvPacket'; + +export const BuildMsgRecvPacket = (signer: string, proofCommitment: Uint8Array, packet?: Packet, proofHeight?: Height): Message => { + return { + typeUrl: MsgRecvPacketUrl, + value: { + signer, + proofCommitment, + packet, + proofHeight, + } as MsgRecvPacket, + }; +}; diff --git a/src/messages/ibc/MsgSubmitMisbehaviour.ts b/src/messages/ibc/MsgSubmitMisbehaviour.ts new file mode 100644 index 0000000..10cb30c --- /dev/null +++ b/src/messages/ibc/MsgSubmitMisbehaviour.ts @@ -0,0 +1,16 @@ +import { Message } from '../Message'; +import { MsgSubmitMisbehaviour } from '../../codec/ibc/core/client/v1/tx'; +import { Any } from '../../codec/google/protobuf/any'; + +export const MsgSubmitMisbehaviourUrl = '/ibc.core.client.v1.MsgSubmitMisbehaviour'; + +export const BuildMsgSubmitMisbehaviour = (signer: string, clientId: string, misbehaviour?: Any): Message => { + return { + typeUrl: MsgSubmitMisbehaviourUrl, + value: { + signer, + clientId, + misbehaviour, + } as MsgSubmitMisbehaviour, + }; +}; diff --git a/src/messages/ibc/MsgTimeout.ts b/src/messages/ibc/MsgTimeout.ts new file mode 100644 index 0000000..115706e --- /dev/null +++ b/src/messages/ibc/MsgTimeout.ts @@ -0,0 +1,20 @@ +import { Message } from '../Message'; +import { MsgTimeout } from '../../codec/ibc/core/channel/v1/tx'; +import Long from 'long'; +import { Packet } from '../../codec/ibc/core/channel/v1/channel'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgTimeoutUrl = '/ibc.core.channel.v1.MsgTimeout'; + +export const BuildMsgTimeout = (nextSequenceRecv: Long.Long, proofUnreceived: Uint8Array, signer: string, packet?: Packet, proofHeight?: Height): Message => { + return { + typeUrl: MsgTimeoutUrl, + value: { + nextSequenceRecv, + packet, + proofHeight, + proofUnreceived, + signer, + } as MsgTimeout, + }; +}; diff --git a/src/messages/ibc/MsgTimeoutOnClose.ts b/src/messages/ibc/MsgTimeoutOnClose.ts new file mode 100644 index 0000000..ff16b2e --- /dev/null +++ b/src/messages/ibc/MsgTimeoutOnClose.ts @@ -0,0 +1,21 @@ +import { Message } from '../Message'; +import { MsgTimeoutOnClose } from '../../codec/ibc/core/channel/v1/tx'; +import Long from 'long'; +import { Packet } from '../../codec/ibc/core/channel/v1/channel'; +import { Height } from '../../codec/ibc/core/client/v1/client'; + +export const MsgTimeoutOnCloseUrl = '/ibc.core.channel.v1.MsgTimeoutOnClose'; + +export const BuildMsgTimeoutOnClose = (nextSequenceRecv: Long.Long, signer: string, proofClose: Uint8Array, proofUnreceived: Uint8Array, packet?: Packet, proofHeight?: Height): Message => { + return { + typeUrl: MsgTimeoutOnCloseUrl, + value: { + nextSequenceRecv, + signer, + proofClose, + proofUnreceived, + packet, + proofHeight, + } as MsgTimeoutOnClose, + }; +}; diff --git a/src/messages/ibc/MsgTransfer.ts b/src/messages/ibc/MsgTransfer.ts new file mode 100644 index 0000000..67ef540 --- /dev/null +++ b/src/messages/ibc/MsgTransfer.ts @@ -0,0 +1,22 @@ +import { Message } from '../Message'; +import { MsgTransfer } from '../../codec/ibc/applications/transfer/v1/tx'; +import Long from 'long'; +import { Height } from '../../codec/ibc/core/client/v1/client'; +import { Coin } from '../../types'; + +export const MsgTransferUrl = '/ibc.applications.transfer.v1.MsgTransfer'; + +export const BuildMsgTransfer = (receiver: string, sender: string, sourceChannel: string, sourcePort: string, timeoutTimestamp: Long.Long, timeoutHeight?: Height, token?: Coin): Message => { + return { + typeUrl: MsgTransferUrl, + value: { + receiver, + sender, + sourceChannel, + sourcePort, + timeoutTimestamp, + timeoutHeight, + token, + } as MsgTransfer, + }; +}; diff --git a/src/messages/ibc/MsgUpdateClient.ts b/src/messages/ibc/MsgUpdateClient.ts new file mode 100644 index 0000000..94b6cd5 --- /dev/null +++ b/src/messages/ibc/MsgUpdateClient.ts @@ -0,0 +1,16 @@ +import { Message } from '../Message'; +import { MsgUpdateClient } from '../../codec/ibc/core/client/v1/tx'; +import { Any } from '../../codec/google/protobuf/any'; + +export const MsgUpdateClientUrl = '/ibc.core.client.v1.MsgUpdateClient'; + +export const BuildMsgUpdateClient = (clientId: string, signer: string, header?: Any): Message => { + return { + typeUrl: MsgUpdateClientUrl, + value: { + clientId, + signer, + header, + } as MsgUpdateClient, + }; +}; diff --git a/src/messages/ibc/MsgUpgradeClient.ts b/src/messages/ibc/MsgUpgradeClient.ts new file mode 100644 index 0000000..52e7ef8 --- /dev/null +++ b/src/messages/ibc/MsgUpgradeClient.ts @@ -0,0 +1,19 @@ +import { Message } from '../Message'; +import { MsgUpgradeClient } from '../../codec/ibc/core/client/v1/tx'; +import { Any } from '../../codec/google/protobuf/any'; + +export const MsgUpgradeClientUrl = '/ibc.core.client.v1.MsgUpgradeClient'; + +export const BuildMsgUpgradeClient = (clientId: string, proofUpgradeClient: Uint8Array, signer: string, proofUpgradeConsensusState: Uint8Array, clientState?: Any, consensusState?: Any): Message => { + return { + typeUrl: MsgUpgradeClientUrl, + value: { + clientId, + proofUpgradeClient, + signer, + proofUpgradeConsensusState, + clientState, + consensusState, + } as MsgUpgradeClient, + }; +}; diff --git a/src/messages/ibc/index.ts b/src/messages/ibc/index.ts new file mode 100644 index 0000000..2bebc98 --- /dev/null +++ b/src/messages/ibc/index.ts @@ -0,0 +1,19 @@ +export * from './MsgTimeout'; +export * from './MsgUpdateClient'; +export * from './MsgAcknowledgement'; +export * from './MsgTransfer'; +export * from './MsgChannelOpenInit'; +export * from './MsgChannelOpenTry'; +export * from './MsgChannelOpenAck'; +export * from './MsgChannelOpenConfirm'; +export * from './MsgChannelCloseInit'; +export * from './MsgChannelCloseConfirm'; +export * from './MsgRecvPacket'; +export * from './MsgTimeoutOnClose'; +export * from './MsgCreateClient'; +export * from './MsgUpgradeClient'; +export * from './MsgSubmitMisbehaviour'; +export * from './MsgConnectionOpenInit'; +export * from './MsgConnectionOpenTry'; +export * from './MsgConnectionOpenAck'; +export * from './MsgConnectionOpenAck'; diff --git a/src/messages/index.ts b/src/messages/index.ts index 5e1c9b7..6696bab 100644 --- a/src/messages/index.ts +++ b/src/messages/index.ts @@ -8,3 +8,4 @@ export * from './authz'; export * from './feegrant'; export * from './slashing'; export * from './vesting'; +export * from './ibc'; From 514f6722131e8e9a7c014479650f98dae54adafc Mon Sep 17 00:00:00 2001 From: Thibault Jaillard Date: Wed, 26 Jan 2022 14:42:52 +0100 Subject: [PATCH 4/5] Fix MsgTimeout --- src/registry/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registry/index.ts b/src/registry/index.ts index 0065d03..43f8c91 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -86,7 +86,7 @@ const registryTypes: Iterable<[string, GeneratedType]> = [ ['/ibc.core.channel.v1.MsgChannelCloseInit', MsgChannelCloseInit], ['/ibc.core.channel.v1.MsgChannelCloseConfirm', MsgChannelCloseConfirm], ['/ibc.core.channel.v1.MsgRecvPacket', MsgRecvPacket], - ['/ibc.core.channel.v1.MsgTimeout ', MsgTimeout], + ['/ibc.core.channel.v1.MsgTimeout', MsgTimeout], ['/ibc.core.channel.v1.MsgTimeoutOnClose', MsgTimeoutOnClose], ['/ibc.core.channel.v1.MsgAcknowledgement', MsgAcknowledgement], ['/ibc.core.client.v1.MsgCreateClient', MsgCreateClient], From 49ee070649d3fd7071cec56001ee1aaab5445e0a Mon Sep 17 00:00:00 2001 From: Thibault Jaillard Date: Wed, 26 Jan 2022 15:50:17 +0100 Subject: [PATCH 5/5] Bump version to 0.7.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93fb6c6..fb7a5f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lum-network/sdk-javascript", - "version": "0.7.4", + "version": "0.7.5", "license": "Apache-2.0", "description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.", "homepage": "https://github.com/lum-network/sdk-javascript#readme",