From 1c6d2021cd9cff0f0f299b3e41c692d4fdbf15fa Mon Sep 17 00:00:00 2001 From: Nicolas Brugneaux Date: Thu, 28 Mar 2024 09:51:28 +0100 Subject: [PATCH] Refactor: dependencies dedup (such as keccaak, bip, etc) (#139) * test: add bls regression tests * refactor: more deps gone * refactor: types * refactor: getWordList * refactor: more deps gone * fix: utils * fix: keccak hash * fix: various buffer fixes * fix: force keccak to consider string as bytes * chore: update docs * fix: type * refactor: rlp -> @ethereumjs/rlp * refactor: eth-lib removal wip * refactor: eth-lib removal * chore: regenerate docs * fix: ensure no 0x-prefixed string is passed to hextobytes * fix: update snapshot * fix: ensure r,s,v are 0x prefixed * chore: regenerate docs * test: bls * test: some more signing-utils tests * chore: regenerate docs * chore: regenerate docs * fix: web3 resolution * fix: ledger SignMessage * chore: add note * chore: regenerate docs --- package.json | 1 - packages/cli/package.json | 2 +- .../sdk/docs/base/interfaces/account.Bip39.md | 12 +- .../interfaces/account.Bip39.md | 12 +- .../commentEncryption.EncryptionStatus.md | 4 +- .../sdk/docs/cryptographic-utils/modules.md | 1 + .../cryptographic-utils/modules/account.md | 49 ++- .../docs/cryptographic-utils/modules/bls.md | 14 +- .../modules/commentEncryption.md | 10 +- .../modules/dataEncryptionKey.md | 10 +- .../docs/cryptographic-utils/modules/index.md | 7 + .../cryptographic-utils/modules/wordlists.md | 19 + .../interfaces/istanbul.IstanbulExtra.md | 12 +- .../docs/utils/interfaces/istanbul.Seal.md | 6 +- .../sign_typed_data_utils.EIP712Parameter.md | 4 +- .../sign_typed_data_utils.EIP712TypedData.md | 8 +- ...typed_data_utils.EIP712TypesWithPrimary.md | 4 +- packages/docs/sdk/docs/utils/modules/ecdh.md | 10 +- packages/docs/sdk/docs/utils/modules/ecies.md | 105 +++-- .../docs/sdk/docs/utils/modules/istanbul.md | 8 +- .../utils/modules/sign_typed_data_utils.md | 34 +- .../sdk/docs/wallet-base/modules/index.md | 35 ++ .../docs/wallet-base/modules/signing_utils.md | 164 ++++++-- .../classes/aws_hsm_signer.AwsHsmSigner.md | 14 +- .../classes/gcp_hsm_signer.GcpHsmSigner.md | 12 +- .../classes/signature_utils.Signature.md | 8 +- .../wallet-hsm/modules/signature_utils.md | 20 +- .../docs/sdk/docs/wallet-ledger/README.md | 1 + .../classes/ledger_signer.LedgerSigner.md | 10 +- .../classes/ledger_wallet.LedgerWallet.md | 12 +- .../enums/ledger_wallet.AddressValidation.md | 8 +- .../wallet-ledger/interfaces/types.ILedger.md | 135 ++++++ .../wallet-ledger/modules/ledger_wallet.md | 4 +- .../sdk/docs/wallet-ledger/modules/types.md | 31 ++ .../classes/local_signer.LocalSigner.md | 14 +- packages/sdk/base/src/account.ts | 4 +- packages/sdk/cryptographic-utils/package.json | 11 +- .../cryptographic-utils/src/account.test.ts | 7 +- .../sdk/cryptographic-utils/src/account.ts | 81 ++-- .../sdk/cryptographic-utils/src/bls.test.ts | 61 +++ packages/sdk/cryptographic-utils/src/bls.ts | 18 +- .../sdk/cryptographic-utils/src/wordlists.ts | 25 ++ packages/sdk/governance/package.json | 1 - packages/sdk/governance/src/proposals.ts | 8 +- packages/sdk/utils/package.json | 3 +- packages/sdk/utils/src/istanbul.ts | 22 +- .../utils/src/sign-typed-data-utils.test.ts | 54 +-- .../sdk/utils/src/sign-typed-data-utils.ts | 43 +- packages/sdk/wallets/wallet-base/package.json | 6 +- .../wallet-base/src/signing-utils.test.ts | 40 +- .../wallets/wallet-base/src/signing-utils.ts | 391 ++++++++++-------- .../sdk/wallets/wallet-hsm-aws/package.json | 3 +- .../sdk/wallets/wallet-hsm-azure/package.json | 3 +- .../sdk/wallets/wallet-hsm-gcp/package.json | 3 +- packages/sdk/wallets/wallet-hsm/package.json | 3 +- .../sdk/wallets/wallet-ledger/package.json | 6 +- .../wallet-ledger/src/ledger-signer.ts | 14 +- .../wallet-ledger/src/ledger-wallet.test.ts | 128 +++--- .../wallet-ledger/src/ledger-wallet.ts | 9 +- .../sdk/wallets/wallet-ledger/src/types.d.ts | 18 + .../sdk/wallets/wallet-local/package.json | 3 +- .../wallets/wallet-local/src/local-signer.ts | 14 +- .../sdk/wallets/wallet-remote/package.json | 3 +- .../sdk/wallets/wallet-rpc/src/rpc-signer.ts | 6 +- yarn.lock | 132 ++---- 65 files changed, 1227 insertions(+), 693 deletions(-) create mode 100644 packages/docs/sdk/docs/cryptographic-utils/modules/wordlists.md create mode 100644 packages/docs/sdk/docs/wallet-ledger/interfaces/types.ILedger.md create mode 100644 packages/docs/sdk/docs/wallet-ledger/modules/types.md create mode 100644 packages/sdk/cryptographic-utils/src/bls.test.ts create mode 100644 packages/sdk/cryptographic-utils/src/wordlists.ts create mode 100644 packages/sdk/wallets/wallet-ledger/src/types.d.ts diff --git a/package.json b/package.json index 342cfa0cc..3bea1b75f 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ }, "resolutions": { "ganache": "npm:@celo/ganache@7.8.0-unofficial.0", - "bip39": "https://github.com/bitcoinjs/bip39#a7ecbfe2e60d0214ce17163d610cad9f7b23140c", "web3": "1.10.4", "web3-utils": "1.10.4", "blind-threshold-bls": "npm:@celo/blind-threshold-bls@1.0.0-beta", diff --git a/packages/cli/package.json b/packages/cli/package.json index 4f29098b9..5c08c7bc6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -56,9 +56,9 @@ "@oclif/plugin-not-found": "^3.0.9", "@oclif/plugin-plugins": "^4.1.17", "@oclif/plugin-warn-if-update-available": "^3.0.9", + "@scure/bip32": "^1.3.3", "@types/command-exists": "^1.2.3", "bignumber.js": "9.0.0", - "bip32": "3.1.0", "chalk": "^2.4.2", "command-exists": "^1.2.9", "cross-fetch": "3.1.5", diff --git a/packages/docs/sdk/docs/base/interfaces/account.Bip39.md b/packages/docs/sdk/docs/base/interfaces/account.Bip39.md index 04db09581..43b8c908c 100644 --- a/packages/docs/sdk/docs/base/interfaces/account.Bip39.md +++ b/packages/docs/sdk/docs/base/interfaces/account.Bip39.md @@ -43,11 +43,11 @@ ___ ### mnemonicToSeed -• **mnemonicToSeed**: (`mnemonic`: `string`, `password?`: `string`) => `Promise`\<`Buffer`\> +• **mnemonicToSeed**: (`mnemonic`: `string`, `password?`: `string`) => `Promise`\<`Uint8Array`\> #### Type declaration -▸ (`mnemonic`, `password?`): `Promise`\<`Buffer`\> +▸ (`mnemonic`, `password?`): `Promise`\<`Uint8Array`\> ##### Parameters @@ -58,7 +58,7 @@ ___ ##### Returns -`Promise`\<`Buffer`\> +`Promise`\<`Uint8Array`\> #### Defined in @@ -68,11 +68,11 @@ ___ ### mnemonicToSeedSync -• **mnemonicToSeedSync**: (`mnemonic`: `string`, `password?`: `string`) => `Buffer` +• **mnemonicToSeedSync**: (`mnemonic`: `string`, `password?`: `string`) => `Uint8Array` #### Type declaration -▸ (`mnemonic`, `password?`): `Buffer` +▸ (`mnemonic`, `password?`): `Uint8Array` ##### Parameters @@ -83,7 +83,7 @@ ___ ##### Returns -`Buffer` +`Uint8Array` #### Defined in diff --git a/packages/docs/sdk/docs/cryptographic-utils/interfaces/account.Bip39.md b/packages/docs/sdk/docs/cryptographic-utils/interfaces/account.Bip39.md index 3e9e4faa0..690daf184 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/interfaces/account.Bip39.md +++ b/packages/docs/sdk/docs/cryptographic-utils/interfaces/account.Bip39.md @@ -43,11 +43,11 @@ ___ ### mnemonicToSeed -• **mnemonicToSeed**: (`mnemonic`: `string`, `password?`: `string`) => `Promise`\<`Buffer`\> +• **mnemonicToSeed**: (`mnemonic`: `string`, `password?`: `string`) => `Promise`\<`Uint8Array`\> #### Type declaration -▸ (`mnemonic`, `password?`): `Promise`\<`Buffer`\> +▸ (`mnemonic`, `password?`): `Promise`\<`Uint8Array`\> ##### Parameters @@ -58,7 +58,7 @@ ___ ##### Returns -`Promise`\<`Buffer`\> +`Promise`\<`Uint8Array`\> #### Defined in @@ -68,11 +68,11 @@ ___ ### mnemonicToSeedSync -• **mnemonicToSeedSync**: (`mnemonic`: `string`, `password?`: `string`) => `Buffer` +• **mnemonicToSeedSync**: (`mnemonic`: `string`, `password?`: `string`) => `Uint8Array` #### Type declaration -▸ (`mnemonic`, `password?`): `Buffer` +▸ (`mnemonic`, `password?`): `Uint8Array` ##### Parameters @@ -83,7 +83,7 @@ ___ ##### Returns -`Buffer` +`Uint8Array` #### Defined in diff --git a/packages/docs/sdk/docs/cryptographic-utils/interfaces/commentEncryption.EncryptionStatus.md b/packages/docs/sdk/docs/cryptographic-utils/interfaces/commentEncryption.EncryptionStatus.md index 53fa2fdf5..2d9742098 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/interfaces/commentEncryption.EncryptionStatus.md +++ b/packages/docs/sdk/docs/cryptographic-utils/interfaces/commentEncryption.EncryptionStatus.md @@ -19,7 +19,7 @@ #### Defined in -[cryptographic-utils/src/commentEncryption.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L16) +[cryptographic-utils/src/commentEncryption.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L17) ___ @@ -29,4 +29,4 @@ ___ #### Defined in -[cryptographic-utils/src/commentEncryption.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L15) +[cryptographic-utils/src/commentEncryption.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L16) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules.md b/packages/docs/sdk/docs/cryptographic-utils/modules.md index 2dd2163c1..a65227d5b 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules.md @@ -12,3 +12,4 @@ - [dataEncryptionKey](modules/dataEncryptionKey.md) - [index](modules/index.md) - [types](modules/types.md) +- [wordlists](modules/wordlists.md) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/account.md b/packages/docs/sdk/docs/cryptographic-utils/modules/account.md index 1ffc4e1b2..5932c0726 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules/account.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/account.md @@ -32,6 +32,7 @@ - [generateMnemonic](account.md#generatemnemonic) - [generateSeed](account.md#generateseed) - [getAllLanguages](account.md#getalllanguages) +- [getWordList](account.md#getwordlist) - [invalidMnemonicWords](account.md#invalidmnemonicwords) - [mnemonicLengthFromStrength](account.md#mnemoniclengthfromstrength) - [normalizeMnemonic](account.md#normalizemnemonic) @@ -85,7 +86,7 @@ base/lib/account.d.ts:18 #### Defined in -[cryptographic-utils/src/account.ts:465](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L465) +[cryptographic-utils/src/account.ts:455](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L455) ___ @@ -125,7 +126,7 @@ malformed. It may occasionally occur that a typo results in word from another la #### Defined in -[cryptographic-utils/src/account.ts:233](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L233) +[cryptographic-utils/src/account.ts:220](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L220) ___ @@ -149,7 +150,7 @@ now an alias for normalizeMnemonic. #### Defined in -[cryptographic-utils/src/account.ts:159](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L159) +[cryptographic-utils/src/account.ts:166](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L166) ___ @@ -178,7 +179,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:416](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L416) +[cryptographic-utils/src/account.ts:403](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L403) ___ @@ -203,7 +204,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:403](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L403) +[cryptographic-utils/src/account.ts:390](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L390) ___ @@ -232,7 +233,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:444](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L444) +[cryptographic-utils/src/account.ts:431](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L431) ___ @@ -254,7 +255,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:54](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L54) +[cryptographic-utils/src/account.ts:61](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L61) ___ @@ -277,7 +278,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:429](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L429) +[cryptographic-utils/src/account.ts:416](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L416) ___ @@ -291,7 +292,27 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:188](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L188) +[cryptographic-utils/src/account.ts:175](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L175) + +___ + +### getWordList + +▸ **getWordList**(`language?`): `string`[] + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `language` | [`MnemonicLanguages`](../enums/account.MnemonicLanguages.md) | `MnemonicLanguages.english` | + +#### Returns + +`string`[] + +#### Defined in + +[cryptographic-utils/src/account.ts:171](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L171) ___ @@ -320,7 +341,7 @@ invalid, or half of the valid words are from one language and the other half fro #### Defined in -[cryptographic-utils/src/account.ts:88](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L88) +[cryptographic-utils/src/account.ts:95](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L95) ___ @@ -340,7 +361,7 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:202](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L202) +[cryptographic-utils/src/account.ts:189](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L189) ___ @@ -369,7 +390,7 @@ that all the words in the phrase are contained in a valid wordlist. #### Defined in -[cryptographic-utils/src/account.ts:109](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L109) +[cryptographic-utils/src/account.ts:116](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L116) ___ @@ -410,7 +431,7 @@ It is recommended to normalize the mnemonic phrase before inputting to this func #### Defined in -[cryptographic-utils/src/account.ts:288](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L288) +[cryptographic-utils/src/account.ts:275](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L275) ___ @@ -432,4 +453,4 @@ ___ #### Defined in -[cryptographic-utils/src/account.ts:62](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L62) +[cryptographic-utils/src/account.ts:69](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/account.ts#L69) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/bls.md b/packages/docs/sdk/docs/cryptographic-utils/modules/bls.md index fa57df6ce..964ec5fe9 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules/bls.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/bls.md @@ -23,7 +23,7 @@ #### Defined in -[cryptographic-utils/src/bls.ts:12](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L12) +[cryptographic-utils/src/bls.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L11) ___ @@ -33,13 +33,13 @@ ___ #### Defined in -[cryptographic-utils/src/bls.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L11) +[cryptographic-utils/src/bls.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L10) ## Functions ### blsPrivateKeyToProcessedPrivateKey -▸ **blsPrivateKeyToProcessedPrivateKey**(`privateKeyHex`): `any` +▸ **blsPrivateKeyToProcessedPrivateKey**(`privateKeyHex`): `Buffer` #### Parameters @@ -49,11 +49,11 @@ ___ #### Returns -`any` +`Buffer` #### Defined in -[cryptographic-utils/src/bls.ts:14](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L14) +[cryptographic-utils/src/bls.ts:13](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L13) ___ @@ -74,7 +74,7 @@ ___ #### Defined in -[cryptographic-utils/src/bls.ts:53](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L53) +[cryptographic-utils/src/bls.ts:51](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L51) ___ @@ -94,4 +94,4 @@ ___ #### Defined in -[cryptographic-utils/src/bls.ts:48](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L48) +[cryptographic-utils/src/bls.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/bls.ts#L46) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/commentEncryption.md b/packages/docs/sdk/docs/cryptographic-utils/modules/commentEncryption.md index 96f41052c..b38c10d2c 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules/commentEncryption.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/commentEncryption.md @@ -34,7 +34,7 @@ #### Defined in -[cryptographic-utils/src/commentEncryption.ts:115](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L115) +[cryptographic-utils/src/commentEncryption.ts:119](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L119) ## Functions @@ -61,7 +61,7 @@ Decrypted comment if can decrypt, otherwise comment. #### Defined in -[cryptographic-utils/src/commentEncryption.ts:104](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L104) +[cryptographic-utils/src/commentEncryption.ts:108](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L108) ___ @@ -87,7 +87,7 @@ Decrypted data. #### Defined in -[cryptographic-utils/src/commentEncryption.ts:45](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L45) +[cryptographic-utils/src/commentEncryption.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L46) ___ @@ -115,7 +115,7 @@ base64 string of encrypted comment if can encrypt, otherwise comment. #### Defined in -[cryptographic-utils/src/commentEncryption.ts:69](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L69) +[cryptographic-utils/src/commentEncryption.ts:73](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L73) ___ @@ -141,4 +141,4 @@ Encrypted data to sender and recipient. #### Defined in -[cryptographic-utils/src/commentEncryption.ts:27](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L27) +[cryptographic-utils/src/commentEncryption.ts:28](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/commentEncryption.ts#L28) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/dataEncryptionKey.md b/packages/docs/sdk/docs/cryptographic-utils/modules/dataEncryptionKey.md index e50421ae5..12a659b5f 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules/dataEncryptionKey.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/dataEncryptionKey.md @@ -30,7 +30,7 @@ #### Defined in -[cryptographic-utils/src/dataEncryptionKey.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L56) +[cryptographic-utils/src/dataEncryptionKey.ts:47](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L47) ## Functions @@ -50,11 +50,11 @@ Turns a private key to a compressed public key (hex string with hex leader). `string` -Corresponding compessed public key in hex encoding with '0x' leader. +Corresponding compressed public key in hex encoding with '0x' leader. #### Defined in -[cryptographic-utils/src/dataEncryptionKey.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L10) +[cryptographic-utils/src/dataEncryptionKey.ts:12](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L12) ___ @@ -79,7 +79,7 @@ Decompresssed public key without prefix. #### Defined in -[cryptographic-utils/src/dataEncryptionKey.ts:27](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L27) +[cryptographic-utils/src/dataEncryptionKey.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L23) ___ @@ -104,4 +104,4 @@ Comment Encryption Private key. #### Defined in -[cryptographic-utils/src/dataEncryptionKey.ts:42](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L42) +[cryptographic-utils/src/dataEncryptionKey.ts:33](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/dataEncryptionKey.ts#L33) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/index.md b/packages/docs/sdk/docs/cryptographic-utils/modules/index.md index a76fda8e3..a0b8a720d 100644 --- a/packages/docs/sdk/docs/cryptographic-utils/modules/index.md +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/index.md @@ -35,6 +35,7 @@ - [getAllLanguages](index.md#getalllanguages) - [getBlsPoP](index.md#getblspop) - [getBlsPublicKey](index.md#getblspublickey) +- [getWordList](index.md#getwordlist) - [invalidMnemonicWords](index.md#invalidmnemonicwords) - [mnemonicLengthFromStrength](index.md#mnemoniclengthfromstrength) - [normalizeMnemonic](index.md#normalizemnemonic) @@ -217,6 +218,12 @@ Re-exports [getBlsPublicKey](bls.md#getblspublickey) ___ +### getWordList + +Re-exports [getWordList](account.md#getwordlist) + +___ + ### invalidMnemonicWords Re-exports [invalidMnemonicWords](account.md#invalidmnemonicwords) diff --git a/packages/docs/sdk/docs/cryptographic-utils/modules/wordlists.md b/packages/docs/sdk/docs/cryptographic-utils/modules/wordlists.md new file mode 100644 index 000000000..31bf54b02 --- /dev/null +++ b/packages/docs/sdk/docs/cryptographic-utils/modules/wordlists.md @@ -0,0 +1,19 @@ +[@celo/cryptographic-utils](../README.md) / [Exports](../modules.md) / wordlists + +# Module: wordlists + +## Table of contents + +### Variables + +- [default](wordlists.md#default) + +## Variables + +### default + +• `Const` **default**: `Record`\<[`MnemonicLanguages`](../enums/account.MnemonicLanguages.md), `string`[]\> + +#### Defined in + +[cryptographic-utils/src/wordlists.ts:13](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/cryptographic-utils/src/wordlists.ts#L13) diff --git a/packages/docs/sdk/docs/utils/interfaces/istanbul.IstanbulExtra.md b/packages/docs/sdk/docs/utils/interfaces/istanbul.IstanbulExtra.md index bd41de4c3..73e9d68ba 100644 --- a/packages/docs/sdk/docs/utils/interfaces/istanbul.IstanbulExtra.md +++ b/packages/docs/sdk/docs/utils/interfaces/istanbul.IstanbulExtra.md @@ -23,7 +23,7 @@ #### Defined in -[packages/sdk/utils/src/istanbul.ts:22](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L22) +[packages/sdk/utils/src/istanbul.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L23) ___ @@ -33,7 +33,7 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L23) +[packages/sdk/utils/src/istanbul.ts:24](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L24) ___ @@ -43,7 +43,7 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:26](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L26) +[packages/sdk/utils/src/istanbul.ts:27](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L27) ___ @@ -53,7 +53,7 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:27](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L27) +[packages/sdk/utils/src/istanbul.ts:28](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L28) ___ @@ -63,7 +63,7 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:24](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L24) +[packages/sdk/utils/src/istanbul.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L25) ___ @@ -73,4 +73,4 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L25) +[packages/sdk/utils/src/istanbul.ts:26](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L26) diff --git a/packages/docs/sdk/docs/utils/interfaces/istanbul.Seal.md b/packages/docs/sdk/docs/utils/interfaces/istanbul.Seal.md index 05d2e05f8..d39161d9b 100644 --- a/packages/docs/sdk/docs/utils/interfaces/istanbul.Seal.md +++ b/packages/docs/sdk/docs/utils/interfaces/istanbul.Seal.md @@ -20,7 +20,7 @@ #### Defined in -[packages/sdk/utils/src/istanbul.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L15) +[packages/sdk/utils/src/istanbul.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L16) ___ @@ -30,7 +30,7 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L17) +[packages/sdk/utils/src/istanbul.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L18) ___ @@ -40,4 +40,4 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L16) +[packages/sdk/utils/src/istanbul.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L17) diff --git a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712Parameter.md b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712Parameter.md index 56f0d7fef..0d038e838 100644 --- a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712Parameter.md +++ b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712Parameter.md @@ -19,7 +19,7 @@ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L10) +[packages/sdk/utils/src/sign-typed-data-utils.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L9) ___ @@ -29,4 +29,4 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L11) +[packages/sdk/utils/src/sign-typed-data-utils.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L10) diff --git a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypedData.md b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypedData.md index 93b565fd3..c76cad3ab 100644 --- a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypedData.md +++ b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypedData.md @@ -21,7 +21,7 @@ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:38](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L38) +[packages/sdk/utils/src/sign-typed-data-utils.ts:37](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L37) ___ @@ -31,7 +31,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:39](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L39) +[packages/sdk/utils/src/sign-typed-data-utils.ts:38](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L38) ___ @@ -41,7 +41,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:40](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L40) +[packages/sdk/utils/src/sign-typed-data-utils.ts:39](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L39) ___ @@ -51,4 +51,4 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:37](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L37) +[packages/sdk/utils/src/sign-typed-data-utils.ts:36](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L36) diff --git a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypesWithPrimary.md b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypesWithPrimary.md index b0d00d733..d01d88fa3 100644 --- a/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypesWithPrimary.md +++ b/packages/docs/sdk/docs/utils/interfaces/sign_typed_data_utils.EIP712TypesWithPrimary.md @@ -19,7 +19,7 @@ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:20](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L20) +[packages/sdk/utils/src/sign-typed-data-utils.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L19) ___ @@ -29,4 +29,4 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L19) +[packages/sdk/utils/src/sign-typed-data-utils.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L18) diff --git a/packages/docs/sdk/docs/utils/modules/ecdh.md b/packages/docs/sdk/docs/utils/modules/ecdh.md index c932e9af1..66adeb1fc 100644 --- a/packages/docs/sdk/docs/utils/modules/ecdh.md +++ b/packages/docs/sdk/docs/utils/modules/ecdh.md @@ -51,13 +51,13 @@ ___ #### Defined in -[packages/sdk/utils/src/ecdh.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L18) +[packages/sdk/utils/src/ecdh.ts:21](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L21) ___ ### ensureUncompressed -▸ **ensureUncompressed**(`publicKey`): `any` +▸ **ensureUncompressed**(`publicKey`): `Uint8Array` #### Parameters @@ -67,7 +67,7 @@ ___ #### Returns -`any` +`Uint8Array` #### Defined in @@ -91,7 +91,7 @@ ___ #### Defined in -[packages/sdk/utils/src/ecdh.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L10) +[packages/sdk/utils/src/ecdh.ts:13](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L13) ___ @@ -111,4 +111,4 @@ ___ #### Defined in -[packages/sdk/utils/src/ecdh.ts:40](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L40) +[packages/sdk/utils/src/ecdh.ts:32](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecdh.ts#L32) diff --git a/packages/docs/sdk/docs/utils/modules/ecies.md b/packages/docs/sdk/docs/utils/modules/ecies.md index e42535cde..60d4b0a17 100644 --- a/packages/docs/sdk/docs/utils/modules/ecies.md +++ b/packages/docs/sdk/docs/utils/modules/ecies.md @@ -15,6 +15,7 @@ - [AES128DecryptAndHMAC](ecies.md#aes128decryptandhmac) - [AES128Encrypt](ecies.md#aes128encrypt) - [AES128EncryptAndHMAC](ecies.md#aes128encryptandhmac) +- [ConcatKDF](ecies.md#concatkdf) - [Decrypt](ecies.md#decrypt) - [Encrypt](ecies.md#encrypt) @@ -28,14 +29,14 @@ | Name | Type | | :------ | :------ | -| `AES128DecryptAndHMAC` | (`encryptionKey`: `Buffer`, `macKey`: `Buffer`, `ciphertext`: `Buffer`) => `Buffer` | -| `AES128EncryptAndHMAC` | (`encryptionKey`: `Buffer`, `macKey`: `Buffer`, `plaintext`: `Buffer`) => `Buffer` | -| `Decrypt` | (`privKey`: `Buffer`, `encrypted`: `Buffer`) => `Buffer` | -| `Encrypt` | (`pubKeyTo`: `Buffer`, `plaintext`: `Buffer`) => `Buffer` | +| `AES128DecryptAndHMAC` | (`encryptionKey`: `Uint8Array`, `macKey`: `Uint8Array`, `ciphertext`: `Uint8Array`) => `Uint8Array` | +| `AES128EncryptAndHMAC` | (`encryptionKey`: `Uint8Array`, `macKey`: `Uint8Array`, `plaintext`: `Uint8Array`) => `Uint8Array` | +| `Decrypt` | (`privKey`: `PrivKey`, `encrypted`: `Buffer`) => `Uint8Array` | +| `Encrypt` | (`pubKeyTo`: `PubKey`, `plaintext`: `Uint8Array`) => `Buffer` | #### Defined in -[packages/sdk/utils/src/ecies.ts:184](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L184) +[packages/sdk/utils/src/ecies.ts:199](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L199) ___ @@ -45,13 +46,13 @@ ___ #### Defined in -[packages/sdk/utils/src/ecies.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L11) +[packages/sdk/utils/src/ecies.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L18) ## Functions ### AES128Decrypt -▸ **AES128Decrypt**(`encryptionKey`, `iv`, `ciphertext`): `Buffer` +▸ **AES128Decrypt**(`encryptionKey`, `iv`, `ciphertext`): `Uint8Array` AES-128 CTR decrypt @@ -59,25 +60,25 @@ AES-128 CTR decrypt | Name | Type | | :------ | :------ | -| `encryptionKey` | `Buffer` | -| `iv` | `Buffer` | -| `ciphertext` | `Buffer` | +| `encryptionKey` | `Uint8Array` | +| `iv` | `Uint8Array` | +| `ciphertext` | `Uint8Array` | #### Returns -`Buffer` +`Uint8Array` plaintext #### Defined in -[packages/sdk/utils/src/ecies.ts:96](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L96) +[packages/sdk/utils/src/ecies.ts:106](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L106) ___ ### AES128DecryptAndHMAC -▸ **AES128DecryptAndHMAC**(`encryptionKey`, `macKey`, `ciphertext`): `Buffer` +▸ **AES128DecryptAndHMAC**(`encryptionKey`, `macKey`, `ciphertext`): `Uint8Array` AES-128 CTR decrypt with message authentication @@ -85,25 +86,25 @@ AES-128 CTR decrypt with message authentication | Name | Type | | :------ | :------ | -| `encryptionKey` | `Buffer` | -| `macKey` | `Buffer` | -| `ciphertext` | `Buffer` | +| `encryptionKey` | `Uint8Array` | +| `macKey` | `Uint8Array` | +| `ciphertext` | `Uint8Array` | #### Returns -`Buffer` +`Uint8Array` plaintext #### Defined in -[packages/sdk/utils/src/ecies.ts:111](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L111) +[packages/sdk/utils/src/ecies.ts:122](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L122) ___ ### AES128Encrypt -▸ **AES128Encrypt**(`encryptionKey`, `iv`, `plaintext`): `Buffer` +▸ **AES128Encrypt**(`encryptionKey`, `iv`, `plaintext`): `Uint8Array` AES-128 CTR encrypt @@ -111,25 +112,25 @@ AES-128 CTR encrypt | Name | Type | | :------ | :------ | -| `encryptionKey` | `Buffer` | -| `iv` | `Buffer` | -| `plaintext` | `Buffer` | +| `encryptionKey` | `Uint8Array` | +| `iv` | `Uint8Array` | +| `plaintext` | `Uint8Array` | #### Returns -`Buffer` +`Uint8Array` ciphertext #### Defined in -[packages/sdk/utils/src/ecies.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L63) +[packages/sdk/utils/src/ecies.ts:70](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L70) ___ ### AES128EncryptAndHMAC -▸ **AES128EncryptAndHMAC**(`encryptionKey`, `macKey`, `plaintext`): `Buffer` +▸ **AES128EncryptAndHMAC**(`encryptionKey`, `macKey`, `plaintext`): `Uint8Array` AES-128 CTR encrypt with message authentication @@ -137,25 +138,55 @@ AES-128 CTR encrypt with message authentication | Name | Type | | :------ | :------ | -| `encryptionKey` | `Buffer` | -| `macKey` | `Buffer` | -| `plaintext` | `Buffer` | +| `encryptionKey` | `Uint8Array` | +| `macKey` | `Uint8Array` | +| `plaintext` | `Uint8Array` | #### Returns -`Buffer` +`Uint8Array` ciphertext #### Defined in -[packages/sdk/utils/src/ecies.ts:77](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L77) +[packages/sdk/utils/src/ecies.ts:88](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L88) + +___ + +### ConcatKDF + +▸ **ConcatKDF**(`px`, `kdLen`): `Buffer` + +NIST 8000-56C Rev 1 One Step KDF with the following parameters: +- H(x) is SHA-256(x) +- Fixed info is null + +TODO: +- Implement proper ceiling on reps. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `px` | `Buffer` | Input keying material to derive key from. | +| `kdLen` | `number` | Length of output in bytes | + +#### Returns + +`Buffer` + +Output keying material of length kdLen bytes. + +#### Defined in + +[packages/sdk/utils/src/ecies.ts:48](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L48) ___ ### Decrypt -▸ **Decrypt**(`privKey`, `encrypted`): `Buffer` +▸ **Decrypt**(`privKey`, `encrypted`): `Uint8Array` ECIES decrypt @@ -163,18 +194,18 @@ ECIES decrypt | Name | Type | Description | | :------ | :------ | :------ | -| `privKey` | `Buffer` | Ethereum private key, 32 bytes. | +| `privKey` | `PrivKey` | Ethereum private key, 32 bytes. | | `encrypted` | `Buffer` | Encrypted message, serialized, 113+ bytes | #### Returns -`Buffer` +`Uint8Array` plaintext #### Defined in -[packages/sdk/utils/src/ecies.ts:163](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L163) +[packages/sdk/utils/src/ecies.ts:179](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L179) ___ @@ -188,8 +219,8 @@ ECIES encrypt | Name | Type | Description | | :------ | :------ | :------ | -| `pubKeyTo` | `Buffer` | Ethereum pub key, 64 bytes. | -| `plaintext` | `Buffer` | Plaintext to be encrypted. | +| `pubKeyTo` | `PubKey` | Ethereum pub key, 64 bytes. | +| `plaintext` | `Uint8Array` | Plaintext to be encrypted. | #### Returns @@ -199,4 +230,4 @@ Encrypted message, serialized, 113+ bytes #### Defined in -[packages/sdk/utils/src/ecies.ts:134](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L134) +[packages/sdk/utils/src/ecies.ts:145](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/ecies.ts#L145) diff --git a/packages/docs/sdk/docs/utils/modules/istanbul.md b/packages/docs/sdk/docs/utils/modules/istanbul.md index 77679fa64..624a63aa5 100644 --- a/packages/docs/sdk/docs/utils/modules/istanbul.md +++ b/packages/docs/sdk/docs/utils/modules/istanbul.md @@ -30,7 +30,7 @@ #### Defined in -[packages/sdk/utils/src/istanbul.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L11) +[packages/sdk/utils/src/istanbul.ts:12](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L12) ## Variables @@ -47,7 +47,7 @@ #### Defined in -[packages/sdk/utils/src/istanbul.ts:66](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L66) +[packages/sdk/utils/src/istanbul.ts:72](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L72) ## Functions @@ -68,7 +68,7 @@ #### Defined in -[packages/sdk/utils/src/istanbul.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L56) +[packages/sdk/utils/src/istanbul.ts:62](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L62) ___ @@ -88,4 +88,4 @@ ___ #### Defined in -[packages/sdk/utils/src/istanbul.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L43) +[packages/sdk/utils/src/istanbul.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/istanbul.ts#L44) diff --git a/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md b/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md index 355f15173..295436f8d 100644 --- a/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md +++ b/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md @@ -46,7 +46,7 @@ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L23) +[packages/sdk/utils/src/sign-typed-data-utils.ts:22](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L22) ___ @@ -76,7 +76,7 @@ EIP712Optonal is not part of the EIP712 standard, but is fully compatible with i #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:81](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L81) +[packages/sdk/utils/src/sign-typed-data-utils.ts:80](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L80) ## Variables @@ -88,7 +88,7 @@ Array of all EIP-712 atomic type names. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L44) +[packages/sdk/utils/src/sign-typed-data-utils.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L43) ___ @@ -98,7 +98,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:64](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L64) +[packages/sdk/utils/src/sign-typed-data-utils.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L63) ___ @@ -108,7 +108,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:62](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L62) +[packages/sdk/utils/src/sign-typed-data-utils.ts:61](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L61) ___ @@ -120,7 +120,7 @@ Undefined EIP712Optional type with value type boolean. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:115](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L115) +[packages/sdk/utils/src/sign-typed-data-utils.ts:114](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L114) ___ @@ -132,7 +132,7 @@ Undefined EIP712Optional type with value type number. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:121](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L121) +[packages/sdk/utils/src/sign-typed-data-utils.ts:120](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L120) ___ @@ -144,7 +144,7 @@ Undefined EIP712Optional type with value type string. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:127](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L127) +[packages/sdk/utils/src/sign-typed-data-utils.ts:126](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L126) ## Functions @@ -172,7 +172,7 @@ Utility to construct an defined EIP712Optional value with inferred type. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:109](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L109) +[packages/sdk/utils/src/sign-typed-data-utils.ts:108](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L108) ___ @@ -200,7 +200,7 @@ Utility to build EIP712Optional schemas for encoding and decoding with io-ts. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:102](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L102) +[packages/sdk/utils/src/sign-typed-data-utils.ts:101](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L101) ___ @@ -222,7 +222,7 @@ Utility to build EIP712Optional types to insert in EIP-712 type arrays. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:91](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L91) +[packages/sdk/utils/src/sign-typed-data-utils.ts:90](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L90) ___ @@ -246,7 +246,7 @@ Constructs the struct encoding of the data as the primary type. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:248](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L248) +[packages/sdk/utils/src/sign-typed-data-utils.ts:251](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L251) ___ @@ -270,7 +270,7 @@ E.g. "Transaction(Person from,Person to,Asset tx)Asset(address token,uint256 amo #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:183](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L183) +[packages/sdk/utils/src/sign-typed-data-utils.ts:184](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L184) ___ @@ -294,7 +294,7 @@ A Buffer containing the hash of the typed data. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:137](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L137) +[packages/sdk/utils/src/sign-typed-data-utils.ts:136](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L136) ___ @@ -316,7 +316,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:257](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L257) +[packages/sdk/utils/src/sign-typed-data-utils.ts:260](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L260) ___ @@ -337,7 +337,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:194](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L194) +[packages/sdk/utils/src/sign-typed-data-utils.ts:195](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L195) ___ @@ -368,4 +368,4 @@ Note that EIP-712 does not specify zero values, and so this is non-standard. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:273](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L273) +[packages/sdk/utils/src/sign-typed-data-utils.ts:276](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L276) diff --git a/packages/docs/sdk/docs/wallet-base/modules/index.md b/packages/docs/sdk/docs/wallet-base/modules/index.md index 7227e45a8..5a5a4a2c5 100644 --- a/packages/docs/sdk/docs/wallet-base/modules/index.md +++ b/packages/docs/sdk/docs/wallet-base/modules/index.md @@ -15,11 +15,16 @@ - [extractSignature](index.md#extractsignature) - [getHashFromEncoded](index.md#gethashfromencoded) - [getSignerFromTxEIP2718TX](index.md#getsignerfromtxeip2718tx) +- [handleBigInt](index.md#handlebigint) +- [handleData](index.md#handledata) +- [handleHexString](index.md#handlehexstring) +- [handleNumber](index.md#handlenumber) - [isPriceToLow](index.md#ispricetolow) - [publicKeyPrefix](index.md#publickeyprefix) - [recoverMessageSigner](index.md#recovermessagesigner) - [recoverTransaction](index.md#recovertransaction) - [rlpEncodedTx](index.md#rlpencodedtx) +- [signTransaction](index.md#signtransaction) - [sixtyFour](index.md#sixtyfour) - [stringNumberOrBNToHex](index.md#stringnumberorbntohex) - [thirtyTwo](index.md#thirtytwo) @@ -82,6 +87,30 @@ Re-exports [getSignerFromTxEIP2718TX](signing_utils.md#getsignerfromtxeip2718tx) ___ +### handleBigInt + +Re-exports [handleBigInt](signing_utils.md#handlebigint) + +___ + +### handleData + +Re-exports [handleData](signing_utils.md#handledata) + +___ + +### handleHexString + +Re-exports [handleHexString](signing_utils.md#handlehexstring) + +___ + +### handleNumber + +Re-exports [handleNumber](signing_utils.md#handlenumber) + +___ + ### isPriceToLow Re-exports [isPriceToLow](signing_utils.md#ispricetolow) @@ -112,6 +141,12 @@ Re-exports [rlpEncodedTx](signing_utils.md#rlpencodedtx) ___ +### signTransaction + +Re-exports [signTransaction](signing_utils.md#signtransaction) + +___ + ### sixtyFour Re-exports [sixtyFour](signing_utils.md#sixtyfour) diff --git a/packages/docs/sdk/docs/wallet-base/modules/signing_utils.md b/packages/docs/sdk/docs/wallet-base/modules/signing_utils.md index d1d08af50..ebf09d040 100644 --- a/packages/docs/sdk/docs/wallet-base/modules/signing_utils.md +++ b/packages/docs/sdk/docs/wallet-base/modules/signing_utils.md @@ -18,10 +18,15 @@ - [extractSignature](signing_utils.md#extractsignature) - [getHashFromEncoded](signing_utils.md#gethashfromencoded) - [getSignerFromTxEIP2718TX](signing_utils.md#getsignerfromtxeip2718tx) +- [handleBigInt](signing_utils.md#handlebigint) +- [handleData](signing_utils.md#handledata) +- [handleHexString](signing_utils.md#handlehexstring) +- [handleNumber](signing_utils.md#handlenumber) - [isPriceToLow](signing_utils.md#ispricetolow) - [recoverMessageSigner](signing_utils.md#recovermessagesigner) - [recoverTransaction](signing_utils.md#recovertransaction) - [rlpEncodedTx](signing_utils.md#rlpencodedtx) +- [signTransaction](signing_utils.md#signtransaction) - [stringNumberOrBNToHex](signing_utils.md#stringnumberorbntohex) - [verifyEIP712TypedDataSigner](signing_utils.md#verifyeip712typeddatasigner) - [verifySignatureWithoutPrefix](signing_utils.md#verifysignaturewithoutprefix) @@ -34,7 +39,7 @@ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L44) +[wallets/wallet-base/src/signing-utils.ts:40](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L40) ___ @@ -44,7 +49,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:45](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L45) +[wallets/wallet-base/src/signing-utils.ts:41](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L41) ___ @@ -54,7 +59,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L46) +[wallets/wallet-base/src/signing-utils.ts:42](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L42) ## Functions @@ -80,13 +85,14 @@ ___ ### decodeSig -▸ **decodeSig**(`sig`): `Object` +▸ **decodeSig**(`sig`, `addToV?`): `Object` #### Parameters -| Name | Type | -| :------ | :------ | -| `sig` | `any` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `sig` | \`0x$\{string}\` \| `RecoveredSignatureType` | `undefined` | +| `addToV` | `number` | `0` | #### Returns @@ -100,7 +106,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:774](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L774) +[wallets/wallet-base/src/signing-utils.ts:796](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L796) ___ @@ -124,7 +130,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:348](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L348) +[wallets/wallet-base/src/signing-utils.ts:350](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L350) ___ @@ -144,19 +150,19 @@ ___ | Name | Type | | :------ | :------ | -| `r` | `string` | -| `s` | `string` | -| `v` | `undefined` \| `string` | +| `r` | \`0x$\{string}\` | +| `s` | \`0x$\{string}\` | +| `v` | \`0x$\{string}\` | #### Defined in -[wallets/wallet-base/src/signing-utils.ts:445](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L445) +[wallets/wallet-base/src/signing-utils.ts:444](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L444) ___ ### getHashFromEncoded -▸ **getHashFromEncoded**(`rlpEncode`): `string` +▸ **getHashFromEncoded**(`rlpEncode`): `StrongAddress` #### Parameters @@ -166,7 +172,7 @@ ___ #### Returns -`string` +`StrongAddress` #### Defined in @@ -190,7 +196,87 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:518](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L518) +[wallets/wallet-base/src/signing-utils.ts:514](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L514) + +___ + +### handleBigInt + +▸ **handleBigInt**(`n`): `bigint` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `n` | `Uint8Array` | + +#### Returns + +`bigint` + +#### Defined in + +[wallets/wallet-base/src/signing-utils.ts:821](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L821) + +___ + +### handleData + +▸ **handleData**(`data`): `string` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | `Uint8Array` | + +#### Returns + +`string` + +#### Defined in + +[wallets/wallet-base/src/signing-utils.ts:835](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L835) + +___ + +### handleHexString + +▸ **handleHexString**(`adr`): `StrongAddress` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `adr` | `Uint8Array` | + +#### Returns + +`StrongAddress` + +#### Defined in + +[wallets/wallet-base/src/signing-utils.ts:827](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L827) + +___ + +### handleNumber + +▸ **handleNumber**(`n`): `number` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `n` | `Uint8Array` | + +#### Returns + +`number` + +#### Defined in + +[wallets/wallet-base/src/signing-utils.ts:815](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L815) ___ @@ -210,7 +296,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:290](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L290) +[wallets/wallet-base/src/signing-utils.ts:292](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L292) ___ @@ -231,7 +317,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:742](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L742) +[wallets/wallet-base/src/signing-utils.ts:764](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L764) ___ @@ -251,7 +337,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:479](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L479) +[wallets/wallet-base/src/signing-utils.ts:475](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L475) ___ @@ -271,13 +357,41 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:113](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L113) +[wallets/wallet-base/src/signing-utils.ts:115](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L115) + +___ + +### signTransaction + +▸ **signTransaction**(`hash`, `privateKey`, `addToV?`): `Object` + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `hash` | \`0x$\{string}\` | `undefined` | +| `privateKey` | \`0x$\{string}\` | `undefined` | +| `addToV` | `number` | `0` | + +#### Returns + +`Object` + +| Name | Type | +| :------ | :------ | +| `r` | `Buffer` | +| `s` | `Buffer` | +| `v` | `number` | + +#### Defined in + +[wallets/wallet-base/src/signing-utils.ts:806](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L806) ___ ### stringNumberOrBNToHex -▸ **stringNumberOrBNToHex**(`num?`): `Hex` +▸ **stringNumberOrBNToHex**(`num?`): `StrongAddress` #### Parameters @@ -287,11 +401,11 @@ ___ #### Returns -`Hex` +`StrongAddress` #### Defined in -[wallets/wallet-base/src/signing-utils.ts:97](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L97) +[wallets/wallet-base/src/signing-utils.ts:99](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L99) ___ @@ -313,7 +427,7 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:752](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L752) +[wallets/wallet-base/src/signing-utils.ts:774](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L774) ___ @@ -335,4 +449,4 @@ ___ #### Defined in -[wallets/wallet-base/src/signing-utils.ts:761](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L761) +[wallets/wallet-base/src/signing-utils.ts:783](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-base/src/signing-utils.ts#L783) diff --git a/packages/docs/sdk/docs/wallet-hsm-aws/classes/aws_hsm_signer.AwsHsmSigner.md b/packages/docs/sdk/docs/wallet-hsm-aws/classes/aws_hsm_signer.AwsHsmSigner.md index 10a97d1bf..0c3297240 100644 --- a/packages/docs/sdk/docs/wallet-hsm-aws/classes/aws_hsm_signer.AwsHsmSigner.md +++ b/packages/docs/sdk/docs/wallet-hsm-aws/classes/aws_hsm_signer.AwsHsmSigner.md @@ -43,7 +43,7 @@ #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:26](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L26) +[wallet-hsm-aws/src/aws-hsm-signer.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L25) ## Methods @@ -67,7 +67,7 @@ Signer.computeSharedSecret #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:112](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L112) +[wallet-hsm-aws/src/aws-hsm-signer.ts:117](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L117) ___ @@ -91,7 +91,7 @@ Signer.decrypt #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:106](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L106) +[wallet-hsm-aws/src/aws-hsm-signer.ts:111](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L111) ___ @@ -109,7 +109,7 @@ Signer.getNativeKey #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:102](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L102) +[wallet-hsm-aws/src/aws-hsm-signer.ts:107](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L107) ___ @@ -133,7 +133,7 @@ Signer.signPersonalMessage #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:79](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L79) +[wallet-hsm-aws/src/aws-hsm-signer.ts:84](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L84) ___ @@ -158,7 +158,7 @@ Signer.signTransaction #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:67](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L67) +[wallet-hsm-aws/src/aws-hsm-signer.ts:72](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L72) ___ @@ -182,4 +182,4 @@ Signer.signTypedData #### Defined in -[wallet-hsm-aws/src/aws-hsm-signer.ts:91](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L91) +[wallet-hsm-aws/src/aws-hsm-signer.ts:96](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-aws/src/aws-hsm-signer.ts#L96) diff --git a/packages/docs/sdk/docs/wallet-hsm-gcp/classes/gcp_hsm_signer.GcpHsmSigner.md b/packages/docs/sdk/docs/wallet-hsm-gcp/classes/gcp_hsm_signer.GcpHsmSigner.md index b2369e9ae..8688a4442 100644 --- a/packages/docs/sdk/docs/wallet-hsm-gcp/classes/gcp_hsm_signer.GcpHsmSigner.md +++ b/packages/docs/sdk/docs/wallet-hsm-gcp/classes/gcp_hsm_signer.GcpHsmSigner.md @@ -67,7 +67,7 @@ Signer.computeSharedSecret #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:108](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L108) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:115](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L115) ___ @@ -91,7 +91,7 @@ Signer.decrypt #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:102](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L102) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:109](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L109) ___ @@ -109,7 +109,7 @@ Signer.getNativeKey #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:98](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L98) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:105](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L105) ___ @@ -133,7 +133,7 @@ Signer.signPersonalMessage #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:75](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L75) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:82](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L82) ___ @@ -158,7 +158,7 @@ Signer.signTransaction #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L63) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:70](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L70) ___ @@ -182,4 +182,4 @@ Signer.signTypedData #### Defined in -[wallet-hsm-gcp/src/gcp-hsm-signer.ts:87](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L87) +[wallet-hsm-gcp/src/gcp-hsm-signer.ts:94](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm-gcp/src/gcp-hsm-signer.ts#L94) diff --git a/packages/docs/sdk/docs/wallet-hsm/classes/signature_utils.Signature.md b/packages/docs/sdk/docs/wallet-hsm/classes/signature_utils.Signature.md index 9938b08a8..a0d6224cb 100644 --- a/packages/docs/sdk/docs/wallet-hsm/classes/signature_utils.Signature.md +++ b/packages/docs/sdk/docs/wallet-hsm/classes/signature_utils.Signature.md @@ -36,7 +36,7 @@ #### Defined in -[signature-utils.ts:48](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L48) +[signature-utils.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L46) ## Properties @@ -46,7 +46,7 @@ #### Defined in -[signature-utils.ts:45](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L45) +[signature-utils.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L43) ___ @@ -56,7 +56,7 @@ ___ #### Defined in -[signature-utils.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L46) +[signature-utils.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L44) ___ @@ -66,4 +66,4 @@ ___ #### Defined in -[signature-utils.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L44) +[signature-utils.ts:42](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L42) diff --git a/packages/docs/sdk/docs/wallet-hsm/modules/signature_utils.md b/packages/docs/sdk/docs/wallet-hsm/modules/signature_utils.md index d0b9c5b67..5eb11d69b 100644 --- a/packages/docs/sdk/docs/wallet-hsm/modules/signature_utils.md +++ b/packages/docs/sdk/docs/wallet-hsm/modules/signature_utils.md @@ -30,7 +30,7 @@ #### Defined in -[signature-utils.ts:8](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L8) +[signature-utils.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L9) ___ @@ -40,7 +40,7 @@ ___ #### Defined in -[signature-utils.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L9) +[signature-utils.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L10) ___ @@ -50,7 +50,7 @@ ___ #### Defined in -[signature-utils.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L10) +[signature-utils.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L11) ## Functions @@ -71,7 +71,7 @@ ___ #### Defined in -[signature-utils.ts:34](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L34) +[signature-utils.ts:32](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L32) ___ @@ -91,7 +91,7 @@ ___ #### Defined in -[signature-utils.ts:30](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L30) +[signature-utils.ts:28](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L28) ___ @@ -111,7 +111,7 @@ ___ #### Defined in -[signature-utils.ts:78](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L78) +[signature-utils.ts:99](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L99) ___ @@ -136,13 +136,13 @@ https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#Low_S_values_in_s #### Defined in -[signature-utils.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L18) +[signature-utils.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L19) ___ ### recoverKeyIndex -▸ **recoverKeyIndex**(`signature`, `publicKey`, `hash`): `number` +▸ **recoverKeyIndex**(`signature`, `_publicKey`, `hash`): `number` Attempts each recovery key to find a match @@ -151,7 +151,7 @@ Attempts each recovery key to find a match | Name | Type | | :------ | :------ | | `signature` | `Uint8Array` | -| `publicKey` | `BigNumber` | +| `_publicKey` | `BigNumber` | | `hash` | `Uint8Array` | #### Returns @@ -160,4 +160,4 @@ Attempts each recovery key to find a match #### Defined in -[signature-utils.ts:58](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L58) +[signature-utils.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-hsm/src/signature-utils.ts#L56) diff --git a/packages/docs/sdk/docs/wallet-ledger/README.md b/packages/docs/sdk/docs/wallet-ledger/README.md index be7dbb496..8843df04f 100644 --- a/packages/docs/sdk/docs/wallet-ledger/README.md +++ b/packages/docs/sdk/docs/wallet-ledger/README.md @@ -12,3 +12,4 @@ - [ledger-utils](modules/ledger_utils.md) - [ledger-wallet](modules/ledger_wallet.md) - [tokens](modules/tokens.md) +- [types](modules/types.md) diff --git a/packages/docs/sdk/docs/wallet-ledger/classes/ledger_signer.LedgerSigner.md b/packages/docs/sdk/docs/wallet-ledger/classes/ledger_signer.LedgerSigner.md index 0b7a4414e..47e6f4bb1 100644 --- a/packages/docs/sdk/docs/wallet-ledger/classes/ledger_signer.LedgerSigner.md +++ b/packages/docs/sdk/docs/wallet-ledger/classes/ledger_signer.LedgerSigner.md @@ -35,7 +35,7 @@ Signs the EVM transaction with a Ledger device | Name | Type | | :------ | :------ | -| `ledger` | `any` | +| `ledger` | [`ILedger`](../interfaces/types.ILedger.md) | | `derivationPath` | `string` | | `ledgerAddressValidation` | [`AddressValidation`](../enums/ledger_wallet.AddressValidation.md) | | `appConfiguration` | `Object` | @@ -48,7 +48,7 @@ Signs the EVM transaction with a Ledger device #### Defined in -[wallet-ledger/src/ledger-signer.ts:24](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L24) +[wallet-ledger/src/ledger-signer.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L25) ## Methods @@ -114,7 +114,7 @@ Signer.getNativeKey #### Defined in -[wallet-ledger/src/ledger-signer.ts:39](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L39) +[wallet-ledger/src/ledger-signer.ts:40](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L40) ___ @@ -163,7 +163,7 @@ Signer.signTransaction #### Defined in -[wallet-ledger/src/ledger-signer.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L43) +[wallet-ledger/src/ledger-signer.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L44) ___ @@ -187,4 +187,4 @@ Signer.signTypedData #### Defined in -[wallet-ledger/src/ledger-signer.ts:103](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L103) +[wallet-ledger/src/ledger-signer.ts:102](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts#L102) diff --git a/packages/docs/sdk/docs/wallet-ledger/classes/ledger_wallet.LedgerWallet.md b/packages/docs/sdk/docs/wallet-ledger/classes/ledger_wallet.LedgerWallet.md index 8bc189d59..61216db4f 100644 --- a/packages/docs/sdk/docs/wallet-ledger/classes/ledger_wallet.LedgerWallet.md +++ b/packages/docs/sdk/docs/wallet-ledger/classes/ledger_wallet.LedgerWallet.md @@ -65,7 +65,7 @@ RemoteWallet\<LedgerSigner\>.constructor #### Defined in -[wallet-ledger/src/ledger-wallet.ts:55](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L55) +[wallet-ledger/src/ledger-wallet.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L56) ## Properties @@ -77,7 +77,7 @@ base derivation path. Default: "44'/52752'/0'/0" #### Defined in -[wallet-ledger/src/ledger-wallet.ts:57](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L57) +[wallet-ledger/src/ledger-wallet.ts:58](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L58) ___ @@ -92,7 +92,7 @@ Example: [3, 99, 53] will retrieve the derivation paths of #### Defined in -[wallet-ledger/src/ledger-wallet.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L56) +[wallet-ledger/src/ledger-wallet.ts:57](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L57) ___ @@ -124,7 +124,7 @@ ___ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:59](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L59) +[wallet-ledger/src/ledger-wallet.ts:60](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L60) ___ @@ -136,7 +136,7 @@ Transport to connect the ledger device #### Defined in -[wallet-ledger/src/ledger-wallet.ts:58](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L58) +[wallet-ledger/src/ledger-wallet.ts:59](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L59) ## Methods @@ -360,7 +360,7 @@ RemoteWallet.signTransaction #### Defined in -[wallet-ledger/src/ledger-wallet.ts:70](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L70) +[wallet-ledger/src/ledger-wallet.ts:71](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L71) ___ diff --git a/packages/docs/sdk/docs/wallet-ledger/enums/ledger_wallet.AddressValidation.md b/packages/docs/sdk/docs/wallet-ledger/enums/ledger_wallet.AddressValidation.md index c601e3478..fac61ee74 100644 --- a/packages/docs/sdk/docs/wallet-ledger/enums/ledger_wallet.AddressValidation.md +++ b/packages/docs/sdk/docs/wallet-ledger/enums/ledger_wallet.AddressValidation.md @@ -21,7 +21,7 @@ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L19) +[wallet-ledger/src/ledger-wallet.ts:20](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L20) ___ @@ -31,7 +31,7 @@ ___ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:21](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L21) +[wallet-ledger/src/ledger-wallet.ts:22](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L22) ___ @@ -41,7 +41,7 @@ ___ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L17) +[wallet-ledger/src/ledger-wallet.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L18) ___ @@ -51,4 +51,4 @@ ___ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L23) +[wallet-ledger/src/ledger-wallet.ts:24](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L24) diff --git a/packages/docs/sdk/docs/wallet-ledger/interfaces/types.ILedger.md b/packages/docs/sdk/docs/wallet-ledger/interfaces/types.ILedger.md new file mode 100644 index 000000000..18bb00255 --- /dev/null +++ b/packages/docs/sdk/docs/wallet-ledger/interfaces/types.ILedger.md @@ -0,0 +1,135 @@ +[@celo/wallet-ledger](../README.md) / [types](../modules/types.md) / ILedger + +# Interface: ILedger + +[types](../modules/types.md).ILedger + +## Table of contents + +### Methods + +- [getAddress](types.ILedger.md#getaddress) +- [getAppConfiguration](types.ILedger.md#getappconfiguration) +- [provideERC20TokenInformation](types.ILedger.md#provideerc20tokeninformation) +- [signEIP712HashedMessage](types.ILedger.md#signeip712hashedmessage) +- [signPersonalMessage](types.ILedger.md#signpersonalmessage) +- [signTransaction](types.ILedger.md#signtransaction) + +## Methods + +### getAddress + +▸ **getAddress**(`derivationPath`, `forceValidation?`): `Promise`\<\{ `address?`: \`0x$\{string}\` ; `derivationPath?`: `string` }\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `derivationPath` | `string` | +| `forceValidation?` | `boolean` | + +#### Returns + +`Promise`\<\{ `address?`: \`0x$\{string}\` ; `derivationPath?`: `string` }\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:5](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L5) + +___ + +### getAppConfiguration + +▸ **getAppConfiguration**(): `Promise`\<\{ `arbitraryDataEnabled`: `number` ; `version`: `string` }\> + +#### Returns + +`Promise`\<\{ `arbitraryDataEnabled`: `number` ; `version`: `string` }\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L16) + +___ + +### provideERC20TokenInformation + +▸ **provideERC20TokenInformation**(`TokenInfo`): `Promise`\<`unknown`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `TokenInfo` | `any` | + +#### Returns + +`Promise`\<`unknown`\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L17) + +___ + +### signEIP712HashedMessage + +▸ **signEIP712HashedMessage**(`derivationPath`, `domainSeparator`, `structHash`): `Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `derivationPath` | `string` | +| `domainSeparator` | `Buffer` | +| `structHash` | `Buffer` | + +#### Returns + +`Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L11) + +___ + +### signPersonalMessage + +▸ **signPersonalMessage**(`derivationPath`, `data`): `Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `derivationPath` | `string` | +| `data` | `string` | + +#### Returns + +`Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L10) + +___ + +### signTransaction + +▸ **signTransaction**(`derivationPath`, `data`): `Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `derivationPath` | `string` | +| `data` | `string` | + +#### Returns + +`Promise`\<[`LedgerSignature`](../modules/types.md#ledgersignature)\> + +#### Defined in + +[wallet-ledger/src/types.d.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L9) diff --git a/packages/docs/sdk/docs/wallet-ledger/modules/ledger_wallet.md b/packages/docs/sdk/docs/wallet-ledger/modules/ledger_wallet.md index 6511e76de..cd4e7fee0 100644 --- a/packages/docs/sdk/docs/wallet-ledger/modules/ledger_wallet.md +++ b/packages/docs/sdk/docs/wallet-ledger/modules/ledger_wallet.md @@ -28,7 +28,7 @@ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L11) +[wallet-ledger/src/ledger-wallet.ts:12](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L12) ## Functions @@ -51,4 +51,4 @@ #### Defined in -[wallet-ledger/src/ledger-wallet.ts:26](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L26) +[wallet-ledger/src/ledger-wallet.ts:27](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts#L27) diff --git a/packages/docs/sdk/docs/wallet-ledger/modules/types.md b/packages/docs/sdk/docs/wallet-ledger/modules/types.md new file mode 100644 index 000000000..4f3b61670 --- /dev/null +++ b/packages/docs/sdk/docs/wallet-ledger/modules/types.md @@ -0,0 +1,31 @@ +[@celo/wallet-ledger](../README.md) / types + +# Module: types + +## Table of contents + +### Interfaces + +- [ILedger](../interfaces/types.ILedger.md) + +### Type Aliases + +- [LedgerSignature](types.md#ledgersignature) + +## Type Aliases + +### LedgerSignature + +Ƭ **LedgerSignature**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `r` | `string` | +| `s` | `string` | +| `v` | `string` | + +#### Defined in + +[wallet-ledger/src/types.d.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-ledger/src/types.d.ts#L3) diff --git a/packages/docs/sdk/docs/wallet-local/classes/local_signer.LocalSigner.md b/packages/docs/sdk/docs/wallet-local/classes/local_signer.LocalSigner.md index 6a8cf8617..d1acf05f4 100644 --- a/packages/docs/sdk/docs/wallet-local/classes/local_signer.LocalSigner.md +++ b/packages/docs/sdk/docs/wallet-local/classes/local_signer.LocalSigner.md @@ -43,7 +43,7 @@ Signs the EVM transaction using the provided private key #### Defined in -[wallet-local/src/local-signer.ts:17](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L17) +[wallet-local/src/local-signer.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L15) ## Methods @@ -67,7 +67,7 @@ Signer.computeSharedSecret #### Defined in -[wallet-local/src/local-signer.ts:71](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L71) +[wallet-local/src/local-signer.ts:66](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L66) ___ @@ -91,7 +91,7 @@ Signer.decrypt #### Defined in -[wallet-local/src/local-signer.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L63) +[wallet-local/src/local-signer.ts:59](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L59) ___ @@ -109,7 +109,7 @@ Signer.getNativeKey #### Defined in -[wallet-local/src/local-signer.ts:21](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L21) +[wallet-local/src/local-signer.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L19) ___ @@ -133,7 +133,7 @@ Signer.signPersonalMessage #### Defined in -[wallet-local/src/local-signer.ts:34](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L34) +[wallet-local/src/local-signer.ts:30](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L30) ___ @@ -158,7 +158,7 @@ Signer.signTransaction #### Defined in -[wallet-local/src/local-signer.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L25) +[wallet-local/src/local-signer.ts:23](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L23) ___ @@ -182,4 +182,4 @@ Signer.signTypedData #### Defined in -[wallet-local/src/local-signer.ts:50](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L50) +[wallet-local/src/local-signer.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/wallets/wallet-local/src/local-signer.ts#L46) diff --git a/packages/sdk/base/src/account.ts b/packages/sdk/base/src/account.ts index bd13ab400..d3444eba8 100644 --- a/packages/sdk/base/src/account.ts +++ b/packages/sdk/base/src/account.ts @@ -23,8 +23,8 @@ export type RandomNumberGenerator = ( ) => void export interface Bip39 { - mnemonicToSeedSync: (mnemonic: string, password?: string) => Buffer - mnemonicToSeed: (mnemonic: string, password?: string) => Promise + mnemonicToSeedSync: (mnemonic: string, password?: string) => Uint8Array + mnemonicToSeed: (mnemonic: string, password?: string) => Promise generateMnemonic: ( strength?: number, rng?: RandomNumberGenerator, diff --git a/packages/sdk/cryptographic-utils/package.json b/packages/sdk/cryptographic-utils/package.json index 2044d6882..ba572f9d1 100644 --- a/packages/sdk/cryptographic-utils/package.json +++ b/packages/sdk/cryptographic-utils/package.json @@ -25,20 +25,15 @@ "@celo/base": "^6.0.1", "@celo/bls12377js": "0.1.1", "@celo/utils": "^6.0.1", - "@ethereumjs/util": "8.0.5", "@noble/ciphers": "0.4.1", "@noble/curves": "1.3.0", "@noble/hashes": "1.3.3", + "@scure/bip32": "^1.3.3", + "@scure/bip39": "^1.2.2", "@types/bn.js": "^5.1.0", "@types/node": "^18.7.16", - "@types/randombytes": "^2.0.0", "bigi": "^1.4.2", - "bip32": "^3.1.0", - "bip39": "https://github.com/bitcoinjs/bip39#a7ecbfe2e60d0214ce17163d610cad9f7b23140c", - "buffer-reverse": "^1.0.1", - "ethereum-cryptography": "1.2.0", - "randombytes": "^2.0.1", - "tiny-secp256k1": "2.2.1" + "buffer-reverse": "^1.0.1" }, "devDependencies": { "@celo/typescript": "0.0.1" diff --git a/packages/sdk/cryptographic-utils/src/account.test.ts b/packages/sdk/cryptographic-utils/src/account.test.ts index bf4aefb72..84b4a5b6f 100644 --- a/packages/sdk/cryptographic-utils/src/account.test.ts +++ b/packages/sdk/cryptographic-utils/src/account.test.ts @@ -1,9 +1,10 @@ import { MnemonicLanguages } from '@celo/base/lib/account' -import * as bip39 from 'bip39' +import * as bip39 from '@scure/bip39' import { generateKeys, generateMnemonic, getAllLanguages, + getWordList, invalidMnemonicWords, MnemonicStrength, normalizeMnemonic, @@ -32,7 +33,7 @@ describe('AccountUtils', () => { // This validates against all languages expect(validateMnemonic(mnemonic)).toBeTruthy() // This validates using a specific wordlist - expect(bip39.validateMnemonic(mnemonic, bip39.wordlists[languageName])).toBeTruthy() + expect(bip39.validateMnemonic(mnemonic, getWordList(language))).toBeTruthy() }) } }) @@ -69,7 +70,7 @@ describe('AccountUtils', () => { // This validates against all languages expect(validateMnemonic(mnemonic)).toBeTruthy() // This validates using a specific wordlist - expect(bip39.validateMnemonic(mnemonic, bip39.wordlists[languageName])).toBeTruthy() + expect(bip39.validateMnemonic(mnemonic, getWordList(language))).toBeTruthy() }) } }) diff --git a/packages/sdk/cryptographic-utils/src/account.ts b/packages/sdk/cryptographic-utils/src/account.ts index c596f0cd9..7f8b99dc4 100644 --- a/packages/sdk/cryptographic-utils/src/account.ts +++ b/packages/sdk/cryptographic-utils/src/account.ts @@ -8,17 +8,13 @@ import { import { normalizeAccents } from '@celo/base/lib/string' import { privateKeyToAddress } from '@celo/utils/lib/address' import { levenshteinDistance } from '@celo/utils/lib/levenshtein' -// TODO replace by @scure/bip32 -import BIP32Factory from 'bip32' -// TODO replace by @scure/bip32 -import * as bip39 from 'bip39' -// TODO replace by @noble/hashes/sha3 { keccak_256 } -import { keccak256 } from 'ethereum-cryptography/keccak' -import { utf8ToBytes } from 'ethereum-cryptography/utils' -import randomBytes from 'randombytes' - -// TODO replace by @noble/curves/secp256k1 -import * as ecc from 'tiny-secp256k1' +import { keccak_256 } from '@noble/hashes/sha3' +import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils' +import { HDKey } from '@scure/bip32' +import * as bip39 from '@scure/bip39' +import { randomBytes } from 'crypto' +import wordlists from './wordlists' + // Exports moved to @celo/base, forwarding them // here for backwards compatibility export { @@ -28,12 +24,11 @@ export { MnemonicStrength, RandomNumberGenerator, } from '@celo/base/lib/account' -const bip32 = BIP32Factory(ecc) function defaultGenerateMnemonic( strength?: number, rng?: RandomNumberGenerator, - wordlist?: string[] + wordlist: string[] = wordlists[MnemonicLanguages.english] ): Promise { return new Promise((resolve, reject) => { strength = strength || 128 @@ -43,30 +38,37 @@ function defaultGenerateMnemonic( if (error) { reject(error) } else { - resolve(bip39.entropyToMnemonic(randomBytesBuffer.toString('hex'), wordlist)) + resolve(bip39.entropyToMnemonic(randomBytesBuffer, wordlist)) } }) }) } +function _validateMnemonic( + mnemonic: string, + wordlist: string[] = wordlists[MnemonicLanguages.english] +) { + return bip39.validateMnemonic(mnemonic, wordlist) +} + const bip39Wrapper: Bip39 = { mnemonicToSeedSync: bip39.mnemonicToSeedSync, mnemonicToSeed: bip39.mnemonicToSeed, generateMnemonic: defaultGenerateMnemonic, - validateMnemonic: bip39.validateMnemonic, + validateMnemonic: _validateMnemonic, } export async function generateMnemonic( strength: MnemonicStrength = MnemonicStrength.s256_24words, language?: MnemonicLanguages, - bip39ToUse: Bip39 = bip39Wrapper + bip39ToUse = bip39Wrapper ): Promise { return bip39ToUse.generateMnemonic(strength, undefined, getWordList(language)) } export function validateMnemonic( mnemonic: string, - bip39ToUse: Bip39 = bip39Wrapper, + bip39ToUse = bip39Wrapper, language?: MnemonicLanguages ) { if (language !== undefined) { @@ -166,28 +168,8 @@ export function formatNonAccentedCharacters(mnemonic: string) { } // Unify the bip39.wordlists (otherwise depends on the instance of the bip39) -function getWordList(language?: MnemonicLanguages): string[] { - // Use exhaustive switch to ensure that every language is accounted for. - switch (language ?? MnemonicLanguages.english) { - case MnemonicLanguages.chinese_simplified: - return bip39.wordlists.chinese_simplified - case MnemonicLanguages.chinese_traditional: - return bip39.wordlists.chinese_traditional - case MnemonicLanguages.english: - return bip39.wordlists.english - case MnemonicLanguages.french: - return bip39.wordlists.french - case MnemonicLanguages.italian: - return bip39.wordlists.italian - case MnemonicLanguages.japanese: - return bip39.wordlists.japanese - case MnemonicLanguages.korean: - return bip39.wordlists.korean - case MnemonicLanguages.spanish: - return bip39.wordlists.spanish - case MnemonicLanguages.portuguese: - return bip39.wordlists.portuguese - } +export function getWordList(language: MnemonicLanguages = MnemonicLanguages.english): string[] { + return wordlists[language] } export function getAllLanguages(): MnemonicLanguages[] { @@ -410,7 +392,7 @@ export async function generateKeys( password?: string, changeIndex: number = 0, addressIndex: number = 0, - bip39ToUse: Bip39 = bip39Wrapper, + bip39ToUse = bip39Wrapper, derivationPath: string = CELO_DERIVATION_PATH_BASE ): Promise<{ privateKey: string; publicKey: string; address: string }> { const seed: Buffer = await generateSeed(mnemonic, password, bip39ToUse) @@ -425,7 +407,7 @@ export function generateDeterministicInviteCode( changeIndex: number = 0, derivationPath: string = CELO_DERIVATION_PATH_BASE ): { privateKey: string; publicKey: string } { - const seed = keccak256(utf8ToBytes(recipientPhoneHash + recipientPepper)) as Buffer + const seed = Buffer.from(keccak_256(utf8ToBytes(recipientPhoneHash + recipientPepper))) return generateKeysFromSeed(seed, changeIndex, addressIndex, derivationPath) } @@ -434,10 +416,10 @@ export function generateDeterministicInviteCode( export async function generateSeed( mnemonic: string, password?: string, - bip39ToUse: Bip39 = bip39Wrapper, + bip39ToUse = bip39Wrapper, keyByteLength: number = 64 ): Promise { - let seed: Buffer = await bip39ToUse.mnemonicToSeed(mnemonic, password) + let seed = Buffer.from(await bip39ToUse.mnemonicToSeed(mnemonic, password)) if (keyByteLength > 0 && seed.byteLength > keyByteLength) { const bufAux = Buffer.allocUnsafe(keyByteLength) seed.copy(bufAux, 0, 0, keyByteLength) @@ -452,18 +434,21 @@ export function generateKeysFromSeed( addressIndex: number = 0, derivationPath: string = CELO_DERIVATION_PATH_BASE ): { privateKey: string; publicKey: string; address: string } { - const node = bip32.fromSeed(seed) - const newNode = node.derivePath( + const node = HDKey.fromMasterSeed(seed) + const newNode = node.derive( `${derivationPath ? `${derivationPath}/` : ''}${changeIndex}/${addressIndex}` ) if (!newNode.privateKey) { // As we are generating the node from a seed, the node will always have a private key and this would never happened throw new Error('utils-accounts@generateKeys: invalid node to derivate') } + const privateKey = bytesToHex(newNode.privateKey) + const publicKey = bytesToHex(newNode.publicKey!) + return { - privateKey: newNode.privateKey.toString('hex'), - publicKey: newNode.publicKey.toString('hex'), - address: privateKeyToAddress(newNode.privateKey.toString('hex')), + privateKey, + publicKey, + address: privateKeyToAddress(privateKey), } } diff --git a/packages/sdk/cryptographic-utils/src/bls.test.ts b/packages/sdk/cryptographic-utils/src/bls.test.ts new file mode 100644 index 000000000..2758bf892 --- /dev/null +++ b/packages/sdk/cryptographic-utils/src/bls.test.ts @@ -0,0 +1,61 @@ +import { normalizeAddressWith0x } from '@celo/base' +import { privateKeyToAddress } from '@celo/utils/lib/address' +import { blsPrivateKeyToProcessedPrivateKey, getBlsPoP, getBlsPublicKey } from './bls' +const PRIVATE_KEY1 = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' +const ACCOUNT_ADDRESS1 = normalizeAddressWith0x(privateKeyToAddress(PRIVATE_KEY1)) as `0x${string}` + +describe('BLS regression tests', () => { + test('blsPrivateKeyToProcessedPrivateKey', () => { + expect(blsPrivateKeyToProcessedPrivateKey(PRIVATE_KEY1)).toMatchInlineSnapshot(` + { + "data": [ + 242, + 30, + 152, + 172, + 17, + 130, + 80, + 64, + 6, + 191, + 156, + 10, + 65, + 229, + 164, + 189, + 107, + 121, + 20, + 112, + 230, + 253, + 30, + 215, + 206, + 48, + 25, + 145, + 97, + 14, + 121, + 3, + ], + "type": "Buffer", + } + `) + }) + + test('getBlsPublicKey', () => { + expect(getBlsPublicKey(PRIVATE_KEY1)).toMatchInlineSnapshot( + `"0x71436cf1cd3aacc12cf48122094802172522e0ae788a3c53328c911c6b84920cf584a865cccb319c82dcebb00e37520031d5c4c68104f1ae9eebb34fa76060da75ae8039810227104a89d7e033e4af8813ba0556cc8ffc47ca0791c7fa4ec680"` + ) + }) + + test('getBlsPoP', () => { + expect(getBlsPoP(ACCOUNT_ADDRESS1, PRIVATE_KEY1)).toMatchInlineSnapshot( + `"0x049cb0478d23fe074f01f0d8e5a512e6fb4b1dfe1ed1e079aea01e88a693f59904fc7a1668fef32a4ea0ce4e4e71f800"` + ) + }) +}) diff --git a/packages/sdk/cryptographic-utils/src/bls.ts b/packages/sdk/cryptographic-utils/src/bls.ts index c4f22ca68..3451a67cc 100644 --- a/packages/sdk/cryptographic-utils/src/bls.ts +++ b/packages/sdk/cryptographic-utils/src/bls.ts @@ -1,11 +1,10 @@ import { BLS } from '@celo/bls12377js' // this is an implementation of a subset of BLS12-377 import { isValidAddress } from '@celo/utils/lib/address' -import { keccak256 } from 'ethereum-cryptography/keccak' -const BigInteger = require('bigi') -const reverse = require('buffer-reverse') +import { keccak_256 } from '@noble/hashes/sha3' +import { bytesToHex } from '@noble/hashes/utils' -const n = BigInteger.fromHex('12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001', 16) +const n = BigInt('0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001') const MODULUSMASK = 31 export const BLS_PUBLIC_KEY_SIZE = 96 @@ -22,19 +21,18 @@ export const blsPrivateKeyToProcessedPrivateKey = (privateKeyHex: string) => { iBuffer, originalPrivateKeyBytes, ]) - const privateKeyBLSBytes = keccak256(keyBytes) + const privateKeyBLSBytes = keccak_256(keyBytes) // eslint-disable-next-line no-bitwise privateKeyBLSBytes[0] &= MODULUSMASK - const privateKeyNum = BigInteger.fromBuffer(privateKeyBLSBytes) - if (privateKeyNum.compareTo(n) >= 0) { + const _privateKeyHex = `0x${bytesToHex(privateKeyBLSBytes)}` + const privateKeyNum = BigInt(_privateKeyHex) + if (privateKeyNum >= n) { continue } - const privateKeyBytes = reverse(privateKeyNum.toBuffer()) - - return privateKeyBytes + return Buffer.from(privateKeyBLSBytes.reverse()) } throw new Error("couldn't derive BLS key from ECDSA key") diff --git a/packages/sdk/cryptographic-utils/src/wordlists.ts b/packages/sdk/cryptographic-utils/src/wordlists.ts new file mode 100644 index 000000000..9f9a40392 --- /dev/null +++ b/packages/sdk/cryptographic-utils/src/wordlists.ts @@ -0,0 +1,25 @@ +import { MnemonicLanguages } from '@celo/base/lib/account' + +import { wordlist as english } from '@scure/bip39/wordlists/english' +import { wordlist as french } from '@scure/bip39/wordlists/french' +import { wordlist as italian } from '@scure/bip39/wordlists/italian' +import { wordlist as japanese } from '@scure/bip39/wordlists/japanese' +import { wordlist as korean } from '@scure/bip39/wordlists/korean' +import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese' +import { wordlist as chinese_simplified } from '@scure/bip39/wordlists/simplified-chinese' +import { wordlist as spanish } from '@scure/bip39/wordlists/spanish' +import { wordlist as chinese_traditional } from '@scure/bip39/wordlists/traditional-chinese' + +const wordlists: Record = { + [MnemonicLanguages.english]: english, + [MnemonicLanguages.french]: french, + [MnemonicLanguages.italian]: italian, + [MnemonicLanguages.japanese]: japanese, + [MnemonicLanguages.korean]: korean, + [MnemonicLanguages.portuguese]: portuguese, + [MnemonicLanguages.chinese_simplified]: chinese_simplified, + [MnemonicLanguages.spanish]: spanish, + [MnemonicLanguages.chinese_traditional]: chinese_traditional, +} as const + +export default wordlists diff --git a/packages/sdk/governance/package.json b/packages/sdk/governance/package.json index 74e7db528..41e47243e 100644 --- a/packages/sdk/governance/package.json +++ b/packages/sdk/governance/package.json @@ -32,7 +32,6 @@ "@types/inquirer": "^6.5.0", "bignumber.js": "^9.0.0", "debug": "^4.1.1", - "ethereum-cryptography": "1.2.0", "inquirer": "^7.0.5" }, "engines": { diff --git a/packages/sdk/governance/src/proposals.ts b/packages/sdk/governance/src/proposals.ts index f51040d86..77234b5fa 100644 --- a/packages/sdk/governance/src/proposals.ts +++ b/packages/sdk/governance/src/proposals.ts @@ -38,10 +38,10 @@ import { newBlockExplorer } from '@celo/explorer' import { fetchMetadata, tryGetProxyImplementation } from '@celo/explorer/lib/sourcify' import { isValidAddress } from '@celo/utils/lib/address' import { fromFixed } from '@celo/utils/lib/fixidity' +import { keccak_256 } from '@noble/hashes/sha3' +import { utf8ToBytes } from '@noble/hashes/utils' import { BigNumber } from 'bignumber.js' import debugFactory from 'debug' -import { keccak256 } from 'ethereum-cryptography/keccak' -import { utf8ToBytes } from 'ethereum-cryptography/utils' import * as inquirer from 'inquirer' const debug = debugFactory('governance:proposals') @@ -54,8 +54,8 @@ export const hotfixToEncodedParams = (kit: ContractKit, proposal: Proposal, salt hotfixToParams(proposal, salt) ) -export const hotfixToHash = (kit: ContractKit, proposal: Proposal, salt: Buffer) => - keccak256(utf8ToBytes(hotfixToEncodedParams(kit, proposal, salt))) as Buffer +export const hotfixToHash = (kit: ContractKit, proposal: Proposal, salt: Buffer): Buffer => + Buffer.from(keccak_256(utf8ToBytes(hotfixToEncodedParams(kit, proposal, salt)))) /** * JSON encoding of a proposal transaction. diff --git a/packages/sdk/utils/package.json b/packages/sdk/utils/package.json index 766682ad0..e3bb3ee00 100644 --- a/packages/sdk/utils/package.json +++ b/packages/sdk/utils/package.json @@ -23,6 +23,7 @@ ], "dependencies": { "@celo/base": "^6.0.1", + "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/util": "8.0.5", "@noble/ciphers": "0.4.1", "@noble/curves": "1.3.0", @@ -30,10 +31,8 @@ "@types/bn.js": "^5.1.0", "@types/node": "^18.7.16", "bignumber.js": "^9.0.0", - "ethereum-cryptography": "1.2.0", "fp-ts": "2.1.1", "io-ts": "2.0.1", - "rlp": "^2.2.4", "web3-eth-abi": "1.10.4", "web3-utils": "1.10.4" }, diff --git a/packages/sdk/utils/src/istanbul.ts b/packages/sdk/utils/src/istanbul.ts index 4ee6bcb08..5ab7f9be9 100644 --- a/packages/sdk/utils/src/istanbul.ts +++ b/packages/sdk/utils/src/istanbul.ts @@ -1,6 +1,7 @@ import { bufferToHex, toChecksumAddress } from '@ethereumjs/util' import BigNumber from 'bignumber.js' -import * as rlp from 'rlp' +// import * as rlp from 'rlp' +import * as rlp from '@ethereumjs/rlp' import { Address } from './address' // This file contains utilities that help with istanbul-specific block information. @@ -42,14 +43,19 @@ function sealFromBuffers(data: Buffer[]): Seal { // Parse RLP encoded block extra data into an IstanbulExtra object. export function parseBlockExtraData(data: string): IstanbulExtra { const buffer = Buffer.from(data.replace(/^0x/, ''), 'hex') - const decode: any = rlp.decode('0x' + buffer.slice(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex')) + const decode = rlp.decode('0x' + buffer.subarray(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex')) + return { - addedValidators: decode[0].map((addr: Buffer) => toChecksumAddress(bufferToHex(addr))), - addedValidatorsPublicKeys: decode[1].map((key: Buffer) => '0x' + key.toString('hex')), - removedValidators: bigNumberFromBuffer(decode[2]), - seal: '0x' + decode[3].toString('hex'), - aggregatedSeal: sealFromBuffers(decode[4]), - parentAggregatedSeal: sealFromBuffers(decode[5]), + addedValidators: (decode.at(0) as Uint8Array[]).map((addr) => + toChecksumAddress(bufferToHex(Buffer.from(addr))) + ), + addedValidatorsPublicKeys: (decode.at(1) as Uint8Array[]).map( + (key) => '0x' + Buffer.from(key).toString('hex') + ), + removedValidators: bigNumberFromBuffer(Buffer.from(decode.at(2) as Uint8Array)), + seal: '0x' + Buffer.from(decode.at(3) as Uint8Array).toString('hex'), + aggregatedSeal: sealFromBuffers((decode.at(4) as Uint8Array[]).map(Buffer.from)), + parentAggregatedSeal: sealFromBuffers((decode.at(5) as Uint8Array[]).map(Buffer.from)), } } diff --git a/packages/sdk/utils/src/sign-typed-data-utils.test.ts b/packages/sdk/utils/src/sign-typed-data-utils.test.ts index ad552fc1a..2a69be91c 100644 --- a/packages/sdk/utils/src/sign-typed-data-utils.test.ts +++ b/packages/sdk/utils/src/sign-typed-data-utils.test.ts @@ -1,7 +1,7 @@ import { NULL_ADDRESS } from '@celo/base/lib/address' +import { keccak_256 } from '@noble/hashes/sha3' +import { utf8ToBytes } from '@noble/hashes/utils' import { BigNumber } from 'bignumber.js' -import { keccak256 } from 'ethereum-cryptography/keccak' -import { utf8ToBytes } from 'ethereum-cryptography/utils' import { EIP712Object, EIP712ObjectValue, @@ -55,7 +55,7 @@ const TEST_TYPES: EIP712TestCase[] = [ dataEncoding: Buffer.concat([ Buffer.from('000000000000000000000000000000000000000000000000000000000000a1ce', 'hex'), Buffer.from('0000000000000000000000000000000000000000000000000000000000000b0b', 'hex'), - keccak256(utf8ToBytes('hello bob!')), + keccak_256(utf8ToBytes('hello bob!')), ]), }, { @@ -68,7 +68,7 @@ const TEST_TYPES: EIP712TestCase[] = [ dataEncoding: Buffer.concat([ Buffer.from('000000000000000000000000000000000000000000000000000000000000a1ce', 'hex'), Buffer.from('0000000000000000000000000000000000000000000000000000000000000b0b', 'hex'), - keccak256(Buffer.from('0xdeadbeef', 'utf8')), + keccak_256(utf8ToBytes('0xdeadbeef')), ]), }, ], @@ -108,29 +108,29 @@ const TEST_TYPES: EIP712TestCase[] = [ }, }, dataEncoding: Buffer.concat([ - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Person(address wallet,string name)')), + keccak_256(utf8ToBytes('Person(address wallet,string name)')), Buffer.from( '000000000000000000000000000000000000000000000000000000000000a1ce', 'hex' ), - keccak256(utf8ToBytes('Alice')), + keccak_256(utf8ToBytes('Alice')), ]) ), - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Person(address wallet,string name)')), + keccak_256(utf8ToBytes('Person(address wallet,string name)')), Buffer.from( '0000000000000000000000000000000000000000000000000000000000000b0b', 'hex' ), - keccak256(utf8ToBytes('Bob')), + keccak_256(utf8ToBytes('Bob')), ]) ), - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Asset(address token,uint256 amount)')), + keccak_256(utf8ToBytes('Asset(address token,uint256 amount)')), Buffer.from( '000000000000000000000000000000000000000000000000000000000000ce10', 'hex' @@ -202,13 +202,13 @@ const TEST_TYPES: EIP712TestCase[] = [ ], }, dataEncoding: Buffer.concat([ - keccak256( + keccak_256( Buffer.concat([ - keccak256( + keccak_256( Buffer.concat([ - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), + keccak_256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), Buffer.from( '0000000000000000000000000000000000000000000000000000000000000001', 'hex' @@ -219,9 +219,9 @@ const TEST_TYPES: EIP712TestCase[] = [ ), ]) ), - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), + keccak_256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), Buffer.from( '0000000000000000000000000000000000000000000000000000000000000000', 'hex' @@ -234,11 +234,11 @@ const TEST_TYPES: EIP712TestCase[] = [ ), ]) ), - keccak256( + keccak_256( Buffer.concat([ - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), + keccak_256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), Buffer.from( '0000000000000000000000000000000000000000000000000000000000000001', 'hex' @@ -249,9 +249,9 @@ const TEST_TYPES: EIP712TestCase[] = [ ), ]) ), - keccak256( + keccak_256( Buffer.concat([ - keccak256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), + keccak_256(utf8ToBytes('Tile(bool occupied,uint8 occupantId)')), Buffer.from( '0000000000000000000000000000000000000000000000000000000000000001', 'hex' @@ -446,7 +446,9 @@ describe('encodeType()', () => { describe('typeHash()', () => { for (const { primaryType, types, typeEncoding } of TEST_TYPES) { it(`should hash type ${primaryType} correctly`, () => { - expect(typeHash(primaryType, types)).toEqual(keccak256(utf8ToBytes(typeEncoding))) + expect(typeHash(primaryType, types)).toEqual( + Buffer.from(keccak_256(utf8ToBytes(typeEncoding))) + ) }) } }) @@ -468,7 +470,9 @@ describe('structHash()', () => { if (examples.length > 0) { it(`should hash data ${primaryType} correctly`, () => { for (const { data, dataEncoding } of examples) { - const expected = keccak256(Buffer.concat([typeHash(primaryType, types), dataEncoding])) + const expected = Buffer.from( + keccak_256(Buffer.concat([typeHash(primaryType, types), dataEncoding])) + ) expect(structHash(primaryType, data, types)).toEqual(expected) } }) diff --git a/packages/sdk/utils/src/sign-typed-data-utils.ts b/packages/sdk/utils/src/sign-typed-data-utils.ts index 5ac97de71..c49bd0b92 100644 --- a/packages/sdk/utils/src/sign-typed-data-utils.ts +++ b/packages/sdk/utils/src/sign-typed-data-utils.ts @@ -1,8 +1,7 @@ import { NULL_ADDRESS, trimLeading0x } from '@celo/base/lib/address' -import { toBuffer } from '@ethereumjs/util' +import { keccak_256 } from '@noble/hashes/sha3' +import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils' import { BigNumber } from 'bignumber.js' -import { keccak256 } from 'ethereum-cryptography/keccak' -import { hexToBytes, utf8ToBytes } from 'ethereum-cryptography/utils' import * as t from 'io-ts' import coder from 'web3-eth-abi' @@ -135,13 +134,15 @@ export const noString: EIP712Optional = { * @return A Buffer containing the hash of the typed data. */ export function generateTypedDataHash(typedData: EIP712TypedData): Buffer { - return keccak256( - Buffer.concat([ - Buffer.from('1901', 'hex'), - structHash('EIP712Domain', typedData.domain, typedData.types), - structHash(typedData.primaryType, typedData.message, typedData.types), - ]) - ) as Buffer + return Buffer.from( + keccak_256( + Buffer.concat([ + Buffer.from('1901', 'hex'), + structHash('EIP712Domain', typedData.domain, typedData.types), + structHash(typedData.primaryType, typedData.message, typedData.types), + ]) + ) + ) } /** @@ -192,7 +193,7 @@ export function encodeType(primaryType: string, types: EIP712Types): string { } export function typeHash(primaryType: string, types: EIP712Types): Buffer { - return keccak256(utf8ToBytes(encodeType(primaryType, types))) as Buffer + return Buffer.from(keccak_256(utf8ToBytes(encodeType(primaryType, types)))) } /** Encodes a single EIP-712 value to a 32-byte buffer */ @@ -208,12 +209,12 @@ function encodeValue(valueType: string, value: EIP712ObjectValue, types: EIP712T // Converting to Buffer before passing to `keccak` prevents an issue where the string is // interpretted as a hex-encoded string when is starts with 0x. // https://github.com/ethereumjs/ethereumjs-util/blob/7e3be1d97b4e11fbc4924836b8c444e644f643ac/index.js#L155-L183 - return keccak256(Buffer.from(value as string, 'utf8')) as Buffer + return Buffer.from(keccak_256(Buffer.from(value as string, 'utf8'))) } if (valueType === 'bytes') { // Allow the user to use either utf8 (plain string) or hex encoding for their bytes. // Note: keccak throws if the value cannot be converted into a Buffer, - return toBuffer(keccak256(hexToBytes(trimLeading0x(value as string)))) + return Buffer.from(keccak_256(hexToBytes(trimLeading0x(value as string)))) } // Encode structs as its hashStruct (e.g. keccak(typeHash || encodeData(struct)) ). @@ -226,11 +227,13 @@ function encodeValue(valueType: string, value: EIP712ObjectValue, types: EIP712T // Note: If a fixed length is provided in the type, it is not checked. const match = EIP712_ARRAY_REGEXP.exec(valueType) const memberType: string = match?.groups?.memberType! - return keccak256( - Buffer.concat( - (value as EIP712ObjectValue[]).map((member) => encodeValue(memberType, member, types)) + return Buffer.from( + keccak_256( + Buffer.concat( + (value as EIP712ObjectValue[]).map((member) => encodeValue(memberType, member, types)) + ) ) - ) as Buffer + ) } throw new Error(`Unrecognized or unsupported type in EIP-712 encoding: ${valueType}`) @@ -255,9 +258,9 @@ export function encodeData(primaryType: string, data: EIP712Object, types: EIP71 } export function structHash(primaryType: string, data: EIP712Object, types: EIP712Types): Buffer { - return keccak256( - Buffer.concat([typeHash(primaryType, types), encodeData(primaryType, data, types)]) - ) as Buffer + return Buffer.from( + keccak_256(Buffer.concat([typeHash(primaryType, types), encodeData(primaryType, data, types)])) + ) } /** diff --git a/packages/sdk/wallets/wallet-base/package.json b/packages/sdk/wallets/wallet-base/package.json index 6859b72a1..46b1e3dd5 100644 --- a/packages/sdk/wallets/wallet-base/package.json +++ b/packages/sdk/wallets/wallet-base/package.json @@ -28,13 +28,13 @@ "@celo/base": "^6.0.1", "@celo/connect": "^5.3.0", "@celo/utils": "^6.0.1", - "@ethereumjs/rlp": "^5.0.0", + "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/util": "8.0.5", + "@noble/curves": "^1.3.0", + "@noble/hashes": "^1.3.3", "@types/debug": "^4.1.5", "bignumber.js": "^9.0.0", "debug": "^4.1.1", - "eth-lib": "^0.2.8", - "ethereum-cryptography": "^2.1.2", "web3": "1.10.4", "web3-eth-accounts": "1.10.4" }, diff --git a/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts b/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts index 54d1149fe..7cdf73ed5 100644 --- a/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts +++ b/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts @@ -1,5 +1,6 @@ import { CeloTx } from '@celo/connect' import { normalizeAddressWith0x, privateKeyToAddress } from '@celo/utils/lib/address' +import { hexToBytes } from '@noble/hashes/utils' import { parseTransaction, serializeTransaction } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { celo } from 'viem/chains' @@ -7,6 +8,10 @@ import Web3 from 'web3' import { extractSignature, getSignerFromTxEIP2718TX, + handleBigInt, + handleData, + handleHexString, + handleNumber, isPriceToLow, recoverTransaction, rlpEncodedTx, @@ -298,7 +303,7 @@ describe('rlpEncodedTx', () => { function ckToViem(tx: CeloTx & { v?: number }) { return { ...tx, - gas: BigInt(tx.gas!), + gas: BigInt(tx.gas! as string), maxFeePerGas: BigInt(tx.maxFeePerGas?.toString()!), maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas?.toString()!), value: BigInt(tx.value?.toString()!), @@ -621,8 +626,17 @@ describe('extractSignature', () => { `) }) it('fails when length is wrong', () => { + expect(() => + extractSignature( + '0xf88282ad5a8063630a94588e4b68193001e4d10928660ab4165b813717c0880de0b6b3a764000083abcdefc094cd2a3d9f938e13cd947ec05abc7fe734df8dd82680a091b5504a59e529e7efa42dbb97fbc3311a91d035c873a94ab0789441fc989f84a02e8254d6b3101b63417e5d496833bc84f4832d4a8bf8a2b83e291d8f38c0f62d' + ) + ).toThrowErrorMatchingInlineSnapshot( + `"@extractSignature: provided transaction has 13 elements but ethereum-legacy txs with a signature have 9 [{"0":173,"1":90},{},{"0":99},{"0":99},{"0":10},{"0":88,"1":142,"2":75,"3":104,"4":25,"5":48,"6":1,"7":228,"8":209,"9":9,"10":40,"11":102,"12":10,"13":180,"14":22,"15":91,"16":129,"17":55,"18":23,"19":192},{"0":13,"1":224,"2":182,"3":179,"4":167,"5":100,"6":0,"7":0},{"0":171,"1":205,"2":239},[],{"0":205,"1":42,"2":61,"3":159,"4":147,"5":142,"6":19,"7":205,"8":148,"9":126,"10":192,"11":90,"12":188,"13":127,"14":231,"15":52,"16":223,"17":141,"18":216,"19":38},{},{"0":145,"1":181,"2":80,"3":74,"4":89,"5":229,"6":41,"7":231,"8":239,"9":164,"10":45,"11":187,"12":151,"13":251,"14":195,"15":49,"16":26,"17":145,"18":208,"19":53,"20":200,"21":115,"22":169,"23":74,"24":176,"25":120,"26":148,"27":65,"28":252,"29":152,"30":159,"31":132},{"0":46,"1":130,"2":84,"3":214,"4":179,"5":16,"6":27,"7":99,"8":65,"9":126,"10":93,"11":73,"12":104,"13":51,"14":188,"15":132,"16":244,"17":131,"18":45,"19":74,"20":139,"21":248,"22":162,"23":184,"24":62,"25":41,"26":29,"27":143,"28":56,"29":192,"30":246,"31":45}]"` + ) + }) + it('fails when length is empty', () => { expect(() => extractSignature('0x')).toThrowErrorMatchingInlineSnapshot( - `"@extractSignature: provided transaction has 0 elements but ethereum-legacy txs with a signature have 9 []"` + `"Invalid byte sequence"` ) }) }) @@ -670,3 +684,25 @@ describe('stringNumberOrBNToHex', () => { expect(stringNumberOrBNToHex(biggie)).toEqual('0x7b') }) }) + +describe('handleNumber', () => { + test('handles numbers', () => { + expect(handleNumber(hexToBytes('cafe0123'))).toEqual(3405644067) + expect(handleNumber(hexToBytes(''))).toEqual(0) + }) +}) + +describe('handleBigInt', () => { + expect(handleBigInt(hexToBytes('ffffffffffffff'))).toEqual(BigInt('72057594037927935')) + expect(handleBigInt(hexToBytes(''))).toEqual(BigInt(0)) +}) + +describe('handleHexString', () => { + expect(handleHexString(hexToBytes('cafe0123'))).toEqual('0xcafe0123') + expect(handleHexString(hexToBytes(''))).toEqual('0x') +}) + +describe('handleData', () => { + expect(handleData(hexToBytes('cafe0123'))).toEqual('0xcafe0123') + expect(handleData(hexToBytes(''))).toEqual('0x') +}) diff --git a/packages/sdk/wallets/wallet-base/src/signing-utils.ts b/packages/sdk/wallets/wallet-base/src/signing-utils.ts index 705a37d5d..03bfbb3d3 100644 --- a/packages/sdk/wallets/wallet-base/src/signing-utils.ts +++ b/packages/sdk/wallets/wallet-base/src/signing-utils.ts @@ -1,9 +1,13 @@ -import { ensureLeading0x, trimLeading0x } from '@celo/base/lib/address' +import { + StrongAddress, + ensureLeading0x, + normalizeAddressWith0x, + trimLeading0x, +} from '@celo/base/lib/address' import { CeloTx, CeloTxWithSig, EncodedTransaction, - Hex, RLPEncodedTx, TransactionTypes, isPresent, @@ -15,25 +19,17 @@ import { } from '@celo/connect/lib/utils/formatter' import { EIP712TypedData, generateTypedDataHash } from '@celo/utils/lib/sign-typed-data-utils' import { parseSignatureWithoutPrefix } from '@celo/utils/lib/signatureUtils' -// @ts-ignore-next-line +import { publicKeyToAddress } from '@celo/utils/src/address' +import * as RLP from '@ethereumjs/rlp' import * as ethUtil from '@ethereumjs/util' +import { secp256k1 } from '@noble/curves/secp256k1' +import { keccak_256 } from '@noble/hashes/sha3' +import { bytesToHex, hexToBytes } from '@noble/hashes/utils' import debugFactory from 'debug' -// @ts-ignore-next-line eth-lib types not found -import { account as Account, bytes as Bytes, hash as Hash, RLP } from 'eth-lib' -import { keccak256 } from 'ethereum-cryptography/keccak' -import { hexToBytes } from 'ethereum-cryptography/utils.js' import Web3 from 'web3' // TODO try to do this without web3 direct import Accounts from 'web3-eth-accounts' -const { - Address, - ecrecover, - fromRpcSig, - hashPersonalMessage, - pubToAddress, - toBuffer, - toChecksumAddress, -} = ethUtil +const { ecrecover, fromRpcSig, hashPersonalMessage, toBuffer } = ethUtil const debug = debugFactory('wallet-base:tx:sign') // Original code taken from @@ -47,6 +43,10 @@ export const thirtyTwo: number = 32 const Y_PARITY_EIP_2098 = 27 +function rlpEncodeHex(value: RLP.Input): StrongAddress { + return ensureLeading0x(Buffer.from(RLP.encode(value)).toString('hex')) +} + function isNullOrUndefined(value: any): boolean { return value === null || value === undefined } @@ -57,8 +57,10 @@ export function chainIdTransformationForSigning(chainId: number): number { return chainId * 2 + 35 } -export function getHashFromEncoded(rlpEncode: string): string { - return Hash.keccak256(rlpEncode) +export function getHashFromEncoded(rlpEncode: string): StrongAddress { + const rlpBytes = hexToBytes(trimLeading0x(rlpEncode)) + const hash = Buffer.from(keccak_256(rlpBytes)) + return `0x${hash.toString('hex')}` } function trimLeadingZero(hex: string) { @@ -88,40 +90,40 @@ function signatureFormatter( v = signature.v === Y_PARITY_EIP_2098 ? 0 : 1 } return { - v: stringNumberToHex(v), - r: makeEven(trimLeadingZero(ensureLeading0x(signature.r.toString('hex')))), - s: makeEven(trimLeadingZero(ensureLeading0x(signature.s.toString('hex')))), + v: trimLeading0x(stringNumberToHex(v)), + r: trimLeading0x(makeEven(trimLeadingZero(ensureLeading0x(signature.r.toString('hex'))))), + s: trimLeading0x(makeEven(trimLeadingZero(ensureLeading0x(signature.s.toString('hex'))))), } } export function stringNumberOrBNToHex( num?: number | string | ReturnType -): Hex { +): StrongAddress { if (typeof num === 'string' || typeof num === 'number' || num === undefined) { return stringNumberToHex(num) } else { - return makeEven(`0x` + num.toString(16)) as Hex + return makeEven(`0x` + num.toString(16)) as StrongAddress } } -function stringNumberToHex(num?: number | string): Hex { +function stringNumberToHex(num?: number | string): StrongAddress { const auxNumber = Number(num) if (num === '0x' || num === undefined || auxNumber === 0) { return '0x' } - return makeEven(Web3.utils.numberToHex(num)) as Hex + return makeEven(Web3.utils.numberToHex(num)) as StrongAddress } export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { assertSerializableTX(tx) const transaction = inputCeloTxFormatter(tx) - transaction.to = Bytes.fromNat(tx.to || '0x').toLowerCase() + transaction.to = ensureLeading0x((tx.to || '0x').toLowerCase()) transaction.nonce = Number(((tx.nonce as any) !== '0x' ? tx.nonce : 0) || 0) - transaction.data = Bytes.fromNat(tx.data || '0x').toLowerCase() + transaction.data = (tx.data || '0x').toLowerCase() transaction.value = stringNumberOrBNToHex(tx.value) transaction.gas = stringNumberOrBNToHex(tx.gas) transaction.chainId = tx.chainId || 1 // Celo Specific - transaction.feeCurrency = Bytes.fromNat(tx.feeCurrency || '0x').toLowerCase() - transaction.gatewayFeeRecipient = Bytes.fromNat(tx.gatewayFeeRecipient || '0x').toLowerCase() + transaction.feeCurrency = ensureLeading0x((tx.feeCurrency || '0x').toLowerCase()) + transaction.gatewayFeeRecipient = ensureLeading0x((tx.gatewayFeeRecipient || '0x').toLowerCase()) transaction.gatewayFee = stringNumberOrBNToHex(tx.gatewayFee) // Legacy @@ -130,11 +132,11 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { transaction.maxFeePerGas = stringNumberOrBNToHex(tx.maxFeePerGas) transaction.maxPriorityFeePerGas = stringNumberOrBNToHex(tx.maxPriorityFeePerGas) - let rlpEncode: Hex + let rlpEncode: StrongAddress if (isCIP64(tx)) { // https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0064.md // 0x7b || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, feeCurrency, signatureYParity, signatureR, signatureS]). - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -154,7 +156,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { // There shall be a typed transaction with the code 0x7c that has the following format: // 0x7c || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, feecurrency, gatewayFeeRecipient, gatewayfee, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]). // This will be in addition to the type 0x02 transaction as specified in EIP-1559. - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -173,7 +175,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { } else if (isEIP1559(tx)) { // https://eips.ethereum.org/EIPS/eip-1559 // 0x02 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]). - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -196,7 +198,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { } else if (isCeloLegacy(tx)) { // This order should match the order in Geth. // https://github.com/celo-org/celo-blockchain/blob/027dba2e4584936cc5a8e8993e4e27d28d5247b8/core/types/transaction.go#L65 - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.nonce), transaction.gasPrice, transaction.gas, @@ -214,7 +216,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { } else { // https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0035.md // rlp([nonce, gasprice, gaslimit, recipient, amount, data, v, r, s]) - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.nonce), transaction.gasPrice, transaction.gas, @@ -243,12 +245,12 @@ enum TxTypeToPrefix { function concatTypePrefixHex( rawTransaction: string, txType: EncodedTransaction['tx']['type'] -): Hex { +): StrongAddress { const prefix = TxTypeToPrefix[txType] if (prefix) { return concatHex([prefix, rawTransaction]) } - return rawTransaction as Hex + return rawTransaction as StrongAddress } function assertSerializableTX(tx: CeloTx) { @@ -328,7 +330,7 @@ function isCeloLegacy(tx: CeloTx): boolean { ) } -function concatHex(values: string[]): Hex { +function concatHex(values: string[]): StrongAddress { return `0x${values.reduce((acc, x) => acc + x.replace('0x', ''), '')}` } @@ -350,12 +352,10 @@ export async function encodeTransaction( signature: { v: number; r: Buffer; s: Buffer } ): Promise { const sanitizedSignature = signatureFormatter(signature, rlpEncoded.type) - const v = sanitizedSignature.v - const r = sanitizedSignature.r - const s = sanitizedSignature.s - const decodedTX = prefixAwareRLPDecode(rlpEncoded.rlpEncode, rlpEncoded.type) - - let decodedFields: string[] + const { v, r, s } = sanitizedSignature + const decodedTX = prefixAwareRLPDecode(rlpEncoded.rlpEncode, rlpEncoded.type) as Uint8Array[] + // for legacy tx we need to slice but for new ones we do not want to do that + let decodedFields: typeof decodedTX // for legacy tx we need to slice but for new ones we do not want to do that if (rlpEncoded.type == 'celo-legacy') { @@ -365,11 +365,10 @@ export async function encodeTransaction( } else { decodedFields = decodedTX } - - const rawTx = decodedFields.concat([v, r, s]) + const rawTx = decodedFields.concat([hexToBytes(v), hexToBytes(r), hexToBytes(s)]) // After signing, the transaction is encoded again and type prefix added - const rawTransaction = concatTypePrefixHex(RLP.encode(rawTx), rlpEncoded.type) + const rawTransaction = concatTypePrefixHex(rlpEncodeHex(rawTx), rlpEncoded.type) const hash = getHashFromEncoded(rawTransaction) const baseTX = { @@ -378,9 +377,9 @@ export async function encodeTransaction( to: rlpEncoded.transaction.to!.toString(), value: rlpEncoded.transaction.value!.toString(), input: rlpEncoded.transaction.data!, - v, - r, - s, + v: ensureLeading0x(v), + r: ensureLeading0x(r), + s: ensureLeading0x(s), hash, } let tx: Partial = baseTX @@ -405,7 +404,7 @@ export async function encodeTransaction( if (rlpEncoded.type === 'celo-legacy' || rlpEncoded.type === 'ethereum-legacy') { tx = { ...tx, - // @ts-expect-error -- just a matter of how this tx is built + // @ts-expect-error -- just a matter of how this tx is built gasPrice: rlpEncoded.transaction.gasPrice!.toString(), } } @@ -418,7 +417,7 @@ export async function encodeTransaction( return result } // new types have prefix but legacy does not -function prefixAwareRLPDecode(rlpEncode: string, type: TransactionTypes): string[] { +function prefixAwareRLPDecode(rlpEncode: string, type: TransactionTypes) { if (type === 'celo-legacy' || type === 'ethereum-legacy') { return RLP.decode(rlpEncode) } @@ -453,10 +452,10 @@ export function extractSignature(rawTx: string) { )} ${JSON.stringify(rawValues)}` ) } - return extractSignatureFromDecoded(rawValues) + return extractSignatureFromDecoded(rawValues as Uint8Array[]) } -function extractSignatureFromDecoded(rawValues: string[]) { +function extractSignatureFromDecoded(rawValues: Uint8Array[]) { // signature is always (for the tx we support so far) the last three elements of the array in order v, r, s, const v = rawValues.at(-3) let r = rawValues.at(-2) @@ -464,13 +463,10 @@ function extractSignatureFromDecoded(rawValues: string[]) { // https://github.com/wagmi-dev/viem/blob/993321689b3e2220976504e7e170fe47731297ce/src/utils/transaction/parseTransaction.ts#L281 // Account.recover cannot handle canonicalized signatures // A canonicalized signature may have the first byte removed if its value is 0 - r = ensureLeading0x(trimLeading0x(r as string).padStart(64, '0')) - s = ensureLeading0x(trimLeading0x(s as string).padStart(64, '0')) - return { - v, - r, - s, + v: handleHexString(v!), + r: ensureLeading0x(bytesToHex(r!).padStart(64, '0')), + s: ensureLeading0x(bytesToHex(s!).padStart(64, '0')), } } @@ -483,29 +479,29 @@ export function recoverTransaction(rawTx: string): [CeloTx, string] { switch (determineTXType(rawTx)) { case 'cip64': - return recoverTransactionCIP64(rawTx as Hex) + return recoverTransactionCIP64(rawTx as StrongAddress) case 'cip42': - return recoverTransactionCIP42(rawTx as Hex) + return recoverTransactionCIP42(rawTx as StrongAddress) case 'eip1559': - return recoverTransactionEIP1559(rawTx as Hex) + return recoverTransactionEIP1559(rawTx as StrongAddress) case 'celo-legacy': - return recoverCeloLegacy(rawTx as Hex) + return recoverCeloLegacy(rawTx as StrongAddress) default: - return recoverEthereumLegacy(rawTx as Hex) + return recoverEthereumLegacy(rawTx as StrongAddress) } } // inspired by @ethereumjs/tx -function getPublicKeyofSignerFromTx(transactionArray: string[], type: TransactionTypes) { +function getPublicKeyofSignerFromTx(transactionArray: Uint8Array[], type: TransactionTypes) { // this needs to be 10 for cip64, 12 for cip42 and eip1559 const base = transactionArray.slice(0, correctLengthOf(type, false)) - const message = concatHex([TxTypeToPrefix[type], RLP.encode(base).slice(2)]) - const msgHash = keccak256(hexToBytes(message)) + const message = concatHex([TxTypeToPrefix[type], rlpEncodeHex(base).slice(2)]) + const msgHash = keccak_256(hexToBytes(trimLeading0x(message))) const { v, r, s } = extractSignatureFromDecoded(transactionArray) try { return ecrecover( - toBuffer(msgHash), + Buffer.from(msgHash), v === '0x' || v === undefined ? BigInt(0) : BigInt(1), toBuffer(r), toBuffer(s) @@ -516,12 +512,13 @@ function getPublicKeyofSignerFromTx(transactionArray: string[], type: Transactio } export function getSignerFromTxEIP2718TX(serializedTransaction: string): string { - const transactionArray: any[] = RLP.decode(`0x${serializedTransaction.slice(4)}`) + const transactionArray = RLP.decode(`0x${serializedTransaction.slice(4)}`) const signer = getPublicKeyofSignerFromTx( - transactionArray, + transactionArray as Uint8Array[], determineTXType(serializedTransaction) ) - return toChecksumAddress(Address.fromPublicKey(signer).toString()) + + return publicKeyToAddress(signer.toString('hex')) } function determineTXType(serializedTransaction: string): TransactionTypes { @@ -553,8 +550,8 @@ function vrsForRecovery(vRaw: string, r: string, s: string) { } as const } -function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'cip42') +function recoverTransactionCIP42(serializedTransaction: StrongAddress): [CeloTxWithSig, string] { + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'cip42') debug('signing-utils@recoverTransactionCIP42: values are %s', transactionArray) if (transactionArray.length !== 15 && transactionArray.length !== 12) { throw new Error( @@ -577,24 +574,23 @@ function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, st vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTX: CeloTxWithSig = { type: 'cip42', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - feeCurrency, - gatewayFeeRecipient, - gatewayFee, - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + gas: handleNumber(gas), + feeCurrency: handleHexString(feeCurrency), + gatewayFeeRecipient: handleHexString(gatewayFeeRecipient), + gatewayFee: handleHexString(gatewayFee), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const signer = @@ -602,8 +598,8 @@ function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, st return [celoTX, signer] } -function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'cip64') +function recoverTransactionCIP64(serializedTransaction: StrongAddress): [CeloTxWithSig, string] { + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'cip64') debug('signing-utils@recoverTransactionCIP64: values are %s', transactionArray) if (transactionArray.length !== 13 && transactionArray.length !== 10) { throw new Error( @@ -624,22 +620,21 @@ function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, st vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTX: CeloTxWithSig = { type: 'cip64', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - feeCurrency, - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + gas: handleNumber(gas), + feeCurrency: handleHexString(feeCurrency), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const signer = @@ -647,8 +642,8 @@ function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, st return [celoTX, signer] } -function recoverTransactionEIP1559(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'eip1559') +function recoverTransactionEIP1559(serializedTransaction: StrongAddress): [CeloTxWithSig, string] { + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'eip1559') debug('signing-utils@recoverTransactionEIP1559: values are %s', transactionArray) const [ @@ -664,21 +659,20 @@ function recoverTransactionEIP1559(serializedTransaction: Hex): [CeloTxWithSig, vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTx: CeloTxWithSig = { type: 'eip1559', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + gas: handleNumber(gas), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const web3Account = new Accounts() const signer = web3Account.recoverTransaction(serializedTransaction) @@ -686,57 +680,85 @@ function recoverTransactionEIP1559(serializedTransaction: Hex): [CeloTxWithSig, return [celoTx, signer] } -function recoverCeloLegacy(serializedTransaction: Hex): [CeloTx, string] { - const rawValues = RLP.decode(serializedTransaction) +function recoverCeloLegacy(serializedTransaction: StrongAddress): [CeloTx, string] { + const rawValues = RLP.decode(serializedTransaction) as Uint8Array[] debug('signing-utils@recoverTransaction: values are %s', rawValues) - const recovery = Bytes.toNumber(rawValues[9]) - // eslint-disable-next-line no-bitwise - const chainId = Bytes.fromNumber((recovery - 35) >> 1) + const recovery = handleNumber(rawValues[9]) + // eslint-disable-next-line no-bitwise + const chainId = (recovery - 35) >> 1 const celoTx: CeloTx = { type: 'celo-legacy', - nonce: rawValues[0].toLowerCase() === '0x' ? 0 : parseInt(rawValues[0], 16), - gasPrice: rawValues[1].toLowerCase() === '0x' ? 0 : parseInt(rawValues[1], 16), - gas: rawValues[2].toLowerCase() === '0x' ? 0 : parseInt(rawValues[2], 16), - feeCurrency: rawValues[3], - gatewayFeeRecipient: rawValues[4], - gatewayFee: rawValues[5], - to: rawValues[6], - value: rawValues[7], - data: rawValues[8], - chainId, - } - const { r, v, s } = extractSignatureFromDecoded(rawValues) - const signature = Account.encodeSignature([v, r, s]) - const extraData = recovery < 35 ? [] : [chainId, '0x', '0x'] + nonce: handleNumber(rawValues[0]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gasPrice: handleNumber(rawValues[1]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gas: handleNumber(rawValues[2]), + feeCurrency: handleHexString(rawValues[3]), + gatewayFeeRecipient: handleHexString(rawValues[4]), + gatewayFee: handleHexString(rawValues[5]), + to: handleHexString(rawValues[6]), + value: handleHexString(rawValues[7]), + data: handleData(rawValues[8]), + // NOTE: I stringified to make it match the snapshot but it doesn't + // match the signature of TransactionConfig which expects a number + // @ts-expect-error + chainId: ensureLeading0x(chainId.toString(16)), + } + const { r, v: _v, s } = extractSignatureFromDecoded(rawValues) + let v = parseInt(_v || '0x0', 16) + const signature = new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit( + v - chainIdTransformationForSigning(chainId) + ) + const safeChainId = trimLeading0x( + makeEven(trimLeadingZero(ensureLeading0x(chainId.toString(16)))) + ) + const extraData = recovery < 35 ? [] : [hexToBytes(safeChainId), hexToBytes(''), hexToBytes('')] const signingData = rawValues.slice(0, 9).concat(extraData) - const signingDataHex = RLP.encode(signingData) - const signer = Account.recover(getHashFromEncoded(signingDataHex), signature) - return [celoTx, signer] + const signingDataHex = rlpEncodeHex(signingData) + const signingDataHash = getHashFromEncoded(signingDataHex) + const publicKey = signature.recoverPublicKey(trimLeading0x(signingDataHash)).toHex(false) + return [celoTx, publicKeyToAddress(publicKey)] } -function recoverEthereumLegacy(serializedTransaction: Hex): [CeloTx, string] { - const rawValues = RLP.decode(serializedTransaction) +function recoverEthereumLegacy(serializedTransaction: StrongAddress): [CeloTx, string] { + const rawValues = RLP.decode(serializedTransaction) as Uint8Array[] debug('signing-utils@recoverTransaction: values are %s', rawValues) - const recovery = Bytes.toNumber(rawValues[6]) - // eslint-disable-next-line no-bitwise - const chainId = Bytes.fromNumber((recovery - 35) >> 1) + const recovery = handleNumber(rawValues[6]) + // eslint-disable-next-line no-bitwise + const chainId = (recovery - 35) >> 1 const celoTx: CeloTx = { type: 'ethereum-legacy', - nonce: rawValues[0].toLowerCase() === '0x' ? 0 : parseInt(rawValues[0], 16), - gasPrice: rawValues[1].toLowerCase() === '0x' ? 0 : parseInt(rawValues[1], 16), - gas: rawValues[2].toLowerCase() === '0x' ? 0 : parseInt(rawValues[2], 16), - to: rawValues[3], - value: rawValues[4], - data: rawValues[5], - chainId, - } - const { r, v, s } = extractSignatureFromDecoded(rawValues) - const signature = Account.encodeSignature([v, r, s]) - const extraData = recovery < 35 ? [] : [chainId, '0x', '0x'] + nonce: handleNumber(rawValues[0]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gasPrice: handleNumber(rawValues[1]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gas: handleNumber(rawValues[2]), + to: handleHexString(rawValues[3]), + value: handleHexString(rawValues[4]), + data: handleData(rawValues[5]), + // NOTE: I stringified to make it match the snapshot but it doesn't + // match the signature of TransactionConfig which expects a number + // @ts-expect-error + chainId: ensureLeading0x(chainId.toString(16)), + } + const { r, v: _v, s } = extractSignatureFromDecoded(rawValues) + let v = parseInt(_v || '0x0', 16) + const signature = new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit( + v - chainIdTransformationForSigning(chainId) + ) + const safeChainId = trimLeading0x( + makeEven(trimLeadingZero(ensureLeading0x(chainId.toString(16)))) + ) + const extraData = recovery < 35 ? [] : [hexToBytes(safeChainId), hexToBytes(''), hexToBytes('')] const signingData = rawValues.slice(0, 6).concat(extraData) - const signingDataHex = RLP.encode(signingData) - const signer = Account.recover(getHashFromEncoded(signingDataHex), signature) - return [celoTx, signer] + const signingDataHex = rlpEncodeHex(signingData) + const signingDataHash = getHashFromEncoded(signingDataHex) + const publicKey = signature.recoverPublicKey(trimLeading0x(signingDataHash)).toHex(false) + return [celoTx, publicKeyToAddress(publicKey)] } export function recoverMessageSigner(signingDataHex: string, signedData: string): string { @@ -745,8 +767,8 @@ export function recoverMessageSigner(signingDataHex: string, signedData: string) const signature = fromRpcSig(signedData) const publicKey = ecrecover(msgHashBuff, signature.v, signature.r, signature.s) - const address = pubToAddress(publicKey, true) - return ensureLeading0x(address.toString('hex')) + const address = publicKeyToAddress(publicKey.toString('hex')) + return ensureLeading0x(address) } export function verifyEIP712TypedDataSigner( @@ -771,12 +793,49 @@ export function verifySignatureWithoutPrefix( } } -export function decodeSig(sig: any) { - const [v, r, s] = Account.decodeSignature(sig) +export function decodeSig(sig: StrongAddress | ReturnType, addToV = 0) { + const { recovery, r, s } = typeof sig === 'string' ? secp256k1.Signature.fromCompact(sig) : sig return { - v: parseInt(v, 16), - r: toBuffer(r) as Buffer, - s: toBuffer(s) as Buffer, + v: recovery! + addToV, + r: Buffer.from(r.toString(16).padStart(64, '0'), 'hex'), + s: Buffer.from(s.toString(16).padStart(64, '0'), 'hex'), + } +} + +export function signTransaction(hash: StrongAddress, privateKey: StrongAddress, addToV = 0) { + const signature = secp256k1.sign( + trimLeading0x(hash), + hexToBytes(trimLeading0x(privateKey)), + { lowS: true } // canonical:true + ) + return decodeSig(signature, addToV) +} + +export function handleNumber(n: Uint8Array): number { + const hex = `0x${bytesToHex(n)}` + if (hex === '0x') return 0 + return parseInt(hex, 16) +} + +export function handleBigInt(n: Uint8Array): bigint { + const hex = `0x${bytesToHex(n)}` + if (hex === '0x') return BigInt(0) + return BigInt(hex) +} + +export function handleHexString(adr: Uint8Array): StrongAddress { + if (!adr.length) { + return '0x' + } + const hex = `0x${bytesToHex(adr)}` + return normalizeAddressWith0x(hex) +} + +export function handleData(data: Uint8Array): string { + if (!data.length) { + return '0x' } + const hex = `0x${bytesToHex(data)}` + return hex } diff --git a/packages/sdk/wallets/wallet-hsm-aws/package.json b/packages/sdk/wallets/wallet-hsm-aws/package.json index a49a02b04..d91e93c9b 100644 --- a/packages/sdk/wallets/wallet-hsm-aws/package.json +++ b/packages/sdk/wallets/wallet-hsm-aws/package.json @@ -32,8 +32,7 @@ "@types/secp256k1": "^4.0.0", "aws-sdk": "^2.705.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm-azure/package.json b/packages/sdk/wallets/wallet-hsm-azure/package.json index 4b68ec570..a07a1e2a8 100644 --- a/packages/sdk/wallets/wallet-hsm-azure/package.json +++ b/packages/sdk/wallets/wallet-hsm-azure/package.json @@ -34,8 +34,7 @@ "@ethereumjs/util": "8.0.5", "@types/secp256k1": "^4.0.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm-gcp/package.json b/packages/sdk/wallets/wallet-hsm-gcp/package.json index d5d0d343d..808dfc3fe 100644 --- a/packages/sdk/wallets/wallet-hsm-gcp/package.json +++ b/packages/sdk/wallets/wallet-hsm-gcp/package.json @@ -31,8 +31,7 @@ "@types/debug": "^4.1.5", "@types/secp256k1": "^4.0.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm/package.json b/packages/sdk/wallets/wallet-hsm/package.json index 29e9f8bfd..be7447bcf 100644 --- a/packages/sdk/wallets/wallet-hsm/package.json +++ b/packages/sdk/wallets/wallet-hsm/package.json @@ -31,8 +31,7 @@ "@types/debug": "^4.1.5", "@types/secp256k1": "^4.0.0", "asn1js": "^2.0.26", - "bignumber.js": "^9.0.0", - "eth-lib": "^0.2.8" + "bignumber.js": "^9.0.0" }, "devDependencies": { "dotenv": "^8.2.0" diff --git a/packages/sdk/wallets/wallet-ledger/package.json b/packages/sdk/wallets/wallet-ledger/package.json index 284f76f89..e94d38ae3 100644 --- a/packages/sdk/wallets/wallet-ledger/package.json +++ b/packages/sdk/wallets/wallet-ledger/package.json @@ -18,6 +18,7 @@ "clean": "yarn run --top-level tsc -b . --clean", "docs": "yarn run --top-level typedoc", "test": "yarn run --top-level jest --runInBand", + "test:physical_ledger": "USE_PHYSICAL_LEDGER=true yarn test", "lint": "yarn run --top-level eslint -c .eslintrc.js ", "prepublishOnly": "yarn build" }, @@ -31,12 +32,11 @@ "@ledgerhq/errors": "^5.50.0", "@ledgerhq/hw-app-eth": "~5.11.0", "@ledgerhq/hw-transport": "~5.11.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8", - "ethereum-cryptography": "1.2.0" + "debug": "^4.1.1" }, "devDependencies": { "@ledgerhq/hw-transport-node-hid": "^6.27.4", + "@noble/hashes": "^1.3.3", "web3": "1.10.4" }, "engines": { diff --git a/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts b/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts index 4ff801529..68e7ee532 100644 --- a/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts +++ b/packages/sdk/wallets/wallet-ledger/src/ledger-signer.ts @@ -7,6 +7,7 @@ import debugFactory from 'debug' import { transportErrorFriendlyMessage } from './ledger-utils' import { AddressValidation } from './ledger-wallet' import { compareLedgerAppVersions, tokenInfoByAddressAndChainId } from './tokens' +import { ILedger } from './types' const debug = debugFactory('kit:wallet:ledger') const CELO_APP_ACCEPTS_CONTRACT_DATA_FROM_VERSION = '1.0.2' @@ -15,14 +16,14 @@ const CELO_APP_ACCEPTS_CONTRACT_DATA_FROM_VERSION = '1.0.2' * Signs the EVM transaction with a Ledger device */ export class LedgerSigner implements Signer { - private ledger: any + private ledger: ILedger private derivationPath: string private validated: boolean = false private ledgerAddressValidation: AddressValidation private appConfiguration: { arbitraryDataEnabled: number; version: string } constructor( - ledger: any, + ledger: ILedger, derivationPath: string, ledgerAddressValidation: AddressValidation, appConfiguration: { arbitraryDataEnabled: number; version: string } = { @@ -57,9 +58,8 @@ export class LedgerSigner implements Signer { if (rv !== addToV && (rv & addToV) !== rv) { addToV += 1 // add signature v bit. } - signature.v = addToV.toString(10) return { - v: signature.v, + v: addToV, r: ethUtil.toBuffer(ensureLeading0x(signature.r)) as Buffer, s: ethUtil.toBuffer(ensureLeading0x(signature.s)) as Buffer, } @@ -86,9 +86,8 @@ export class LedgerSigner implements Signer { await this.getValidatedDerivationPath(), trimLeading0x(data) ) - return { - v: signature.v, + v: parseInt(signature.v, 10), r: ethUtil.toBuffer(ensureLeading0x(signature.r)) as Buffer, s: ethUtil.toBuffer(ensureLeading0x(signature.s)) as Buffer, } @@ -109,6 +108,7 @@ export class LedgerSigner implements Signer { typedData.types ) + // NOTE: this function doesn't exist on ledger 5.11 so it fails, probably never worked const sig = await this.ledger!.signEIP712HashedMessage( await this.getValidatedDerivationPath(), domainSeparator, @@ -116,7 +116,7 @@ export class LedgerSigner implements Signer { ) return { - v: parseInt(sig.v, 10), + v: parseInt(sig.v, 16), r: ethUtil.toBuffer(ensureLeading0x(sig.r)) as Buffer, s: ethUtil.toBuffer(ensureLeading0x(sig.s)) as Buffer, } diff --git a/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts b/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts index 4764ee164..4b822c9e1 100644 --- a/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts +++ b/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts @@ -4,25 +4,25 @@ import { normalizeAddressWith0x, trimLeading0x, } from '@celo/base/lib/address' -import { CeloTx, EncodedTransaction } from '@celo/connect' +import { CeloTx, EncodedTransaction, Hex } from '@celo/connect' import { privateKeyToAddress } from '@celo/utils/lib/address' import { verifySignature } from '@celo/utils/lib/signatureUtils' import { chainIdTransformationForSigning, getHashFromEncoded, recoverTransaction, + signTransaction, verifyEIP712TypedDataSigner, } from '@celo/wallet-base' import * as ethUtil from '@ethereumjs/util' import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' -// @ts-ignore-next-line eth-lib types not found -import { account as Account } from 'eth-lib' -import { keccak256 } from 'ethereum-cryptography/keccak' +import { keccak_256 } from '@noble/hashes/sha3' import Web3 from 'web3' import { AddressValidation, LedgerWallet } from './ledger-wallet' +import { ILedger } from './types' // Update this variable when testing using a physical device -const USE_PHYSICAL_LEDGER = false +const USE_PHYSICAL_LEDGER = process.env.USE_PHYSICAL_LEDGER === 'true' // Increase timeout to give developer time to respond on device const TEST_TIMEOUT_IN_MS = USE_PHYSICAL_LEDGER ? 30 * 1000 : 1 * 1000 @@ -39,7 +39,7 @@ const ACCOUNT_ADDRESS5 = normalizeAddressWith0x(privateKeyToAddress(PRIVATE_KEY5 const PRIVATE_KEY_NEVER = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890ffffff' const ACCOUNT_ADDRESS_NEVER = normalizeAddressWith0x(privateKeyToAddress(PRIVATE_KEY_NEVER)) -const ledgerAddresses: { [myKey: string]: { address: string; privateKey: string } } = { +const ledgerAddresses: { [myKey: string]: { address: Hex; privateKey: Hex } } = { "44'/52752'/0'/0/0": { address: ACCOUNT_ADDRESS1, privateKey: PRIVATE_KEY1, @@ -105,68 +105,76 @@ const TYPED_DATA = { } function mockLedger(wallet: LedgerWallet, mockForceValidation: () => void) { - jest.spyOn(wallet, 'generateNewLedger').mockImplementation((_transport: any) => { - return { - getAddress: async (derivationPath: string, forceValidation?: boolean) => { - if (forceValidation) { - mockForceValidation() - } - if (ledgerAddresses[derivationPath]) { - return { address: ledgerAddresses[derivationPath].address, derivationPath } - } - return {} - }, - signTransaction: async (derivationPath: string, data: string) => { - if (ledgerAddresses[derivationPath]) { - const hash = getHashFromEncoded(ensureLeading0x(data)) - const signature = Account.makeSigner(chainIdTransformationForSigning(CHAIN_ID))( - hash, - ledgerAddresses[derivationPath].privateKey + jest + .spyOn(wallet, 'generateNewLedger') + .mockImplementation((_transport: any): ILedger => { + return { + getAddress: async (derivationPath: string, forceValidation?: boolean) => { + if (forceValidation) { + mockForceValidation() + } + if (ledgerAddresses[derivationPath]) { + return { address: ledgerAddresses[derivationPath].address, derivationPath } + } + return {} + }, + signTransaction: async (derivationPath: string, data: string) => { + if (ledgerAddresses[derivationPath]) { + const { r, s, v } = signTransaction( + getHashFromEncoded(ensureLeading0x(data)), + ledgerAddresses[derivationPath].privateKey, + chainIdTransformationForSigning(CHAIN_ID) + ) + return { + v: v.toString(16), + r: r.toString('hex'), + s: s.toString('hex'), + } + } + throw new Error('Invalid Path') + }, + signPersonalMessage: async (derivationPath: string, data: string) => { + if (ledgerAddresses[derivationPath]) { + const dataBuff = ethUtil.toBuffer(ensureLeading0x(data)) + const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff) + + const trimmedKey = trimLeading0x(ledgerAddresses[derivationPath].privateKey) + const pkBuffer = Buffer.from(trimmedKey, 'hex') + const signature = ethUtil.ecsign(msgHashBuff, pkBuffer) + return { + v: signature.v.toString(10), + r: signature.r.toString('hex'), + s: signature.s.toString('hex'), + } + } + throw new Error('Invalid Path') + }, + signEIP712HashedMessage: async ( + derivationPath: string, + domainSeparator: Buffer, + structHash: Buffer + ) => { + const messageHash = Buffer.from( + keccak_256(Buffer.concat([Buffer.from('1901', 'hex'), domainSeparator, structHash])) ) - const [v, r, s] = Account.decodeSignature(signature) - return { v, r, s } - } - throw new Error('Invalid Path') - }, - signPersonalMessage: async (derivationPath: string, data: string) => { - if (ledgerAddresses[derivationPath]) { - const dataBuff = ethUtil.toBuffer(ensureLeading0x(data)) - const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff) const trimmedKey = trimLeading0x(ledgerAddresses[derivationPath].privateKey) const pkBuffer = Buffer.from(trimmedKey, 'hex') - const signature = ethUtil.ecsign(msgHashBuff, pkBuffer) + const signature = ethUtil.ecsign(messageHash, pkBuffer) return { - v: signature.v, + v: signature.v.toString(16), r: signature.r.toString('hex'), s: signature.s.toString('hex'), } - } - throw new Error('Invalid Path') - }, - signEIP712HashedMessage: async ( - derivationPath: string, - domainSeparator: Buffer, - structHash: Buffer - ) => { - const messageHash = keccak256( - Buffer.concat([Buffer.from('1901', 'hex'), domainSeparator, structHash]) - ) as Buffer - - const trimmedKey = trimLeading0x(ledgerAddresses[derivationPath].privateKey) - const pkBuffer = Buffer.from(trimmedKey, 'hex') - const signature = ethUtil.ecsign(messageHash, pkBuffer) - return { - v: signature.v, - r: signature.r.toString('hex'), - s: signature.s.toString('hex'), - } - }, - getAppConfiguration: async () => { - return { arbitraryDataEnabled: 1, version: '0.0.0' } - }, - } - }) + }, + getAppConfiguration: async () => { + return { arbitraryDataEnabled: 1, version: '0.0.0' } + }, + provideERC20TokenInformation: async (_token) => { + return {} + }, + } + }) } describe('LedgerWallet class', () => { diff --git a/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts b/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts index 0ac4d7aa5..15747cd34 100644 --- a/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts +++ b/packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts @@ -7,6 +7,7 @@ import Ledger from '@ledgerhq/hw-app-eth' import debugFactory from 'debug' import { LedgerSigner } from './ledger-signer' import { transportErrorFriendlyMessage } from './ledger-utils' +import { ILedger } from './types' export const CELO_BASE_DERIVATION_PATH = `${CELO_DERIVATION_PATH_BASE.slice(2)}/0` const ADDRESS_QTY = 5 @@ -42,7 +43,7 @@ export async function newLedgerWalletWithSetup( const debug = debugFactory('kit:wallet:ledger') export class LedgerWallet extends RemoteWallet implements ReadOnlyWallet { - private ledger: any + private ledger: ILedger | undefined /** * @param derivationPathIndexes number array of "address_index" for the base derivation path. @@ -82,7 +83,7 @@ export class LedgerWallet extends RemoteWallet implements ReadOnly protected async loadAccountSigners(): Promise> { if (!this.ledger) { - this.ledger = this.generateNewLedger(this.transport) + this.ledger = this.generateNewLedger(this.transport) as ILedger } debug('Fetching addresses from the ledger') let addressToSigner = new Map() @@ -112,9 +113,9 @@ export class LedgerWallet extends RemoteWallet implements ReadOnly const derivationPath = `${this.baseDerivationPath}/${value}` const addressInfo = await this.ledger!.getAddress(derivationPath, validationRequired) addressToSigner.set( - addressInfo.address, + addressInfo.address!, new LedgerSigner( - this.ledger, + this.ledger!, derivationPath, this.ledgerAddressValidation, appConfiguration diff --git a/packages/sdk/wallets/wallet-ledger/src/types.d.ts b/packages/sdk/wallets/wallet-ledger/src/types.d.ts new file mode 100644 index 000000000..991902965 --- /dev/null +++ b/packages/sdk/wallets/wallet-ledger/src/types.d.ts @@ -0,0 +1,18 @@ +import { Hex } from '@celo/connect' + +type LedgerSignature = { v: string; r: string; s: string } +export interface ILedger { + getAddress( + derivationPath: string, + forceValidation?: boolean + ): Promise<{ address?: Hex; derivationPath?: string }> + signTransaction(derivationPath: string, data: string): Promise + signPersonalMessage(derivationPath: string, data: string): Promise + signEIP712HashedMessage( + derivationPath: string, + domainSeparator: Buffer, + structHash: Buffer + ): Promise + getAppConfiguration(): Promise<{ arbitraryDataEnabled: number; version: string }> + provideERC20TokenInformation(TokenInfo): Promise +} diff --git a/packages/sdk/wallets/wallet-local/package.json b/packages/sdk/wallets/wallet-local/package.json index 5974963b7..cb870ff85 100644 --- a/packages/sdk/wallets/wallet-local/package.json +++ b/packages/sdk/wallets/wallet-local/package.json @@ -25,8 +25,7 @@ "@celo/connect": "^5.3.0", "@celo/utils": "^6.0.1", "@celo/wallet-base": "^5.2.0", - "@ethereumjs/util": "8.0.5", - "eth-lib": "^0.2.8" + "@ethereumjs/util": "8.0.5" }, "devDependencies": { "viem": "~1.5.4", diff --git a/packages/sdk/wallets/wallet-local/src/local-signer.ts b/packages/sdk/wallets/wallet-local/src/local-signer.ts index 1bb598659..5f2199f0a 100644 --- a/packages/sdk/wallets/wallet-local/src/local-signer.ts +++ b/packages/sdk/wallets/wallet-local/src/local-signer.ts @@ -1,21 +1,19 @@ -import { RLPEncodedTx, Signer } from '@celo/connect' +import { Hex, RLPEncodedTx, Signer } from '@celo/connect' import { ensureLeading0x, trimLeading0x } from '@celo/utils/lib/address' import { computeSharedSecret as computeECDHSecret } from '@celo/utils/lib/ecdh' import { Decrypt } from '@celo/utils/lib/ecies' import { EIP712TypedData, generateTypedDataHash } from '@celo/utils/lib/sign-typed-data-utils' -import { decodeSig, getHashFromEncoded } from '@celo/wallet-base' +import { getHashFromEncoded, signTransaction } from '@celo/wallet-base' import * as ethUtil from '@ethereumjs/util' -// @ts-ignore eth-lib types not found -import { account as Account } from 'eth-lib' /** * Signs the EVM transaction using the provided private key */ export class LocalSigner implements Signer { - private privateKey: string + private privateKey: Hex constructor(privateKey: string) { - this.privateKey = privateKey + this.privateKey = ensureLeading0x(privateKey) } getNativeKey(): string { @@ -26,9 +24,7 @@ export class LocalSigner implements Signer { addToV: number, encodedTx: RLPEncodedTx ): Promise<{ v: number; r: Buffer; s: Buffer }> { - const hash = getHashFromEncoded(encodedTx.rlpEncode) - const signature = Account.makeSigner(addToV)(hash, this.privateKey) - return decodeSig(signature) + return signTransaction(getHashFromEncoded(encodedTx.rlpEncode), this.privateKey, addToV) } async signPersonalMessage(data: string): Promise<{ v: number; r: Buffer; s: Buffer }> { diff --git a/packages/sdk/wallets/wallet-remote/package.json b/packages/sdk/wallets/wallet-remote/package.json index a51130325..e203d2c7a 100644 --- a/packages/sdk/wallets/wallet-remote/package.json +++ b/packages/sdk/wallets/wallet-remote/package.json @@ -26,8 +26,7 @@ "@celo/utils": "^6.0.1", "@celo/wallet-base": "^5.2.0", "@ethereumjs/util": "8.0.5", - "@types/debug": "^4.1.5", - "eth-lib": "^0.2.8" + "@types/debug": "^4.1.5" }, "devDependencies": { "web3": "1.10.4" diff --git a/packages/sdk/wallets/wallet-rpc/src/rpc-signer.ts b/packages/sdk/wallets/wallet-rpc/src/rpc-signer.ts index 3fef77474..80178d981 100644 --- a/packages/sdk/wallets/wallet-rpc/src/rpc-signer.ts +++ b/packages/sdk/wallets/wallet-rpc/src/rpc-signer.ts @@ -1,5 +1,5 @@ import { ensureLeading0x, normalizeAddressWith0x, trimLeading0x } from '@celo/base/lib/address' -import { CeloTx, EncodedTransaction, RpcCaller, Signer } from '@celo/connect' +import { CeloTx, EncodedTransaction, Hex, RpcCaller, Signer } from '@celo/connect' import { EIP712TypedData } from '@celo/utils/lib/sign-typed-data-utils' import { decodeSig } from '@celo/wallet-base' import BigNumber from 'bignumber.js' @@ -109,7 +109,7 @@ export class RpcSigner implements Signer { typedData, ]) - return decodeSig(result) + return decodeSig(result as Hex) } async signPersonalMessage(data: string): Promise<{ v: number; r: Buffer; s: Buffer }> { @@ -117,7 +117,7 @@ export class RpcSigner implements Signer { this.account, data, ]) - return decodeSig(result) + return decodeSig(result as Hex) } getNativeKey = () => this.account diff --git a/yarn.lock b/yarn.lock index 9d6a702c2..29b1e6c81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1631,6 +1631,7 @@ __metadata: "@oclif/plugin-not-found": "npm:^3.0.9" "@oclif/plugin-plugins": "npm:^4.1.17" "@oclif/plugin-warn-if-update-available": "npm:^3.0.9" + "@scure/bip32": "npm:^1.3.3" "@types/command-exists": "npm:^1.2.3" "@types/debug": "npm:^4.1.4" "@types/fs-extra": "npm:^8.0.0" @@ -1640,7 +1641,6 @@ __metadata: "@types/node": "npm:^18.7.16" "@types/prompts": "npm:^1.1.1" bignumber.js: "npm:9.0.0" - bip32: "npm:3.1.0" chalk: "npm:^2.4.2" command-exists: "npm:^1.2.9" cross-fetch: "npm:3.1.5" @@ -1777,20 +1777,15 @@ __metadata: "@celo/bls12377js": "npm:0.1.1" "@celo/typescript": "npm:0.0.1" "@celo/utils": "npm:^6.0.1" - "@ethereumjs/util": "npm:8.0.5" "@noble/ciphers": "npm:0.4.1" "@noble/curves": "npm:1.3.0" "@noble/hashes": "npm:1.3.3" + "@scure/bip32": "npm:^1.3.3" + "@scure/bip39": "npm:^1.2.2" "@types/bn.js": "npm:^5.1.0" "@types/node": "npm:^18.7.16" - "@types/randombytes": "npm:^2.0.0" bigi: "npm:^1.4.2" - bip32: "npm:^3.1.0" - bip39: "https://github.com/bitcoinjs/bip39#a7ecbfe2e60d0214ce17163d610cad9f7b23140c" buffer-reverse: "npm:^1.0.1" - ethereum-cryptography: "npm:1.2.0" - randombytes: "npm:^2.0.1" - tiny-secp256k1: "npm:2.2.1" languageName: unknown linkType: soft @@ -1844,7 +1839,6 @@ __metadata: "@types/inquirer": "npm:^6.5.0" bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" - ethereum-cryptography: "npm:1.2.0" inquirer: "npm:^7.0.5" languageName: unknown linkType: soft @@ -1973,6 +1967,7 @@ __metadata: dependencies: "@celo/base": "npm:^6.0.1" "@celo/typescript": "npm:0.0.1" + "@ethereumjs/rlp": "npm:^5.0.2" "@ethereumjs/util": "npm:8.0.5" "@noble/ciphers": "npm:0.4.1" "@noble/curves": "npm:1.3.0" @@ -1980,10 +1975,8 @@ __metadata: "@types/bn.js": "npm:^5.1.0" "@types/node": "npm:^18.7.16" bignumber.js: "npm:^9.0.0" - ethereum-cryptography: "npm:1.2.0" fp-ts: "npm:2.1.1" io-ts: "npm:2.0.1" - rlp: "npm:^2.2.4" web3-eth-abi: "npm:1.10.4" web3-utils: "npm:1.10.4" languageName: unknown @@ -2016,13 +2009,13 @@ __metadata: "@celo/base": "npm:^6.0.1" "@celo/connect": "npm:^5.3.0" "@celo/utils": "npm:^6.0.1" - "@ethereumjs/rlp": "npm:^5.0.0" + "@ethereumjs/rlp": "npm:^5.0.2" "@ethereumjs/util": "npm:8.0.5" + "@noble/curves": "npm:^1.3.0" + "@noble/hashes": "npm:^1.3.3" "@types/debug": "npm:^4.1.5" bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" - eth-lib: "npm:^0.2.8" - ethereum-cryptography: "npm:^2.1.2" viem: "npm:~1.5.4" web3: "npm:1.10.4" web3-eth-accounts: "npm:1.10.4" @@ -2048,7 +2041,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.4" languageName: unknown linkType: soft @@ -2074,7 +2066,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.4" languageName: unknown linkType: soft @@ -2098,7 +2089,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.4" languageName: unknown linkType: soft @@ -2118,7 +2108,6 @@ __metadata: asn1js: "npm:^2.0.26" bignumber.js: "npm:^9.0.0" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" languageName: unknown linkType: soft @@ -2136,9 +2125,8 @@ __metadata: "@ledgerhq/hw-app-eth": "npm:~5.11.0" "@ledgerhq/hw-transport": "npm:~5.11.0" "@ledgerhq/hw-transport-node-hid": "npm:^6.27.4" + "@noble/hashes": "npm:^1.3.3" debug: "npm:^4.1.1" - eth-lib: "npm:^0.2.8" - ethereum-cryptography: "npm:1.2.0" web3: "npm:1.10.4" languageName: unknown linkType: soft @@ -2164,7 +2152,6 @@ __metadata: "@celo/utils": "npm:^6.0.1" "@celo/wallet-base": "npm:^5.2.0" "@ethereumjs/util": "npm:8.0.5" - eth-lib: "npm:^0.2.8" viem: "npm:~1.5.4" web3: "npm:1.10.4" languageName: unknown @@ -2179,7 +2166,6 @@ __metadata: "@celo/wallet-base": "npm:^5.2.0" "@ethereumjs/util": "npm:8.0.5" "@types/debug": "npm:^4.1.5" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.4" languageName: unknown linkType: soft @@ -2641,6 +2627,15 @@ __metadata: languageName: node linkType: hard +"@ethereumjs/rlp@npm:^5.0.2": + version: 5.0.2 + resolution: "@ethereumjs/rlp@npm:5.0.2" + bin: + rlp: bin/rlp.cjs + checksum: 2af80d98faf7f64dfb6d739c2df7da7350ff5ad52426c3219897e843ee441215db0ffa346873200a6be6d11142edb9536e66acd62436b5005fa935baaf7eb6bd + languageName: node + linkType: hard + "@ethereumjs/tx@npm:3.3.2": version: 3.3.2 resolution: "@ethereumjs/tx@npm:3.3.2" @@ -3705,7 +3700,7 @@ __metadata: languageName: node linkType: hard -"@noble/curves@npm:1.3.0": +"@noble/curves@npm:1.3.0, @noble/curves@npm:^1.3.0, @noble/curves@npm:~1.3.0": version: 1.3.0 resolution: "@noble/curves@npm:1.3.0" dependencies: @@ -3735,7 +3730,7 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:1.3.3, @noble/hashes@npm:^1.2.0": +"@noble/hashes@npm:1.3.3, @noble/hashes@npm:^1.3.3, @noble/hashes@npm:~1.3.2": version: 1.3.3 resolution: "@noble/hashes@npm:1.3.3" checksum: 1025ddde4d24630e95c0818e63d2d54ee131b980fe113312d17ed7468bc18f54486ac86c907685759f8a7e13c2f9b9e83ec7b67d1cc20836f36b5e4a65bb102d @@ -4601,7 +4596,7 @@ __metadata: languageName: node linkType: hard -"@scure/base@npm:~1.1.0": +"@scure/base@npm:~1.1.0, @scure/base@npm:~1.1.4": version: 1.1.5 resolution: "@scure/base@npm:1.1.5" checksum: 543fa9991c6378b6a0d5ab7f1e27b30bb9c1e860d3ac81119b4213cfdf0ad7b61be004e06506e89de7ce0cec9391c17f5c082bb34c3b617a2ee6a04129f52481 @@ -4641,6 +4636,17 @@ __metadata: languageName: node linkType: hard +"@scure/bip32@npm:^1.3.3": + version: 1.3.3 + resolution: "@scure/bip32@npm:1.3.3" + dependencies: + "@noble/curves": "npm:~1.3.0" + "@noble/hashes": "npm:~1.3.2" + "@scure/base": "npm:~1.1.4" + checksum: 4b8b75567866ff7d6b3ba154538add02d2951e9433e8dd7f0014331ac500cda5a88fe3d39b408fcc36e86b633682013f172b967af022c2e4e4ab07336801d688 + languageName: node + linkType: hard + "@scure/bip39@npm:1.1.1": version: 1.1.1 resolution: "@scure/bip39@npm:1.1.1" @@ -4671,6 +4677,16 @@ __metadata: languageName: node linkType: hard +"@scure/bip39@npm:^1.2.2": + version: 1.2.2 + resolution: "@scure/bip39@npm:1.2.2" + dependencies: + "@noble/hashes": "npm:~1.3.2" + "@scure/base": "npm:~1.1.4" + checksum: f71aceda10a7937bf3779fd2b4c4156c95ec9813269470ddca464cb8ab610d2451b173037f4b1e6dac45414e406e7adc7b5814c51279f4474d5d38140bbee542 + languageName: node + linkType: hard + "@sigstore/bundle@npm:^1.1.0": version: 1.1.0 resolution: "@sigstore/bundle@npm:1.1.0" @@ -6095,15 +6111,6 @@ __metadata: languageName: node linkType: hard -"@types/randombytes@npm:^2.0.0": - version: 2.0.0 - resolution: "@types/randombytes@npm:2.0.0" - dependencies: - "@types/node": "npm:*" - checksum: 3835678127f020e1f0812f9dbcf400ef98916bc6fb9aff7d36e701c996ae668163f49a69aa6ce6832ca5dd150e6376e3e586094be4f45cc1e190b0db39320671 - languageName: node - linkType: hard - "@types/responselike@npm:^1.0.0": version: 1.0.0 resolution: "@types/responselike@npm:1.0.0" @@ -7269,29 +7276,6 @@ __metadata: languageName: node linkType: hard -"bip32@npm:3.1.0, bip32@npm:^3.1.0": - version: 3.1.0 - resolution: "bip32@npm:3.1.0" - dependencies: - bs58check: "npm:^2.1.1" - create-hash: "npm:^1.2.0" - create-hmac: "npm:^1.1.7" - ripemd160: "npm:^2.0.2" - typeforce: "npm:^1.11.5" - wif: "npm:^2.0.6" - checksum: 6cdad901d25959e21835fe7b43066fc2498548962aa07ce438860b7420a7a93ceec3a9b34ddee68bbc568a68b9d96029338dbea1eadb548651b06d800a14fc3d - languageName: node - linkType: hard - -"bip39@https://github.com/bitcoinjs/bip39#a7ecbfe2e60d0214ce17163d610cad9f7b23140c": - version: 3.1.0 - resolution: "bip39@https://github.com/bitcoinjs/bip39.git#commit=a7ecbfe2e60d0214ce17163d610cad9f7b23140c" - dependencies: - "@noble/hashes": "npm:^1.2.0" - checksum: 406c0b5bdab0d43df2ff8916c5b57bb7f65cd36a115cbd7620a75b972638f8511840bfc27bfc68946027086fd33ed3050d8cd304e85fd527503b23d857a8486e - languageName: node - linkType: hard - "bl@npm:^1.0.0": version: 1.2.3 resolution: "bl@npm:1.2.3" @@ -7520,7 +7504,7 @@ __metadata: languageName: node linkType: hard -"bs58check@npm:<3.0.0, bs58check@npm:^2.1.1, bs58check@npm:^2.1.2": +"bs58check@npm:^2.1.2": version: 2.1.2 resolution: "bs58check@npm:2.1.2" dependencies: @@ -18639,15 +18623,6 @@ __metadata: languageName: node linkType: hard -"tiny-secp256k1@npm:2.2.1": - version: 2.2.1 - resolution: "tiny-secp256k1@npm:2.2.1" - dependencies: - uint8array-tools: "npm:0.0.7" - checksum: 8eb871e912c18d3282d9a6e4cf7f33e18548d48445b16d8381442529cbbf958bbaaa7912817898eadf896d2b8c631ddf3f212162e2305397d4260019d2e17418 - languageName: node - linkType: hard - "title-case@npm:^2.1.0": version: 2.1.1 resolution: "title-case@npm:2.1.1" @@ -19121,13 +19096,6 @@ __metadata: languageName: node linkType: hard -"typeforce@npm:^1.11.5": - version: 1.18.0 - resolution: "typeforce@npm:1.18.0" - checksum: dbf98c75b1d57e56e33c1e1271d5505e67981f4e6a2e2e6e8e31160b58777fea1726160810b6c606517db16476805b7dce315926ba2d4859b9a56cab05b7a41f - languageName: node - linkType: hard - "typescript@npm:5.3.3": version: 5.3.3 resolution: "typescript@npm:5.3.3" @@ -19157,13 +19125,6 @@ __metadata: languageName: node linkType: hard -"uint8array-tools@npm:0.0.7": - version: 0.0.7 - resolution: "uint8array-tools@npm:0.0.7" - checksum: 6ffc45c7d2136757d63c6e556eb8345f908948618a9de37c805fec1249d989c265187b3fbef6cffc4ce5129083204829025b3c58800a0f24c8548e243d42ba13 - languageName: node - linkType: hard - "ultron@npm:~1.1.0": version: 1.1.1 resolution: "ultron@npm:1.1.1" @@ -20332,15 +20293,6 @@ __metadata: languageName: node linkType: hard -"wif@npm:^2.0.6": - version: 2.0.6 - resolution: "wif@npm:2.0.6" - dependencies: - bs58check: "npm:<3.0.0" - checksum: c8d7581664532d9ab6d163ee5194a9bec71b089a6e50d54d6ec57a9bd714fcf84bc8d9f22f4cfc7c297fc6ad10b973b8e83eca5c41240163fc61f44b5154b7da - languageName: node - linkType: hard - "window-size@npm:^0.2.0": version: 0.2.0 resolution: "window-size@npm:0.2.0"