diff --git a/docs/README.md b/docs/README.md index 1cfafbb..23f59fc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -60,8 +60,8 @@ console.log(`Wallet address: ${wallet.address}`); ### Hardware wallets **IMPORTANT NOTES:** -- Transaction signature using Hardware devices is currently work in progress, therefore broadcasting a transaction is not possible at the moment. -- Derivation path using the Cosmos Ledger application cannot be set to the default Lum Path for now `m/44'/118'/0'/*/*` and must remain on the Cosmos path `m/44'/'837/0'/*/*` +- Transaction signature using Ledger only works with legacy amino (wich will be deprecated at some point) +- Derivation path using the Cosmos Ledger application cannot be set to the default Lum Path for now `m/44'/837'/0'/*/*` and must remain on the Cosmos path `m/44'/'118/0'/*/*` #### Ledger diff --git a/docs/lib/README.md b/docs/lib/README.md index 7c1d8f3..bf1f040 100644 --- a/docs/lib/README.md +++ b/docs/lib/README.md @@ -12,14 +12,24 @@ ### Classes - [LumClient](classes/lumclient.md) +- [LumLedgerWallet](classes/lumledgerwallet.md) +- [LumPaperWallet](classes/lumpaperwallet.md) - [LumWallet](classes/lumwallet.md) +- [LumWalletFactory](classes/lumwalletfactory.md) ### Variables +- [LumAminoRegistry](README.md#lumaminoregistry) - [LumRegistry](README.md#lumregistry) ## Variables +### LumAminoRegistry + +• `Const` **LumAminoRegistry**: *AminoTypes* + +___ + ### LumRegistry • `Const` **LumRegistry**: *ExtendedRegistry* diff --git a/docs/lib/classes/lumclient.md b/docs/lib/classes/lumclient.md index 314788f..0740be1 100644 --- a/docs/lib/classes/lumclient.md +++ b/docs/lib/classes/lumclient.md @@ -27,7 +27,6 @@ - [getChainId](lumclient.md#getchainid) - [getSupply](lumclient.md#getsupply) - [getTx](lumclient.md#gettx) -- [getValidators](lumclient.md#getvalidators) - [searchTx](lumclient.md#searchtx) - [signAndBroadcastTx](lumclient.md#signandbroadcasttx) - [signTx](lumclient.md#signtx) @@ -39,7 +38,7 @@ ### constructor -\+ **new LumClient**(`tmClient`: *Client*): [*LumClient*](lumclient.md) +\+ **new LumClient**(`tmClient`: *Tendermint34Client*): [*LumClient*](lumclient.md) Create a LumClient instance using a tendermint RPC client @@ -47,7 +46,7 @@ Create a LumClient instance using a tendermint RPC client Name | Type | Description | :------ | :------ | :------ | -`tmClient` | *Client* | tendermint RPC client | +`tmClient` | *Tendermint34Client* | tendermint RPC client | **Returns:** [*LumClient*](lumclient.md) @@ -67,7 +66,7 @@ ___ ### tmClient -• `Readonly` **tmClient**: *Client* +• `Readonly` **tmClient**: *Tendermint34Client* ## Methods @@ -259,23 +258,6 @@ Name | Type | Description | ___ -### getValidators - -▸ **getValidators**(`blockHeight?`: *number*): *Promise* - -Get all validators -Validators are sorted first by voting power (descending), then by address (ascending) - -#### Parameters: - -Name | Type | Description | -:------ | :------ | :------ | -`blockHeight?` | *number* | block height to return. If no height is provided, it will fetch validator set which corresponds to the latest block | - -**Returns:** *Promise* - -___ - ### searchTx ▸ **searchTx**(`queries`: *string*[], `page?`: *number*, `perPage?`: *number*, `includeProof?`: *boolean*): *Promise* @@ -294,7 +276,7 @@ Name | Type | Default value | Description | :------ | :------ | :------ | :------ | `queries` | *string*[] | - | queries to run (see utils/search for helpers) | `page` | *number* | 1 | page to query (default to 1) | -`perPage` | *number* | 30 | result per pages (default to 30) | +`perPage` | *number* | 30 | results per pages (default to 30) | `includeProof?` | *boolean* | - | whether or not to include proofs of the transactions inclusion in the block | **Returns:** *Promise* @@ -303,7 +285,7 @@ ___ ### signAndBroadcastTx -▸ **signAndBroadcastTx**(`wallet`: [*LumWallet*](lumwallet.md), `messages`: [*Message*](../interfaces/lummessages.message.md)[], `fee`: [*Fee*](../interfaces/lumtypes.fee.md), `memo?`: *string*): *Promise* +▸ **signAndBroadcastTx**(`wallet`: [*LumWallet*](lumwallet.md), `doc`: [*Doc*](../interfaces/lumtypes.doc.md)): *Promise* Signs and broadcast the transaction using the specified wallet and messages @@ -312,9 +294,7 @@ Signs and broadcast the transaction using the specified wallet and messages Name | Type | Description | :------ | :------ | :------ | `wallet` | [*LumWallet*](lumwallet.md) | signing wallet | -`messages` | [*Message*](../interfaces/lummessages.message.md)[] | messages to sign | -`fee` | [*Fee*](../interfaces/lumtypes.fee.md) | requested fee | -`memo?` | *string* | optional memo for the transaction | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | document to sign and broadcast as a transaction | **Returns:** *Promise* @@ -322,7 +302,7 @@ ___ ### signTx -▸ **signTx**(`wallet`: [*LumWallet*](lumwallet.md), `messages`: [*Message*](../interfaces/lummessages.message.md)[], `fee`: [*Fee*](../interfaces/lumtypes.fee.md), `memo?`: *string*): *Promise* +▸ **signTx**(`wallet`: [*LumWallet*](lumwallet.md), `doc`: [*Doc*](../interfaces/lumtypes.doc.md)): *Promise* Signs the messages using the provided wallet and builds the transaction @@ -331,9 +311,7 @@ Signs the messages using the provided wallet and builds the transaction Name | Type | Description | :------ | :------ | :------ | `wallet` | [*LumWallet*](lumwallet.md) | signing wallet | -`messages` | [*Message*](../interfaces/lummessages.message.md)[] | messages to sign | -`fee` | [*Fee*](../interfaces/lumtypes.fee.md) | requested fee | -`memo?` | *string* | optional memo for the transaction | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | document to sign | **Returns:** *Promise* diff --git a/docs/lib/classes/lumledgerwallet.md b/docs/lib/classes/lumledgerwallet.md new file mode 100644 index 0000000..47aab33 --- /dev/null +++ b/docs/lib/classes/lumledgerwallet.md @@ -0,0 +1,169 @@ +# Class: LumLedgerWallet + +## Hierarchy + +* [*LumWallet*](lumwallet.md) + + ↳ **LumLedgerWallet** + +## Table of contents + +### Constructors + +- [constructor](lumledgerwallet.md#constructor) + +### Properties + +- [address](lumledgerwallet.md#address) +- [cosmosApp](lumledgerwallet.md#cosmosapp) +- [hdPath](lumledgerwallet.md#hdpath) +- [publicKey](lumledgerwallet.md#publickey) + +### Methods + +- [canChangeAccount](lumledgerwallet.md#canchangeaccount) +- [getAddress](lumledgerwallet.md#getaddress) +- [getAppConfiguration](lumledgerwallet.md#getappconfiguration) +- [getPublicKey](lumledgerwallet.md#getpublickey) +- [signTransaction](lumledgerwallet.md#signtransaction) +- [signingMode](lumledgerwallet.md#signingmode) +- [useAccount](lumledgerwallet.md#useaccount) + +## Constructors + +### constructor + +\+ **new LumLedgerWallet**(`transport`: *Transport*): [*LumLedgerWallet*](lumledgerwallet.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`transport` | *Transport* | + +**Returns:** [*LumLedgerWallet*](lumledgerwallet.md) + +Inherited from: [LumWallet](lumwallet.md) + +## Properties + +### address + +• `Protected` `Optional` **address**: *undefined* \| *string* + +Inherited from: [LumWallet](lumwallet.md).[address](lumwallet.md#address) + +___ + +### cosmosApp + +• **cosmosApp**: *default* + +___ + +### hdPath + +• `Private` `Optional` **hdPath**: *undefined* \| *string* + +___ + +### publicKey + +• `Protected` `Optional` **publicKey**: *undefined* \| *Uint8Array* + +Inherited from: [LumWallet](lumwallet.md).[publicKey](lumwallet.md#publickey) + +## Methods + +### canChangeAccount + +▸ **canChangeAccount**(): *boolean* + +**Returns:** *boolean* + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### getAddress + +▸ **getAddress**(): *string* + +Gets the current wallet address + +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) + +**Returns:** *string* + +wallet address (Bech32) + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### getAppConfiguration + +▸ **getAppConfiguration**(): *Promise*<{ `device_locked`: *boolean* ; `major`: *string* ; `test_mode`: *boolean* ; `version`: *string* }\> + +Gets the connected application configuration + +**Returns:** *Promise*<{ `device_locked`: *boolean* ; `major`: *string* ; `test_mode`: *boolean* ; `version`: *string* }\> + +___ + +### getPublicKey + +▸ **getPublicKey**(): *Uint8Array* + +Gets the current wallet public key + +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) + +**Returns:** *Uint8Array* + +wallet public key (secp256k1) + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### signTransaction + +▸ **signTransaction**(`doc`: [*Doc*](../interfaces/lumtypes.doc.md)): *Promise* + +#### Parameters: + +Name | Type | +:------ | :------ | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | + +**Returns:** *Promise* + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### signingMode + +▸ **signingMode**(): SignMode + +**Returns:** SignMode + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### useAccount + +▸ **useAccount**(`hdPath`: *string*, `addressPrefix`: *string*): *Promise* + +#### Parameters: + +Name | Type | +:------ | :------ | +`hdPath` | *string* | +`addressPrefix` | *string* | + +**Returns:** *Promise* + +Inherited from: [LumWallet](lumwallet.md) diff --git a/docs/lib/classes/lumpaperwallet.md b/docs/lib/classes/lumpaperwallet.md new file mode 100644 index 0000000..109dd29 --- /dev/null +++ b/docs/lib/classes/lumpaperwallet.md @@ -0,0 +1,162 @@ +# Class: LumPaperWallet + +## Hierarchy + +* [*LumWallet*](lumwallet.md) + + ↳ **LumPaperWallet** + +## Table of contents + +### Constructors + +- [constructor](lumpaperwallet.md#constructor) + +### Properties + +- [address](lumpaperwallet.md#address) +- [mnemonic](lumpaperwallet.md#mnemonic) +- [privateKey](lumpaperwallet.md#privatekey) +- [publicKey](lumpaperwallet.md#publickey) + +### Methods + +- [canChangeAccount](lumpaperwallet.md#canchangeaccount) +- [getAddress](lumpaperwallet.md#getaddress) +- [getPublicKey](lumpaperwallet.md#getpublickey) +- [signTransaction](lumpaperwallet.md#signtransaction) +- [signingMode](lumpaperwallet.md#signingmode) +- [useAccount](lumpaperwallet.md#useaccount) + +## Constructors + +### constructor + +\+ **new LumPaperWallet**(`mnemonicOrPrivateKey`: *string* \| *Uint8Array*): [*LumPaperWallet*](lumpaperwallet.md) + +Create a LumPaperWallet instance based on a mnemonic or a private key +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 + +#### Parameters: + +Name | Type | Description | +:------ | :------ | :------ | +`mnemonicOrPrivateKey` | *string* \| *Uint8Array* | mnemonic (string) used to derive the private key or private key (Uint8Array) | + +**Returns:** [*LumPaperWallet*](lumpaperwallet.md) + +Inherited from: [LumWallet](lumwallet.md) + +## Properties + +### address + +• `Protected` `Optional` **address**: *undefined* \| *string* + +Inherited from: [LumWallet](lumwallet.md).[address](lumwallet.md#address) + +___ + +### mnemonic + +• `Private` `Optional` `Readonly` **mnemonic**: *undefined* \| *string* + +___ + +### privateKey + +• `Private` `Optional` **privateKey**: *undefined* \| *Uint8Array* + +___ + +### publicKey + +• `Protected` `Optional` **publicKey**: *undefined* \| *Uint8Array* + +Inherited from: [LumWallet](lumwallet.md).[publicKey](lumwallet.md#publickey) + +## Methods + +### canChangeAccount + +▸ **canChangeAccount**(): *boolean* + +**Returns:** *boolean* + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### getAddress + +▸ **getAddress**(): *string* + +Gets the current wallet address + +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) + +**Returns:** *string* + +wallet address (Bech32) + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### getPublicKey + +▸ **getPublicKey**(): *Uint8Array* + +Gets the current wallet public key + +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) + +**Returns:** *Uint8Array* + +wallet public key (secp256k1) + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### signTransaction + +▸ **signTransaction**(`doc`: [*Doc*](../interfaces/lumtypes.doc.md)): *Promise* + +#### Parameters: + +Name | Type | +:------ | :------ | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | + +**Returns:** *Promise* + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### signingMode + +▸ **signingMode**(): SignMode + +**Returns:** SignMode + +Inherited from: [LumWallet](lumwallet.md) + +___ + +### useAccount + +▸ **useAccount**(`hdPath?`: *string*, `addressPrefix?`: *string*): *Promise* + +#### Parameters: + +Name | Type | +:------ | :------ | +`hdPath` | *string* | +`addressPrefix` | *string* | + +**Returns:** *Promise* + +Inherited from: [LumWallet](lumwallet.md) diff --git a/docs/lib/classes/lumwallet.md b/docs/lib/classes/lumwallet.md index 848673d..e3f3620 100644 --- a/docs/lib/classes/lumwallet.md +++ b/docs/lib/classes/lumwallet.md @@ -1,5 +1,13 @@ # Class: LumWallet +## Hierarchy + +* **LumWallet** + + ↳ [*LumLedgerWallet*](lumledgerwallet.md) + + ↳ [*LumPaperWallet*](lumpaperwallet.md) + ## Table of contents ### Constructors @@ -9,34 +17,22 @@ ### Properties - [address](lumwallet.md#address) -- [privateKey](lumwallet.md#privatekey) - [publicKey](lumwallet.md#publickey) ### Methods +- [canChangeAccount](lumwallet.md#canchangeaccount) +- [getAddress](lumwallet.md#getaddress) +- [getPublicKey](lumwallet.md#getpublickey) - [signTransaction](lumwallet.md#signtransaction) -- [fromKeyStore](lumwallet.md#fromkeystore) -- [fromMnemonic](lumwallet.md#frommnemonic) -- [fromPrivateKey](lumwallet.md#fromprivatekey) +- [signingMode](lumwallet.md#signingmode) +- [useAccount](lumwallet.md#useaccount) ## Constructors ### constructor -\+ **new LumWallet**(`privateKey`: *Uint8Array*, `publicKey`: *Uint8Array*, `addressPrefix?`: *string*): [*LumWallet*](lumwallet.md) - -Create a LumWallet instance based on a private key and a public key -This constructor is not intended to be used directly as mismatching privateKey and publicKey will lead -to undesired behaviour -Better use the provided static LumWallet builders - -#### Parameters: - -Name | Type | Description | -:------ | :------ | :------ | -`privateKey` | *Uint8Array* | wallet private key (secp256k1) | -`publicKey` | *Uint8Array* | wallet public key (secp256k1) | -`addressPrefix` | *string* | prefix to use to derive the address from the public key (ex: lum) | +\+ **new LumWallet**(): [*LumWallet*](lumwallet.md) **Returns:** [*LumWallet*](lumwallet.md) @@ -44,91 +40,94 @@ Name | Type | Description | ### address -• `Readonly` **address**: *string* - -Adress (bech32) +• `Protected` `Optional` **address**: *undefined* \| *string* ___ -### privateKey +### publicKey -• `Private` `Readonly` **privateKey**: *Uint8Array* +• `Protected` `Optional` **publicKey**: *undefined* \| *Uint8Array* -Private key (secp256k1) +## Methods -___ +### canChangeAccount -### publicKey +▸ `Abstract`**canChangeAccount**(): *boolean* -• `Readonly` **publicKey**: *Uint8Array* +Whether or not the wallet support changing account +Basically only wallet initialized using a private key should not be able to do so -Public key (secp256k1) +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) -## Methods +**Returns:** *boolean* -### signTransaction +___ -▸ **signTransaction**(`hashedMessage`: *Uint8Array*): *Promise* +### getAddress -Sign a transaction using the wallet private key +▸ **getAddress**(): *string* -#### Parameters: +Gets the current wallet address -Name | Type | Description | -:------ | :------ | :------ | -`hashedMessage` | *Uint8Array* | transaction hashed message (sha256) | +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) -**Returns:** *Promise* +**Returns:** *string* + +wallet address (Bech32) ___ -### fromKeyStore +### getPublicKey -▸ `Static`**fromKeyStore**(`keystore`: *string* \| [*KeyStore*](../interfaces/lumutils.keystore.md), `password`: *string*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> +▸ **getPublicKey**(): *Uint8Array* -Create a LumWallet instance based on a keystore +Gets the current wallet public key -#### Parameters: +**`see`** [LumWallet.useAccount](lumwallet.md#useaccount) -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) | +**Returns:** *Uint8Array* -**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> +wallet public key (secp256k1) ___ -### fromMnemonic +### signTransaction -▸ `Static`**fromMnemonic**(`mnemonic`: *string*, `hdPath?`: *string*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> +▸ `Abstract`**signTransaction**(`doc`: [*Doc*](../interfaces/lumtypes.doc.md)): *Promise* -Create a LumWallet instance based on a mnemonic and a derivation path +Sign a transaction document using a LumWallet #### 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) | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | document to sign | + +**Returns:** *Promise* + +___ + +### signingMode + +▸ `Abstract`**signingMode**(): SignMode + +Gets the wallet signin mode -**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> +**Returns:** SignMode ___ -### fromPrivateKey +### useAccount -▸ `Static`**fromPrivateKey**(`privateKey`: *Uint8Array*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> +▸ `Abstract`**useAccount**(`hdPath`: *string*, `addressPrefix`: *string*): *Promise* -Create a LumWallet instance based on a private key (secp256k1) +Change the wallet to use #### 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) | +`hdPath` | *string* | BIP44 HD Path | +`addressPrefix` | *string* | prefix to use (ex: lum) | -**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> +**Returns:** *Promise* diff --git a/docs/lib/classes/lumwalletfactory.md b/docs/lib/classes/lumwalletfactory.md new file mode 100644 index 0000000..bdc73cc --- /dev/null +++ b/docs/lib/classes/lumwalletfactory.md @@ -0,0 +1,93 @@ +# Class: LumWalletFactory + +## Table of contents + +### Constructors + +- [constructor](lumwalletfactory.md#constructor) + +### Methods + +- [fromKeyStore](lumwalletfactory.md#fromkeystore) +- [fromLedgerTransport](lumwalletfactory.md#fromledgertransport) +- [fromMnemonic](lumwalletfactory.md#frommnemonic) +- [fromPrivateKey](lumwalletfactory.md#fromprivatekey) + +## Constructors + +### constructor + +\+ **new LumWalletFactory**(): [*LumWalletFactory*](lumwalletfactory.md) + +**Returns:** [*LumWalletFactory*](lumwalletfactory.md) + +## Methods + +### fromKeyStore + +▸ `Static`**fromKeyStore**(`keystore`: *string* \| [*KeyStore*](../interfaces/lumutils.keystore.md), `password`: *string*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> + +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) | + +**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> + +___ + +### fromLedgerTransport + +▸ `Static`**fromLedgerTransport**(`transport`: *Transport*, `hdPath?`: *string*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> + +Create a LumWallet instance based on a ledger transport + +#### Parameters: + +Name | Type | Description | +:------ | :------ | :------ | +`transport` | *Transport* | 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) | + +**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> + +___ + +### fromMnemonic + +▸ `Static`**fromMnemonic**(`mnemonic`: *string*, `hdPath?`: *string*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> + +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) | + +**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> + +___ + +### fromPrivateKey + +▸ `Static`**fromPrivateKey**(`privateKey`: *Uint8Array*, `addressPrefix?`: *string*): *Promise*<[*LumWallet*](lumwallet.md)\> + +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) | + +**Returns:** *Promise*<[*LumWallet*](lumwallet.md)\> diff --git a/docs/lib/interfaces/lummessages.msgbeginredelegate.md b/docs/lib/interfaces/lummessages.msgbeginredelegate.md new file mode 100644 index 0000000..faf79c4 --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgbeginredelegate.md @@ -0,0 +1,39 @@ +# Interface: MsgBeginRedelegate + +[LumMessages](../modules/lummessages.md).MsgBeginRedelegate + +MsgBeginRedelegate defines a SDK message for performing a redelegation +of coins from a delegator and source validator to a destination validator. + +## Table of contents + +### Properties + +- [amount](lummessages.msgbeginredelegate.md#amount) +- [delegatorAddress](lummessages.msgbeginredelegate.md#delegatoraddress) +- [validatorDstAddress](lummessages.msgbeginredelegate.md#validatordstaddress) +- [validatorSrcAddress](lummessages.msgbeginredelegate.md#validatorsrcaddress) + +## Properties + +### amount + +• `Optional` **amount**: *undefined* \| [*Coin*](lumtypes.coin.md) + +___ + +### delegatorAddress + +• **delegatorAddress**: *string* + +___ + +### validatorDstAddress + +• **validatorDstAddress**: *string* + +___ + +### validatorSrcAddress + +• **validatorSrcAddress**: *string* diff --git a/docs/lib/interfaces/lummessages.msgcreatevalidator.md b/docs/lib/interfaces/lummessages.msgcreatevalidator.md new file mode 100644 index 0000000..5977377 --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgcreatevalidator.md @@ -0,0 +1,59 @@ +# Interface: MsgCreateValidator + +[LumMessages](../modules/lummessages.md).MsgCreateValidator + +MsgCreateValidator defines a SDK message for creating a new validator. + +## Table of contents + +### Properties + +- [commission](lummessages.msgcreatevalidator.md#commission) +- [delegatorAddress](lummessages.msgcreatevalidator.md#delegatoraddress) +- [description](lummessages.msgcreatevalidator.md#description) +- [minSelfDelegation](lummessages.msgcreatevalidator.md#minselfdelegation) +- [pubkey](lummessages.msgcreatevalidator.md#pubkey) +- [validatorAddress](lummessages.msgcreatevalidator.md#validatoraddress) +- [value](lummessages.msgcreatevalidator.md#value) + +## Properties + +### commission + +• `Optional` **commission**: *undefined* \| [*CommissionRates*](lumtypes.commissionrates.md) + +___ + +### delegatorAddress + +• **delegatorAddress**: *string* + +___ + +### description + +• `Optional` **description**: *undefined* \| [*Description*](lumtypes.description.md) + +___ + +### minSelfDelegation + +• **minSelfDelegation**: *string* + +___ + +### pubkey + +• `Optional` **pubkey**: *undefined* \| Any + +___ + +### validatorAddress + +• **validatorAddress**: *string* + +___ + +### value + +• `Optional` **value**: *undefined* \| [*Coin*](lumtypes.coin.md) diff --git a/docs/lib/interfaces/lummessages.msgdelegate.md b/docs/lib/interfaces/lummessages.msgdelegate.md new file mode 100644 index 0000000..9c79fd6 --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgdelegate.md @@ -0,0 +1,32 @@ +# Interface: MsgDelegate + +[LumMessages](../modules/lummessages.md).MsgDelegate + +MsgDelegate defines a SDK message for performing a delegation of coins +from a delegator to a validator. + +## Table of contents + +### Properties + +- [amount](lummessages.msgdelegate.md#amount) +- [delegatorAddress](lummessages.msgdelegate.md#delegatoraddress) +- [validatorAddress](lummessages.msgdelegate.md#validatoraddress) + +## Properties + +### amount + +• `Optional` **amount**: *undefined* \| [*Coin*](lumtypes.coin.md) + +___ + +### delegatorAddress + +• **delegatorAddress**: *string* + +___ + +### validatorAddress + +• **validatorAddress**: *string* diff --git a/docs/lib/interfaces/lummessages.msgeditvalidator.md b/docs/lib/interfaces/lummessages.msgeditvalidator.md new file mode 100644 index 0000000..382b366 --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgeditvalidator.md @@ -0,0 +1,43 @@ +# Interface: MsgEditValidator + +[LumMessages](../modules/lummessages.md).MsgEditValidator + +MsgEditValidator defines a SDK message for editing an existing validator. + +## Table of contents + +### Properties + +- [commissionRate](lummessages.msgeditvalidator.md#commissionrate) +- [description](lummessages.msgeditvalidator.md#description) +- [minSelfDelegation](lummessages.msgeditvalidator.md#minselfdelegation) +- [validatorAddress](lummessages.msgeditvalidator.md#validatoraddress) + +## Properties + +### commissionRate + +• **commissionRate**: *string* + +We pass a reference to the new commission rate and min self delegation as +it's not mandatory to update. If not updated, the deserialized rate will be +zero with no way to distinguish if an update was intended. +REF: #2373 + +___ + +### description + +• `Optional` **description**: *undefined* \| [*Description*](lumtypes.description.md) + +___ + +### minSelfDelegation + +• **minSelfDelegation**: *string* + +___ + +### validatorAddress + +• **validatorAddress**: *string* diff --git a/docs/lib/interfaces/lummessages.msgmintandsend.md b/docs/lib/interfaces/lummessages.msgmintandsend.md new file mode 100644 index 0000000..bbf8fcd --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgmintandsend.md @@ -0,0 +1,26 @@ +# Interface: MsgMintAndSend + +[LumMessages](../modules/lummessages.md).MsgMintAndSend + +MsgMintAndSend defines a SDK message asking the faucet module to send you +a set of coins, for testing purposes only. +This module is ONLY enabled in testnet + +## Table of contents + +### Properties + +- [mintTime](lummessages.msgmintandsend.md#minttime) +- [minter](lummessages.msgmintandsend.md#minter) + +## Properties + +### mintTime + +• **mintTime**: Date + +___ + +### minter + +• **minter**: *string* diff --git a/docs/lib/interfaces/lummessages.msgundelegate.md b/docs/lib/interfaces/lummessages.msgundelegate.md new file mode 100644 index 0000000..c7d70a3 --- /dev/null +++ b/docs/lib/interfaces/lummessages.msgundelegate.md @@ -0,0 +1,32 @@ +# Interface: MsgUndelegate + +[LumMessages](../modules/lummessages.md).MsgUndelegate + +MsgUndelegate defines a SDK message for performing an undelegation from a +delegate and a validator. + +## Table of contents + +### Properties + +- [amount](lummessages.msgundelegate.md#amount) +- [delegatorAddress](lummessages.msgundelegate.md#delegatoraddress) +- [validatorAddress](lummessages.msgundelegate.md#validatoraddress) + +## Properties + +### amount + +• `Optional` **amount**: *undefined* \| [*Coin*](lumtypes.coin.md) + +___ + +### delegatorAddress + +• **delegatorAddress**: *string* + +___ + +### validatorAddress + +• **validatorAddress**: *string* diff --git a/docs/lib/interfaces/lumtypes.doc.md b/docs/lib/interfaces/lumtypes.doc.md new file mode 100644 index 0000000..1d5932b --- /dev/null +++ b/docs/lib/interfaces/lumtypes.doc.md @@ -0,0 +1,64 @@ +# Interface: Doc + +[LumTypes](../modules/lumtypes.md).Doc + +## Table of contents + +### Properties + +- [accountNumber](lumtypes.doc.md#accountnumber) +- [chainId](lumtypes.doc.md#chainid) +- [fee](lumtypes.doc.md#fee) +- [memo](lumtypes.doc.md#memo) +- [messages](lumtypes.doc.md#messages) +- [sequence](lumtypes.doc.md#sequence) + +## Properties + +### accountNumber + +• **accountNumber**: *number* + +account_number is the account number of the account in state + +___ + +### chainId + +• **chainId**: *string* + +chain_id is the unique identifier of the chain this transaction targets. +It prevents signed transactions from being used on another chain by an +attacker + +___ + +### fee + +• **fee**: [*Fee*](lumtypes.fee.md) + +Transaction requested Fee + +___ + +### memo + +• `Optional` **memo**: *undefined* \| *string* + +Transaction memo + +___ + +### messages + +• **messages**: [*Message*](lummessages.message.md)[] + +Transactions messages + +___ + +### sequence + +• **sequence**: *number* + +Transction sequence number diff --git a/docs/lib/interfaces/lumtypes.pubkey.md b/docs/lib/interfaces/lumtypes.pubkey.md new file mode 100644 index 0000000..df4939d --- /dev/null +++ b/docs/lib/interfaces/lumtypes.pubkey.md @@ -0,0 +1,21 @@ +# Interface: PubKey + +[LumTypes](../modules/lumtypes.md).PubKey + +PubKey defines a secp256k1 public key +Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte +if the y-coordinate is the lexicographically largest of the two associated with +the x-coordinate. Otherwise the first byte is a 0x03. +This prefix is followed with the x-coordinate. + +## Table of contents + +### Properties + +- [key](lumtypes.pubkey.md#key) + +## Properties + +### key + +• **key**: *Uint8Array* diff --git a/docs/lib/interfaces/lumtypes.tx.md b/docs/lib/interfaces/lumtypes.tx.md new file mode 100644 index 0000000..aea2199 --- /dev/null +++ b/docs/lib/interfaces/lumtypes.tx.md @@ -0,0 +1,40 @@ +# Interface: Tx + +[LumTypes](../modules/lumtypes.md).Tx + +Tx is the standard type used for broadcasting transactions. + +## Table of contents + +### Properties + +- [authInfo](lumtypes.tx.md#authinfo) +- [body](lumtypes.tx.md#body) +- [signatures](lumtypes.tx.md#signatures) + +## Properties + +### authInfo + +• `Optional` **authInfo**: *undefined* \| AuthInfo + +auth_info is the authorization related content of the transaction, +specifically signers, signer modes and fee + +___ + +### body + +• `Optional` **body**: *undefined* \| TxBody + +body is the processable content of the transaction + +___ + +### signatures + +• **signatures**: *Uint8Array*[] + +signatures is a list of signatures that matches the length and order of +AuthInfo's signer_infos to allow connecting signature meta information like +public key and signing mode by position. diff --git a/docs/lib/modules/lumconstants.md b/docs/lib/modules/lumconstants.md index 764d704..37e349a 100644 --- a/docs/lib/modules/lumconstants.md +++ b/docs/lib/modules/lumconstants.md @@ -22,7 +22,7 @@ ### HDPath -• `Const` **HDPath**: *m/44'/837'/0'/0/*= "m/44'/837'/0'/0/" +• `Const` **HDPath**: *m/44'/837'/0'/*= "m/44'/837'/0'/" Lum Network HDPath @@ -98,7 +98,7 @@ Private Key length ### getLumHdPath -▸ `Const`**getLumHdPath**(`accountIndex?`: *number*): *string* +▸ `Const`**getLumHdPath**(`accountIndex?`: *number*, `walletIndex?`: *number*): *string* Get a Lum Network HDPath for a specified account index @@ -107,5 +107,6 @@ Get a Lum Network HDPath for a specified account index Name | Type | Default value | Description | :------ | :------ | :------ | :------ | `accountIndex` | *number* | 0 | appended at the end of the default Lum derivation path | +`walletIndex` | *number* | 0 | - | **Returns:** *string* diff --git a/docs/lib/modules/lummessages.md b/docs/lib/modules/lummessages.md index c97d30c..02b4f45 100644 --- a/docs/lib/modules/lummessages.md +++ b/docs/lib/modules/lummessages.md @@ -5,39 +5,87 @@ ### Interfaces - [Message](../interfaces/lummessages.message.md) +- [MsgBeginRedelegate](../interfaces/lummessages.msgbeginredelegate.md) +- [MsgCreateValidator](../interfaces/lummessages.msgcreatevalidator.md) +- [MsgDelegate](../interfaces/lummessages.msgdelegate.md) +- [MsgEditValidator](../interfaces/lummessages.msgeditvalidator.md) - [MsgFundCommunityPool](../interfaces/lummessages.msgfundcommunitypool.md) +- [MsgMintAndSend](../interfaces/lummessages.msgmintandsend.md) - [MsgMultiSend](../interfaces/lummessages.msgmultisend.md) - [MsgSend](../interfaces/lummessages.msgsend.md) - [MsgSetWithdrawAddress](../interfaces/lummessages.msgsetwithdrawaddress.md) +- [MsgUndelegate](../interfaces/lummessages.msgundelegate.md) - [MsgWithdrawDelegatorReward](../interfaces/lummessages.msgwithdrawdelegatorreward.md) - [MsgWithdrawValidatorCommission](../interfaces/lummessages.msgwithdrawvalidatorcommission.md) ### Variables +- [MsgBeginRedelegateUrl](lummessages.md#msgbeginredelegateurl) +- [MsgCreateValidatorUrl](lummessages.md#msgcreatevalidatorurl) +- [MsgDelegateUrl](lummessages.md#msgdelegateurl) +- [MsgEditValidatorUrl](lummessages.md#msgeditvalidatorurl) - [MsgFundCommunityPoolUrl](lummessages.md#msgfundcommunitypoolurl) +- [MsgMintAndSendUrl](lummessages.md#msgmintandsendurl) - [MsgMultiSendUrl](lummessages.md#msgmultisendurl) - [MsgSendUrl](lummessages.md#msgsendurl) - [MsgSetWithdrawAddressUrl](lummessages.md#msgsetwithdrawaddressurl) +- [MsgUndelegateUrl](lummessages.md#msgundelegateurl) - [MsgWithdrawDelegatorRewardUrl](lummessages.md#msgwithdrawdelegatorrewardurl) - [MsgWithdrawValidatorCommissionUrl](lummessages.md#msgwithdrawvalidatorcommissionurl) ### Functions +- [BuildMsgBeginRedelegate](lummessages.md#buildmsgbeginredelegate) +- [BuildMsgCreateValidator](lummessages.md#buildmsgcreatevalidator) +- [BuildMsgDelegate](lummessages.md#buildmsgdelegate) +- [BuildMsgEditValidator](lummessages.md#buildmsgeditvalidator) - [BuildMsgFundCommunityPool](lummessages.md#buildmsgfundcommunitypool) +- [BuildMsgMintAndSend](lummessages.md#buildmsgmintandsend) - [BuildMsgMultiSend](lummessages.md#buildmsgmultisend) - [BuildMsgSend](lummessages.md#buildmsgsend) - [BuildMsgSetWithdrawAddress](lummessages.md#buildmsgsetwithdrawaddress) +- [BuildMsgUndelegate](lummessages.md#buildmsgundelegate) - [BuildMsgWithdrawDelegatorReward](lummessages.md#buildmsgwithdrawdelegatorreward) - [BuildMsgWithdrawValidatorCommission](lummessages.md#buildmsgwithdrawvalidatorcommission) ## Variables +### MsgBeginRedelegateUrl + +• `Const` **MsgBeginRedelegateUrl**: */cosmos.staking.v1beta1.MsgBeginRedelegate*= '/cosmos.staking.v1beta1.MsgBeginRedelegate' + +___ + +### MsgCreateValidatorUrl + +• `Const` **MsgCreateValidatorUrl**: */cosmos.staking.v1beta1.MsgCreateValidator*= '/cosmos.staking.v1beta1.MsgCreateValidator' + +___ + +### MsgDelegateUrl + +• `Const` **MsgDelegateUrl**: */cosmos.staking.v1beta1.MsgDelegate*= '/cosmos.staking.v1beta1.MsgDelegate' + +___ + +### MsgEditValidatorUrl + +• `Const` **MsgEditValidatorUrl**: */cosmos.staking.v1beta1.MsgEditValidator*= '/cosmos.staking.v1beta1.MsgEditValidator' + +___ + ### MsgFundCommunityPoolUrl • `Const` **MsgFundCommunityPoolUrl**: */cosmos.distribution.v1beta1.MsgFundCommunityPool*= '/cosmos.distribution.v1beta1.MsgFundCommunityPool' ___ +### MsgMintAndSendUrl + +• `Const` **MsgMintAndSendUrl**: */lum.network.faucet.MsgMintAndSend*= '/lum.network.faucet.MsgMintAndSend' + +___ + ### MsgMultiSendUrl • `Const` **MsgMultiSendUrl**: */cosmos.bank.v1beta1.MsgMultiSend*= '/cosmos.bank.v1beta1.MsgMultiSend' @@ -56,6 +104,12 @@ ___ ___ +### MsgUndelegateUrl + +• `Const` **MsgUndelegateUrl**: */cosmos.staking.v1beta1.MsgUndelegate*= '/cosmos.staking.v1beta1.MsgUndelegate' + +___ + ### MsgWithdrawDelegatorRewardUrl • `Const` **MsgWithdrawDelegatorRewardUrl**: */cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward*= '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward' @@ -68,6 +122,76 @@ ___ ## Functions +### BuildMsgBeginRedelegate + +▸ `Const`**BuildMsgBeginRedelegate**(`delegatorAddress`: *string*, `validatorSrcAddress`: *string*, `validatorDstAddress`: *string*, `amount?`: [*Coin*](../interfaces/lumtypes.coin.md)): [*Message*](../interfaces/lummessages.message.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`delegatorAddress` | *string* | +`validatorSrcAddress` | *string* | +`validatorDstAddress` | *string* | +`amount?` | [*Coin*](../interfaces/lumtypes.coin.md) | + +**Returns:** [*Message*](../interfaces/lummessages.message.md) + +___ + +### BuildMsgCreateValidator + +▸ `Const`**BuildMsgCreateValidator**(`validatorAddress`: *string*, `delegatorAddress`: *string*, `minSelfDelegation`: *string*, `commission?`: [*CommissionRates*](../interfaces/lumtypes.commissionrates.md), `description?`: [*Description*](../interfaces/lumtypes.description.md), `value?`: [*Coin*](../interfaces/lumtypes.coin.md), `pubkey?`: Any): [*Message*](../interfaces/lummessages.message.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`validatorAddress` | *string* | +`delegatorAddress` | *string* | +`minSelfDelegation` | *string* | +`commission?` | [*CommissionRates*](../interfaces/lumtypes.commissionrates.md) | +`description?` | [*Description*](../interfaces/lumtypes.description.md) | +`value?` | [*Coin*](../interfaces/lumtypes.coin.md) | +`pubkey?` | Any | + +**Returns:** [*Message*](../interfaces/lummessages.message.md) + +___ + +### BuildMsgDelegate + +▸ `Const`**BuildMsgDelegate**(`delegatorAddress`: *string*, `validatorAddress`: *string*, `amount?`: [*Coin*](../interfaces/lumtypes.coin.md)): [*Message*](../interfaces/lummessages.message.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`delegatorAddress` | *string* | +`validatorAddress` | *string* | +`amount?` | [*Coin*](../interfaces/lumtypes.coin.md) | + +**Returns:** [*Message*](../interfaces/lummessages.message.md) + +___ + +### BuildMsgEditValidator + +▸ `Const`**BuildMsgEditValidator**(`validatorAddress`: *string*, `commissionRate`: *string*, `minSelfDelegation`: *string*, `description?`: [*Description*](../interfaces/lumtypes.description.md)): [*Message*](../interfaces/lummessages.message.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`validatorAddress` | *string* | +`commissionRate` | *string* | +`minSelfDelegation` | *string* | +`description?` | [*Description*](../interfaces/lumtypes.description.md) | + +**Returns:** [*Message*](../interfaces/lummessages.message.md) + +___ + ### BuildMsgFundCommunityPool ▸ `Const`**BuildMsgFundCommunityPool**(`depositor`: *string*, `amount`: [*Coin*](../interfaces/lumtypes.coin.md)[]): [*Message*](../interfaces/lummessages.message.md) @@ -83,6 +207,26 @@ Name | Type | ___ +### BuildMsgMintAndSend + +▸ `Const`**BuildMsgMintAndSend**(`minter`: *string*, `mintTime`: Date): *object* + +#### Parameters: + +Name | Type | +:------ | :------ | +`minter` | *string* | +`mintTime` | Date | + +**Returns:** *object* + +Name | Type | +:------ | :------ | +`typeUrl` | *string* | +`value` | [*MsgMintAndSend*](../interfaces/lummessages.msgmintandsend.md) | + +___ + ### BuildMsgMultiSend ▸ `Const`**BuildMsgMultiSend**(`input`: { `address`: *string* ; `coins`: [*Coin*](../interfaces/lumtypes.coin.md)[] }[], `output`: { `address`: *string* ; `coins`: [*Coin*](../interfaces/lumtypes.coin.md)[] }[]): [*Message*](../interfaces/lummessages.message.md) @@ -129,6 +273,22 @@ Name | Type | ___ +### BuildMsgUndelegate + +▸ `Const`**BuildMsgUndelegate**(`delegatorAddress`: *string*, `validatorAddress`: *string*, `amount?`: [*Coin*](../interfaces/lumtypes.coin.md)): [*Message*](../interfaces/lummessages.message.md) + +#### Parameters: + +Name | Type | +:------ | :------ | +`delegatorAddress` | *string* | +`validatorAddress` | *string* | +`amount?` | [*Coin*](../interfaces/lumtypes.coin.md) | + +**Returns:** [*Message*](../interfaces/lummessages.message.md) + +___ + ### BuildMsgWithdrawDelegatorReward ▸ `Const`**BuildMsgWithdrawDelegatorReward**(`delegatorAddress`: *string*, `validatorAddress`: *string*): [*Message*](../interfaces/lummessages.message.md) diff --git a/docs/lib/modules/lumtypes.md b/docs/lib/modules/lumtypes.md index 6799f8b..b84db6a 100644 --- a/docs/lib/modules/lumtypes.md +++ b/docs/lib/modules/lumtypes.md @@ -9,8 +9,48 @@ - [Commission](../interfaces/lumtypes.commission.md) - [CommissionRates](../interfaces/lumtypes.commissionrates.md) - [Description](../interfaces/lumtypes.description.md) +- [Doc](../interfaces/lumtypes.doc.md) - [Fee](../interfaces/lumtypes.fee.md) - [Log](../interfaces/lumtypes.log.md) - [LogAttribute](../interfaces/lumtypes.logattribute.md) - [LogEvent](../interfaces/lumtypes.logevent.md) +- [PubKey](../interfaces/lumtypes.pubkey.md) - [SignDoc](../interfaces/lumtypes.signdoc.md) +- [Tx](../interfaces/lumtypes.tx.md) + +### Variables + +- [PubKey](lumtypes.md#pubkey) +- [Tx](lumtypes.md#tx) + +## Variables + +### PubKey + +• **PubKey**: *object* + +#### Type declaration: + +Name | Type | +:------ | :------ | +`decode` | (`input`: *Uint8Array* \| *Reader*, `length?`: *number*) => [*PubKey*](lumtypes.md#pubkey) | +`encode` | (`message`: [*PubKey*](lumtypes.md#pubkey), `writer`: *Writer*) => *Writer* | +`fromJSON` | (`object`: *any*) => [*PubKey*](lumtypes.md#pubkey) | +`fromPartial` | (`object`: { `key`: *undefined* \| *Uint8Array* }) => [*PubKey*](lumtypes.md#pubkey) | +`toJSON` | (`message`: [*PubKey*](lumtypes.md#pubkey)) => *unknown* | + +___ + +### Tx + +• **Tx**: *object* + +#### Type declaration: + +Name | Type | +:------ | :------ | +`decode` | (`input`: *Uint8Array* \| *Reader*, `length?`: *number*) => [*Tx*](lumtypes.md#tx) | +`encode` | (`message`: [*Tx*](lumtypes.md#tx), `writer`: *Writer*) => *Writer* | +`fromJSON` | (`object`: *any*) => [*Tx*](lumtypes.md#tx) | +`fromPartial` | (`object`: { `authInfo?`: *undefined* \| { signerInfos?: { publicKey?: { typeUrl?: string \| undefined; value?: Uint8Array \| undefined; } \| undefined; modeInfo?: { single?: { mode?: SignMode \| undefined; } \| undefined; multi?: { ...; } \| undefined; } \| undefined; sequence?: Long \| undefined; }[] \| undefined; fee?: { ...; } \| undefined; } ; `body?`: *undefined* \| { messages?: { typeUrl?: string \| undefined; value?: Uint8Array \| undefined; }[] \| undefined; memo?: string \| undefined; timeoutHeight?: Long \| undefined; extensionOptions?: { ...; }[] \| undefined; nonCriticalExtensionOptions?: { ...; }[] \| undefined; } ; `signatures`: *undefined* \| *Uint8Array*[] }) => [*Tx*](lumtypes.md#tx) | +`toJSON` | (`message`: [*Tx*](lumtypes.md#tx)) => *unknown* | diff --git a/docs/lib/modules/lumutils.md b/docs/lib/modules/lumutils.md index be59333..e4fb443 100644 --- a/docs/lib/modules/lumutils.md +++ b/docs/lib/modules/lumutils.md @@ -10,7 +10,7 @@ - [broadcastTxCommitSuccess](lumutils.md#broadcasttxcommitsuccess) - [broadcastTxSyncSuccess](lumutils.md#broadcasttxsyncsuccess) -- [generateAuthInfo](lumutils.md#generateauthinfo) +- [generateAuthInfoBytes](lumutils.md#generateauthinfobytes) - [generateKeyStore](lumutils.md#generatekeystore) - [generateMnemonic](lumutils.md#generatemnemonic) - [generatePrivateKey](lumutils.md#generateprivatekey) @@ -38,6 +38,7 @@ - [searchTxFrom](lumutils.md#searchtxfrom) - [searchTxTo](lumutils.md#searchtxto) - [sha3](lumutils.md#sha3) +- [sortJSON](lumutils.md#sortjson) - [toJSON](lumutils.md#tojson) - [verifySignature](lumutils.md#verifysignature) @@ -76,9 +77,9 @@ Name | Type | ___ -### generateAuthInfo +### generateAuthInfoBytes -▸ `Const`**generateAuthInfo**(`publicKey`: *Uint8Array*, `fee`: [*Fee*](../interfaces/lumtypes.fee.md), `sequence`: *number*): *Uint8Array* +▸ `Const`**generateAuthInfoBytes**(`publicKey`: *Uint8Array*, `fee`: [*Fee*](../interfaces/lumtypes.fee.md), `sequence`: *number*, `signMode`: SignMode): *Uint8Array* Generate transaction auth info payload @@ -89,6 +90,7 @@ Name | Type | Description | `publicKey` | *Uint8Array* | wallet public key (secp256k1) | `fee` | [*Fee*](../interfaces/lumtypes.fee.md) | requested fee | `sequence` | *number* | account sequence number | +`signMode` | SignMode | - | **Returns:** *Uint8Array* @@ -141,7 +143,7 @@ ___ ### generateSignDoc -▸ `Const`**generateSignDoc**(`messages`: [*Message*](../interfaces/lummessages.message.md)[], `memo`: *undefined* \| *string*, `authInfoBytes`: *Uint8Array*, `chainId`: *string*, `accountNumber`: *number*): [*SignDoc*](../interfaces/lumtypes.signdoc.md) +▸ `Const`**generateSignDoc**(`doc`: [*Doc*](../interfaces/lumtypes.doc.md), `publicKey`: *Uint8Array*, `signMode`: SignMode): [*SignDoc*](../interfaces/lumtypes.signdoc.md) Generate transaction doc to be signed @@ -149,11 +151,9 @@ Generate transaction doc to be signed Name | Type | Description | :------ | :------ | :------ | -`messages` | [*Message*](../interfaces/lummessages.message.md)[] | Transaction messages | -`memo` | *undefined* \| *string* | optional memo for the transaction | -`authInfoBytes` | *Uint8Array* | info bytes (as generated by the generateAuthInfo function) | -`chainId` | *string* | chain id | -`accountNumber` | *number* | account number | +`doc` | [*Doc*](../interfaces/lumtypes.doc.md) | document to create the sign version | +`publicKey` | *Uint8Array* | public key used for signature | +`signMode` | SignMode | signing mode for the transaction | **Returns:** [*SignDoc*](../interfaces/lumtypes.signdoc.md) @@ -535,6 +535,30 @@ Name | Type | Description | ___ +### sortJSON + +▸ `Const`**sortJSON**(`jsonObj`: T): T + +Sorts an object properties recursively. + +#### Type parameters: + +Name | +:------ | +`T` | + +#### Parameters: + +Name | Type | Description | +:------ | :------ | :------ | +`jsonObj` | T | object to sort | + +**Returns:** T + +a new object with keys sorted alphabetically + +___ + ### toJSON ▸ `Const`**toJSON**(`data`: *unknown*): *unknown* diff --git a/jest.config.js b/jest.config.js index f37e51c..e02a4b2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,5 +13,5 @@ module.exports = { tsconfig: 'tsconfig.spec.json', }, }, - testTimeout: 30000, + testTimeout: 60000, }; diff --git a/src/client/LumClient.ts b/src/client/LumClient.ts index da4300d..37d3972 100644 --- a/src/client/LumClient.ts +++ b/src/client/LumClient.ts @@ -250,7 +250,7 @@ export class LumClient { if (!account) { throw new Error('Account not found'); } - const signDoc = LumUtils.generateSignDoc(doc, wallet.getPublicKey()); + const signDoc = LumUtils.generateSignDoc(doc, wallet.getPublicKey(), wallet.signingMode()); const signature = await wallet.signTransaction(doc); return LumUtils.generateTxBytes(signDoc, signature); }; diff --git a/src/declarations.d.ts b/src/declarations.d.ts index 5eedc74..8b36cf9 100644 --- a/src/declarations.d.ts +++ b/src/declarations.d.ts @@ -12,12 +12,12 @@ declare module '@ledgerhq/hw-app-cosmos' { transport: import('@ledgerhq/hw-transport').default<*>; constructor(transport: import('@ledgerhq/hw-transport').default<*>, scrambleKey: string); - getAppConfiguration(): { + getAppConfiguration(): Promise<{ test_mode: boolean; version: string; device_locked: boolean; major: string; - }; + }>; serializePath(path: Buffer): Buffer; diff --git a/src/index.ts b/src/index.ts index c2535a7..08dc588 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,8 @@ import * as LumUtils from './utils'; import * as LumConstants from './constants'; import * as LumTypes from './types'; import * as LumMessages from './messages'; -import { LumRegistry } from './registry'; -import { LumWallet, LumWalletFactory } from './wallet'; +import { LumRegistry, LumAminoRegistry } from './registry'; +import { LumWallet, LumLedgerWallet, LumPaperWallet, LumWalletFactory } from './wallet'; import { LumClient } from './client'; -export { LumWallet, LumWalletFactory, LumClient, LumTypes, LumUtils, LumConstants, LumMessages, LumRegistry }; +export { LumWallet, LumWalletFactory, LumLedgerWallet, LumPaperWallet, LumClient, LumTypes, LumUtils, LumConstants, LumMessages, LumRegistry, LumAminoRegistry }; diff --git a/src/registry/index.ts b/src/registry/index.ts index 9d1a5b2..32cb9f6 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -1,4 +1,5 @@ import { Registry, GeneratedType } from '@cosmjs/proto-signing'; +import { AminoTypes } from '@cosmjs/stargate'; import { Tx } from '../codec/cosmos/tx/v1beta1/tx'; import { PubKey } from '../codec/cosmos/crypto/secp256k1/keys'; @@ -26,5 +27,5 @@ class ExtendedRegistry extends Registry { return Tx.decode(tx); }; } - +export const LumAminoRegistry = new AminoTypes(); export const LumRegistry = new ExtendedRegistry(registryTypes); diff --git a/src/utils/transactions.ts b/src/utils/transactions.ts index 37bb2c6..d62191d 100644 --- a/src/utils/transactions.ts +++ b/src/utils/transactions.ts @@ -4,6 +4,7 @@ import { Secp256k1, Secp256k1Signature } from '@cosmjs/crypto'; import { makeAuthInfoBytes, makeSignBytes } from '@cosmjs/proto-signing'; import { TxRaw } from '../codec/cosmos/tx/v1beta1/tx'; +import { SignMode } from '../codec/cosmos/tx/signing/v1beta1/signing'; import { sha256 } from './encoding'; import { Fee, Doc, SignDoc } from '../types'; @@ -17,10 +18,10 @@ import { LumRegistry } from '../registry'; * @param fee requested fee * @param sequence account sequence number */ -export const generateAuthInfoBytes = (publicKey: Uint8Array, fee: Fee, sequence: number): Uint8Array => { +export const generateAuthInfoBytes = (publicKey: Uint8Array, fee: Fee, sequence: number, signMode: SignMode): Uint8Array => { const pubkeyAny = publicKeyToProto(publicKey); const gasLimit = Int53.fromString(fee.gas).toNumber(); - return makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence); + return makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence, signMode); }; /** @@ -28,8 +29,9 @@ export const generateAuthInfoBytes = (publicKey: Uint8Array, fee: Fee, sequence: * * @param doc document to create the sign version * @param publicKey public key used for signature + * @param signMode signing mode for the transaction */ -export const generateSignDoc = (doc: Doc, publicKey: Uint8Array): SignDoc => { +export const generateSignDoc = (doc: Doc, publicKey: Uint8Array, signMode: SignMode): SignDoc => { const txBody = { messages: doc.messages, memo: doc.memo, @@ -41,7 +43,7 @@ export const generateSignDoc = (doc: Doc, publicKey: Uint8Array): SignDoc => { return { bodyBytes, - authInfoBytes: generateAuthInfoBytes(publicKey, doc.fee, doc.sequence), + authInfoBytes: generateAuthInfoBytes(publicKey, doc.fee, doc.sequence, signMode), chainId: doc.chainId, accountNumber: Long.fromNumber(doc.accountNumber), }; diff --git a/src/wallet/LumLedgerWallet.ts b/src/wallet/LumLedgerWallet.ts index d9542f3..ef33ad6 100644 --- a/src/wallet/LumLedgerWallet.ts +++ b/src/wallet/LumLedgerWallet.ts @@ -1,7 +1,9 @@ import Transport from '@ledgerhq/hw-transport'; import Cosmos from '@ledgerhq/hw-app-cosmos'; +import { ExtendedSecp256k1Signature } from '@cosmjs/crypto'; -import { LumUtils, LumTypes } from '..'; +import { SignMode } from '../codec/cosmos/tx/signing/v1beta1/signing'; +import { LumUtils, LumTypes, LumAminoRegistry } from '..'; import { LumWallet } from '.'; export class LumLedgerWallet extends LumWallet { @@ -13,10 +15,26 @@ export class LumLedgerWallet extends LumWallet { this.cosmosApp = new Cosmos(transport, 'CSM'); // TODO: CSM identifier should either be LUM or dynamic depending on our ledger implementation } + signingMode = (): SignMode => { + return SignMode.SIGN_MODE_LEGACY_AMINO_JSON; + }; + canChangeAccount = () => { return true; }; + /** + * Gets the connected application configuration + */ + getAppConfiguration = async (): Promise<{ + test_mode: boolean; + version: string; + device_locked: boolean; + major: string; + }> => { + return this.cosmosApp.getAppConfiguration(); + }; + useAccount = async (hdPath: string, addressPrefix: string): Promise => { const { address, publicKey } = await this.cosmosApp.getAddress(hdPath, addressPrefix); this.hdPath = hdPath; @@ -37,17 +55,18 @@ export class LumLedgerWallet extends LumWallet { // sign call: https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-cosmos/src/Cosmos.js // Expected tx format: https://github.com/cosmos/ledger-cosmos/blob/master/docs/TXSPEC.md const msg = { - 'account_number': doc.accountNumber, + 'account_number': doc.accountNumber.toString(), 'chain_id': doc.chainId, 'fee': doc.fee, 'memo': doc.memo, - 'msgs': doc.messages, - 'sequence': doc.sequence, + 'msgs': doc.messages.map((msg) => LumAminoRegistry.toAmino(msg)), + 'sequence': doc.sequence.toString(), }; const { signature, return_code } = await this.cosmosApp.sign(this.hdPath, JSON.stringify(LumUtils.sortJSON(msg))); if (!signature || return_code === 0) { throw new Error(`Failed to sign message: error code ${return_code}`); } - return new Uint8Array(signature); + const sig = ExtendedSecp256k1Signature.fromDer(signature); + return new Uint8Array([...sig.r(32), ...sig.s(32)]); }; } diff --git a/src/wallet/LumPaperWallet.ts b/src/wallet/LumPaperWallet.ts index 3fd1593..5dd4240 100644 --- a/src/wallet/LumPaperWallet.ts +++ b/src/wallet/LumPaperWallet.ts @@ -1,3 +1,4 @@ +import { SignMode } from '../codec/cosmos/tx/signing/v1beta1/signing'; import { LumUtils, LumConstants, LumTypes } from '..'; import { LumWallet } from '.'; @@ -21,6 +22,10 @@ export class LumPaperWallet extends LumWallet { } } + signingMode = (): SignMode => { + return SignMode.SIGN_MODE_DIRECT; + }; + canChangeAccount = (): boolean => { return !!this.mnemonic; }; @@ -43,7 +48,7 @@ export class LumPaperWallet extends LumWallet { if (!this.privateKey || !this.publicKey) { throw new Error('No account selected.'); } - const signDoc = LumUtils.generateSignDoc(doc, this.getPublicKey()); + const signDoc = LumUtils.generateSignDoc(doc, this.getPublicKey(), this.signingMode()); const signBytes = LumUtils.generateSignDocBytes(signDoc); const hashedMessage = LumUtils.sha256(signBytes); const signature = await LumUtils.generateSignature(hashedMessage, this.privateKey); diff --git a/src/wallet/LumWallet.ts b/src/wallet/LumWallet.ts index 90e1943..135844f 100644 --- a/src/wallet/LumWallet.ts +++ b/src/wallet/LumWallet.ts @@ -1,3 +1,4 @@ +import { SignMode } from '../codec/cosmos/tx/signing/v1beta1/signing'; import { LumTypes } from '..'; export abstract class LumWallet { @@ -30,6 +31,11 @@ export abstract class LumWallet { return this.publicKey; }; + /** + * Gets the wallet signin mode + */ + abstract signingMode(): SignMode; + /** * Whether or not the wallet support changing account * Basically only wallet initialized using a private key should not be able to do so diff --git a/tests/ledger.test.ts b/tests/ledger.test.ts index 022735d..a9add04 100644 --- a/tests/ledger.test.ts +++ b/tests/ledger.test.ts @@ -13,21 +13,24 @@ describe('Ledger', () => { await expect(clt.disconnect()).resolves.toBeTruthy(); }); - it('Should be able to connect to ledger hardware wallet', async () => { - // WIP - manual testing using ledger device + it('Manual signature must work', async () => { + // Manual testing using ledger device + // Ledger device must be unlocked and Cosmos app opened prior to running those tests // const transport = await TransportNodeHid.create(); // const w1 = await LumWalletFactory.fromLedgerTransport(transport, `m/44'/118'/0'/0/0`, 'lum'); + // expect(w1).toBeTruthy(); // const acc = await clt.getAccount(w1.getAddress()); // expect(acc).toBeTruthy(); // const balance = await clt.getBalance(acc.address, 'lum'); // expect(parseInt(balance.amount)).toBeGreaterThan(0); - // TODO: requires to fixe the ledger signing implementation + // const chainId = await clt.getChainId(); - // const sendMsg = LumMessages.BuildMsgSend(w1.getAddress(), 'lum1ty3meqzqxq7vkdyp7l7znzvn0t50w92uf6h4px', [{ denom: 'lum', amount: '3' }]); + // const sendMsg = LumMessages.BuildMsgSend(w1.getAddress(), 'lum1lsagfzrm4gz28he4wunt63sts5xzmczwjttsr9', [{ denom: 'lum', amount: '3' }]); // const fee = { // amount: [{ denom: LumConstants.LumDenom, amount: '1' }], // gas: '100000', // }; + // const doc = { // accountNumber: acc.accountNumber, // chainId, @@ -36,6 +39,7 @@ describe('Ledger', () => { // messages: [sendMsg], // sequence: acc.sequence, // }; + // const res = await clt.signAndBroadcastTx(w1, doc); // expect(LumUtils.broadcastTxCommitSuccess(res)).toBeTruthy(); });