@tetherto/wdk-wallet-evm 1.0.0-beta.2 → 1.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +50 -0
- package/README.md +174 -224
- package/bare.js +3 -3
- package/{hardhat.config.cjs → hardhat.config.js} +4 -3
- package/index.js +23 -1
- package/package.json +29 -14
- package/src/memory-safe/hd-node-wallet.js +5 -4
- package/src/memory-safe/signing-key.js +4 -3
- package/src/multicall.js +75 -0
- package/src/signers/index.js +25 -0
- package/src/signers/private-key-signer-evm.js +156 -0
- package/src/signers/seed-signer-evm.js +314 -0
- package/src/utils/tx-populator-evm.js +202 -0
- package/src/wallet-account-evm.js +272 -63
- package/src/wallet-account-read-only-evm.js +470 -33
- package/src/wallet-manager-evm.js +96 -39
- package/types/index.d.ts +20 -1
- package/types/src/signers/index.d.ts +3 -0
- package/types/src/signers/private-key-signer-evm.d.ts +81 -0
- package/types/src/signers/seed-signer-evm.d.ts +187 -0
- package/types/src/utils/tx-populator-evm.d.ts +85 -0
- package/types/src/wallet-account-evm.d.ts +131 -22
- package/types/src/wallet-account-read-only-evm.d.ts +226 -14
- package/types/src/wallet-manager-evm.d.ts +43 -19
package/index.js
CHANGED
|
@@ -13,16 +13,38 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
+
/** @typedef {import('ethers').TypedDataDomain} TypedDataDomain */
|
|
17
|
+
/** @typedef {import('ethers').TypedDataField} TypedDataField */
|
|
18
|
+
/** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
|
|
19
|
+
/** @typedef {import('ethers').Authorization} Authorization */
|
|
20
|
+
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
16
21
|
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
22
|
+
/** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
|
|
23
|
+
/** @typedef {import('ethers').TransactionRequest} EvmTransactionRequest */
|
|
24
|
+
/** @typedef {import('ethers').BlobLike} BlobLike */
|
|
17
25
|
|
|
18
26
|
/** @typedef {import('@tetherto/wdk-wallet').FeeRates} FeeRates */
|
|
19
27
|
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
20
28
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
21
|
-
/** @typedef {import('@tetherto/wdk-wallet').TransferOptions} TransferOptions */
|
|
22
29
|
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
30
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransferOptions} TransferOptions */
|
|
31
|
+
/** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
|
|
32
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
|
|
33
|
+
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
|
|
34
|
+
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
|
|
23
35
|
|
|
36
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
37
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').DelegationInfo} DelegationInfo */
|
|
24
38
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransaction} EvmTransaction */
|
|
39
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmGasOverrides} EvmGasOverrides */
|
|
40
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransferOptions} EvmTransferOptions */
|
|
25
41
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
42
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransactionDetails} EvmTransactionDetails */
|
|
43
|
+
|
|
44
|
+
/** @typedef {import('./src/wallet-account-evm.js').ApproveOptions} ApproveOptions */
|
|
45
|
+
/** @typedef {import('./src/wallet-account-evm.js').EvmApproveOptions} EvmApproveOptions */
|
|
46
|
+
|
|
47
|
+
/** @typedef {import('./src/utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
26
48
|
|
|
27
49
|
export { default } from './src/wallet-manager-evm.js'
|
|
28
50
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet-evm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
|
+
"description": "EVM wallet module for WDK (Wallet Development Kit) by Tether.",
|
|
5
|
+
"homepage": "https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"wdk",
|
|
7
8
|
"wallet",
|
|
@@ -21,28 +22,38 @@
|
|
|
21
22
|
"build:types": "tsc",
|
|
22
23
|
"lint": "standard",
|
|
23
24
|
"lint:fix": "standard --fix",
|
|
24
|
-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
25
|
-
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
26
|
-
"test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration",
|
|
27
|
-
"test:integration:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration --coverage"
|
|
25
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=/tests/integration/",
|
|
26
|
+
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --testPathIgnorePatterns=/tests/integration/",
|
|
27
|
+
"test:integration-wait": "wait-on tcp:127.0.0.1:8545 && cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration --runInBand",
|
|
28
|
+
"test:integration-wait:coverage": "wait-on tcp:127.0.0.1:8545 && cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration --coverage --runInBand",
|
|
29
|
+
"test:integration": "concurrently -k -s first -n \"NODE,TEST\" -c \"black,green\" --hide NODE \"npx hardhat node --network hardhat\" \"npm run test:integration-wait\"",
|
|
30
|
+
"test:integration:coverage": "concurrently -k -s first -n \"NODE,TEST\" -c \"black,green\" --hide NODE \"npx hardhat node --network hardhat\" \"npm run test:integration-wait:coverage\""
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@noble/curves": "1.9.2",
|
|
31
33
|
"@noble/hashes": "1.8.0",
|
|
32
34
|
"@noble/secp256k1": "2.2.3",
|
|
33
|
-
"@tetherto/wdk-
|
|
34
|
-
"
|
|
35
|
+
"@tetherto/wdk-failover-provider": "1.0.0-beta.2",
|
|
36
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.17",
|
|
37
|
+
"bare-node-runtime": "^1.5.0",
|
|
35
38
|
"bip39": "3.1.0",
|
|
36
|
-
"ethers": "6.
|
|
39
|
+
"ethers": "6.17.0",
|
|
37
40
|
"sodium-universal": "5.0.1"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
|
-
"
|
|
43
|
+
"concurrently": "9.2.0",
|
|
41
44
|
"cross-env": "7.0.3",
|
|
42
|
-
"hardhat": "
|
|
45
|
+
"hardhat": "3.12.0",
|
|
43
46
|
"jest": "29.7.0",
|
|
44
47
|
"standard": "17.1.2",
|
|
45
|
-
"typescript": "5.8.3"
|
|
48
|
+
"typescript": "5.8.3",
|
|
49
|
+
"wait-on": "8.0.4"
|
|
50
|
+
},
|
|
51
|
+
"devEngines": {
|
|
52
|
+
"runtime": {
|
|
53
|
+
"name": "node",
|
|
54
|
+
"version": ">=22.13.0",
|
|
55
|
+
"onFail": "error"
|
|
56
|
+
}
|
|
46
57
|
},
|
|
47
58
|
"exports": {
|
|
48
59
|
".": {
|
|
@@ -50,12 +61,16 @@
|
|
|
50
61
|
"bare": "./bare.js",
|
|
51
62
|
"default": "./index.js"
|
|
52
63
|
},
|
|
64
|
+
"./signers": {
|
|
65
|
+
"types": "./types/src/signers/index.d.ts",
|
|
66
|
+
"default": "./src/signers/index.js"
|
|
67
|
+
},
|
|
53
68
|
"./package": {
|
|
54
69
|
"default": "./package.json"
|
|
55
70
|
}
|
|
56
71
|
},
|
|
57
72
|
"publishConfig": {
|
|
58
|
-
"access": "
|
|
73
|
+
"access": "public",
|
|
59
74
|
"registry": "https://registry.npmjs.org/"
|
|
60
75
|
},
|
|
61
76
|
"standard": {
|
|
@@ -156,14 +156,15 @@ export default class MemorySafeHDNodeWallet extends BaseWallet {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
const { IR, IL } = serI(index, this.chainCode, this.publicKey, this.privateKeyBuffer)
|
|
159
|
+
const childPriv = new Uint8Array(this.privateKeyBuffer)
|
|
159
160
|
|
|
160
|
-
const overflow = addToPrivateKey(
|
|
161
|
+
const overflow = addToPrivateKey(childPriv, IL)
|
|
161
162
|
|
|
162
|
-
if (overflow || compareWithCurveOrder(
|
|
163
|
-
subtractCurveOrderFromPrivateKey(
|
|
163
|
+
if (overflow || compareWithCurveOrder(childPriv) >= 0) {
|
|
164
|
+
subtractCurveOrderFromPrivateKey(childPriv)
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
const ki = new MemorySafeSigningKey(
|
|
167
|
+
const ki = new MemorySafeSigningKey(childPriv)
|
|
167
168
|
|
|
168
169
|
return new MemorySafeHDNodeWallet(_guard, ki, this.fingerprint, hexlify(IR),
|
|
169
170
|
path, index, this.depth + 1, this.mnemonic, this.provider)
|
|
@@ -70,8 +70,9 @@ export default class MemorySafeSigningKey extends SigningKey {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
dispose () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
if (this._privateKeyBuffer) {
|
|
74
|
+
sodium_memzero(this._privateKeyBuffer)
|
|
75
|
+
this._privateKeyBuffer = undefined
|
|
76
|
+
}
|
|
76
77
|
}
|
|
77
78
|
}
|
package/src/multicall.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
import { AbiCoder, concat, decodeBase64, hexlify } from 'ethers'
|
|
18
|
+
|
|
19
|
+
/** @typedef {import('ethers').Provider} Provider */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
* @typedef {Object} MulticallRequest
|
|
24
|
+
* @property {string} to - The target contract address.
|
|
25
|
+
* @property {string} data - The ABI-encoded calldata.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
* @typedef {Object} MulticallResult
|
|
31
|
+
* @property {boolean} status - Whether the call succeeded.
|
|
32
|
+
* @property {string} data - The ABI-encoded return data.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Compiled multicall constructor bytecode. Executes calls via staticcall and
|
|
37
|
+
* returns results without deploying. Source: ethers-io/ext-provider-multicall (MIT).
|
|
38
|
+
*
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
const _MULTICALL_BYTECODE = hexlify(decodeBase64('YIBgQFI0gBVhABBXYACA/VtQYEBRYQSxOAOAYQSxgzmBAWBAgZBSYQAvkWECWlZbYACBUWABYEBgAgoDgREVYQBKV2EASmEBr1ZbYEBRkICCUoBgIAJgIAGCAWBAUoAVYQCQV4FgIAFbYECAUYCCAZCRUmAAgVJgYGAgggFSgVJgIAGQYAGQA5CBYQBoV5BQW1CQUGAAW4JRgRAVYQE/V2EA8oOCgVGBEGEAtFdhALRhA+NWW2AgAmAgAQFRYAABUYSDgVGBEGEA0ldhANJhA+NWW2AgAmAgAQFRYCABUWEBbmQBAAAAAAJkAQAAAACQBFZbg4OBUYEQYQEEV2EBBGED41ZbYCACYCABAVFgAAGEhIFRgRBhASFXYQEhYQPjVltgIJCBApGQkQGBAVEBkZCRUpAVFZBSYAEBYQCWVltQYABDgmBAUWAgAWEBVZKRkGEEElZbYEBRYCCBgwMDgVKQYEBSkFCAUWAgggHzW2AAYGBgQFGQUGAAgVJgIIEBYEBSYACAhFFgIIYBh1r6YD89AWAfGRaCAWBAUj2CUpFQPWAAYCCDAT6SUJKQUFZbf05Ie3EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYABSYEFgBFJgJGAA/VtgQIBRkIEBYAFgQGACCgOBEYKCEBcVYQIAV2ECAGEBr1ZbYEBSkFZbYEBRYB+CAWAfGRaBAWABYEBgAgoDgRGCghAXFWECLldhAi5hAa9WW2BAUpGQUFZbYABbg4EQFWECUVeBgQFRg4IBUmAgAWECOVZbUFBgAJEBUlZbYABgIIKEAxIVYQJsV2AAgP1bgVFgAWBAYAIKA4ERFWECgldgAID9W4IBYB+BAYQTYQKTV2AAgP1bgFFgAWBAYAIKA4ERFWECrFdhAqxhAa9WW2AggQJhArxgIIIBYQIGVluRglJgIIGEAYEBkpCBAZCHhBEVYQLYV2AAgP1bYCCFAZJQW4ODEBVhA9hXglFgAWBAYAIKA4ERFWEC/VdgAID9W4UBYECBigNgHxkBEhVhAxNXYACA/VthAxthAd5WW2AgggFRYAFgoGACCgOBFoEUYQM1V2AAgP1bgVJgQIIBUWABYEBgAgoDgREVYQNQV2AAgP1bYCCBhAEBklBQiWAfgwESYQNoV2AAgP1bgVFgAWBAYAIKA4ERFWEDgVdhA4FhAa9WW2EDlGAfggFgHxkWYCABYQIGVluBgVKLYCCDhgEBERVhA6lXYACA/VthA7qCYCCDAWAghwFhAjZWW4BgIIQBUlBQgIRSUFBgIIIBkVBgIIMBklBhAt9WW5eWUFBQUFBQUFZbf05Ie3EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYABSYDJgBFJgJGAA/VtgAGBAggGEg1JgQGAghAFSgIRRgINSYGCFAZFQYGBgIIIChgEBklBgIIYBYABbgoEQFWEEo1dgXxmHhgMBhFKBUYBRFRWGUmAggQFRkFBgQGAghwFSgFGAYECIAVJhBICBYGCJAWAghQFhAjZWW2AfAWAfGRaVkJUBYGABlFBgIJOEAZORkJEBkGABAWEEQFZbUJKXllBQUFBQUFBW/g=='))
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Executes multiple read-only contract calls in a single RPC round-trip.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
* @param {Provider} provider - An ethers provider.
|
|
48
|
+
* @param {MulticallRequest[]} calls - The calls to batch.
|
|
49
|
+
* @returns {Promise<MulticallResult[]>} The result of each call.
|
|
50
|
+
*/
|
|
51
|
+
export async function multicall (provider, calls) {
|
|
52
|
+
if (calls.length === 0) {
|
|
53
|
+
return []
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const data = concat([
|
|
57
|
+
_MULTICALL_BYTECODE,
|
|
58
|
+
AbiCoder.defaultAbiCoder().encode(
|
|
59
|
+
['tuple(address, bytes)[]'],
|
|
60
|
+
[calls.map(call => [call.to, call.data])]
|
|
61
|
+
)
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
const resultData = await provider.call({ data })
|
|
65
|
+
|
|
66
|
+
const [, results] = AbiCoder.defaultAbiCoder().decode(
|
|
67
|
+
['uint', 'tuple(bool, bytes)[]'],
|
|
68
|
+
resultData
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return results.map(result => ({
|
|
72
|
+
status: result[0],
|
|
73
|
+
data: result[1]
|
|
74
|
+
}))
|
|
75
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// src/signers/index.js
|
|
15
|
+
/**
|
|
16
|
+
* Barrel exports for EVM signers.
|
|
17
|
+
*
|
|
18
|
+
* - `SeedSignerEvm`: derives accounts from a BIP-39 seed (BIP-44 path).
|
|
19
|
+
* - `PrivateKeySignerEvm`: memory-safe wrapper around a raw private key.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
23
|
+
|
|
24
|
+
export { default, default as SeedSignerEvm } from './seed-signer-evm.js'
|
|
25
|
+
export { default as PrivateKeySignerEvm } from './private-key-signer-evm.js'
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
'use strict'
|
|
15
|
+
|
|
16
|
+
import { BaseWallet } from 'ethers'
|
|
17
|
+
|
|
18
|
+
import { InvalidSignerError } from '@tetherto/wdk-wallet'
|
|
19
|
+
|
|
20
|
+
import MemorySafeSigningKey from '../memory-safe/signing-key.js'
|
|
21
|
+
import { ISignerEvm } from './seed-signer-evm.js'
|
|
22
|
+
|
|
23
|
+
/** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
24
|
+
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
25
|
+
/** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
|
|
26
|
+
/** @typedef {import('ethers').Authorization} Authorization */
|
|
27
|
+
/** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @extends {ISignerEvm}
|
|
31
|
+
* Signer that wraps a raw private key in a memory-safe buffer, exposing a minimal
|
|
32
|
+
* interface for signing messages, transactions and typed data. This signer does
|
|
33
|
+
* not support derivation and always represents a single account.
|
|
34
|
+
*/
|
|
35
|
+
export default class PrivateKeySignerEvm extends ISignerEvm {
|
|
36
|
+
/**
|
|
37
|
+
* Create a signer from a raw private key.
|
|
38
|
+
*
|
|
39
|
+
* @param {string|Uint8Array} privateKey - Hex string (with/without 0x) or raw key bytes.
|
|
40
|
+
*/
|
|
41
|
+
constructor (privateKey) {
|
|
42
|
+
super()
|
|
43
|
+
|
|
44
|
+
// Expect a Uint8Array buffer; accept hex string as convenience
|
|
45
|
+
let privateKeyBuffer = privateKey
|
|
46
|
+
if (typeof privateKey === 'string') {
|
|
47
|
+
const hex = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey
|
|
48
|
+
privateKeyBuffer = new Uint8Array(Buffer.from(hex, 'hex'))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @private */
|
|
52
|
+
this._signingKey = new MemorySafeSigningKey(privateKeyBuffer)
|
|
53
|
+
/** @private */
|
|
54
|
+
this._wallet = new BaseWallet(this._signingKey, null)
|
|
55
|
+
/** @private */
|
|
56
|
+
this._address = this._wallet.address
|
|
57
|
+
/** @private */
|
|
58
|
+
this._path = undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether this signer can derive child signers. Always false: a private-key signer is a
|
|
63
|
+
* single standalone account and is bound directly to a wallet account.
|
|
64
|
+
* @type {boolean}
|
|
65
|
+
*/
|
|
66
|
+
get isDerivable () { return false }
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The account index. Always undefined for private key signers: a raw key has no
|
|
70
|
+
* BIP-44 position, so reporting an index would be misleading.
|
|
71
|
+
* @type {number|undefined}
|
|
72
|
+
*/
|
|
73
|
+
get index () { return undefined }
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The derivation path. Always undefined for private key signers.
|
|
77
|
+
* @type {string|undefined}
|
|
78
|
+
*/
|
|
79
|
+
get path () { return this._path }
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The account's address.
|
|
83
|
+
* @type {string}
|
|
84
|
+
*/
|
|
85
|
+
get address () { return this._address }
|
|
86
|
+
/**
|
|
87
|
+
* The account's key pair (private and public key buffers).
|
|
88
|
+
* @type {KeyPair}
|
|
89
|
+
*/
|
|
90
|
+
get keyPair () {
|
|
91
|
+
return {
|
|
92
|
+
privateKey: this._signingKey ? this._signingKey.privateKeyBuffer : null,
|
|
93
|
+
publicKey: this._signingKey ? this._signingKey.publicKeyBuffer : null
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
|
|
99
|
+
* @returns {Promise<never>}
|
|
100
|
+
* @throws {InvalidSignerError} Always — private-key signers do not support derivation.
|
|
101
|
+
*/
|
|
102
|
+
async derive () {
|
|
103
|
+
throw new InvalidSignerError('PrivateKeySignerEvm does not support derivation.')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @returns {Promise<string>} */
|
|
107
|
+
async getAddress () {
|
|
108
|
+
return this._address
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Signs a message.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} message - The message to sign.
|
|
115
|
+
* @returns {Promise<string>} The message's signature.
|
|
116
|
+
*/
|
|
117
|
+
async sign (message) {
|
|
118
|
+
return this._wallet.signMessage(message)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Signs a transaction and returns the serialized signed transaction hex.
|
|
123
|
+
*
|
|
124
|
+
* @param {UnsignedEvmTransaction} unsignedTx - The unsigned transaction object.
|
|
125
|
+
* @returns {Promise<string>}
|
|
126
|
+
*/
|
|
127
|
+
async signTransaction (unsignedTx) {
|
|
128
|
+
return this._wallet.signTransaction(unsignedTx)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Signs typed data according to EIP-712.
|
|
133
|
+
*
|
|
134
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
135
|
+
* @returns {Promise<string>} The typed data signature.
|
|
136
|
+
*/
|
|
137
|
+
async signTypedData ({ domain, types, message }) {
|
|
138
|
+
return this._wallet.signTypedData(domain, types, message)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sign an ERC-7702 authorization tuple.
|
|
143
|
+
* @param {AuthorizationRequest} auth
|
|
144
|
+
* @returns {Promise<Authorization>}
|
|
145
|
+
*/
|
|
146
|
+
async signAuthorization (auth) {
|
|
147
|
+
return this._wallet.authorizeSync(auth)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Dispose secrets from memory. */
|
|
151
|
+
dispose () {
|
|
152
|
+
if (this._signingKey) this._signingKey.dispose()
|
|
153
|
+
this._signingKey = undefined
|
|
154
|
+
this._wallet = undefined
|
|
155
|
+
}
|
|
156
|
+
}
|