signet.js 0.0.6 → 0.0.7
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/.eslintrc.json +67 -0
- package/.prettierrc +1 -0
- package/babel.config.js +6 -0
- package/docs/dist/.vocs/icons/arrow-diagonal.svg +3 -0
- package/docs/dist/.vocs/icons/chevron-down.svg +13 -0
- package/docs/dist/.vocs/icons/chevron-up.svg +13 -0
- package/docs/dist/.vocs/icons/link.svg +3 -0
- package/docs/dist/.vocs/search-index-7b499e25.json +1 -0
- package/docs/dist/assets/arbitrary-hash-Cd6eo8ZD.js +309 -0
- package/docs/dist/assets/broadcast-tx-CeTEE9yX.js +8 -0
- package/docs/dist/assets/btc-rpc-adapter-C-qSHpFV.js +226 -0
- package/docs/dist/assets/chain-adapter-interface-B9TpOgQv.js +1280 -0
- package/docs/dist/assets/chain-contract-interface-DEku3k45.js +392 -0
- package/docs/dist/assets/constructor-73n7bp3b.js +161 -0
- package/docs/dist/assets/constructor-Bg7nvLe0.js +14 -0
- package/docs/dist/assets/contract-addresses-BYlrAOs3.js +200 -0
- package/docs/dist/assets/derive-address-and-public-key-DExrKiGV.js +14 -0
- package/docs/dist/assets/finalize-message-signing-W435d71R.js +20 -0
- package/docs/dist/assets/finalize-transaction-signing-BIgJ2dnc.js +36 -0
- package/docs/dist/assets/finalize-transaction-signing-C--HJs8D.js +24 -0
- package/docs/dist/assets/finalize-transaction-signing-CjGmN7d9.js +24 -0
- package/docs/dist/assets/finalize-typed-data-signing-CEOp_GWt.js +21 -0
- package/docs/dist/assets/get-balance-DBC-i6KG.js +13 -0
- package/docs/dist/assets/get-current-signature-deposit-BXm9AzYy.js +6 -0
- package/docs/dist/assets/get-current-signature-deposit-nOw4j1MN.js +6 -0
- package/docs/dist/assets/get-derived-public-key-BXvfo2m2.js +14 -0
- package/docs/dist/assets/get-derived-public-key-DQ1pyiFS.js +14 -0
- package/docs/dist/assets/get-latest-key-version-DWlkMCre.js +6 -0
- package/docs/dist/assets/get-public-key-B4PFoVqu.js +6 -0
- package/docs/dist/assets/get-public-key-B9xkYkD_.js +6 -0
- package/docs/dist/assets/index-BFuwoY4w.js +601 -0
- package/docs/dist/assets/index-C62Mf-vy.js +426 -0
- package/docs/dist/assets/index-D8xhaiVb.js +121 -0
- package/docs/dist/assets/index-DTr0DlO0.js +36 -0
- package/docs/dist/assets/index-V9dXf-ik.js +457 -0
- package/docs/dist/assets/prepare-message-for-signing-DESTq-Hg.js +16 -0
- package/docs/dist/assets/prepare-transaction-for-signing-DIKTU0zj.js +33 -0
- package/docs/dist/assets/prepare-transaction-for-signing-DV_wkZ5g.js +21 -0
- package/docs/dist/assets/prepare-transaction-for-signing-LVDP0COu.js +33 -0
- package/docs/dist/assets/prepare-typed-data-for-signing-CWcmJvw0.js +192 -0
- package/docs/dist/assets/sign-CwtS5LnB.js +13 -0
- package/docs/dist/assets/sign-OQxf9yn7.js +15 -0
- package/docs/dist/assets/signet-quick-start-CQK52nVG.js +350 -0
- package/docs/dist/assets/sponsor-foreign-chain-gas-C9iWXM8Q.js +1 -0
- package/docs/dist/assets/style-CKGXuRqx.css +1 -0
- package/docs/dist/examples/arbitrary-hash/index.html +88 -0
- package/docs/dist/examples/sponsor-foreign-chain-gas/index.html +21 -0
- package/docs/dist/index.html +56 -0
- package/docs/dist/initializeTheme.iife.js +1 -0
- package/docs/dist/introduction/signet-quick-start/index.html +109 -0
- package/docs/dist/primitives/chain-adapter-interface/index.html +515 -0
- package/docs/dist/primitives/chain-contract-interface/index.html +306 -0
- package/docs/dist/primitives/contract-addresses/index.html +97 -0
- package/docs/dist/signet-logo.png +0 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/btc-rpc-adapter/index.html +148 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/finalize-transaction-signing/index.html +41 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/index.html +187 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing/index.html +34 -0
- package/docs/dist/signetjs/chain-adapters/broadcast-tx/index.html +28 -0
- package/docs/dist/signetjs/chain-adapters/cosmos/finalize-transaction-signing/index.html +41 -0
- package/docs/dist/signetjs/chain-adapters/cosmos/index.html +166 -0
- package/docs/dist/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing/index.html +43 -0
- package/docs/dist/signetjs/chain-adapters/derive-address-and-public-key/index.html +31 -0
- package/docs/dist/signetjs/chain-adapters/evm/finalize-message-signing/index.html +38 -0
- package/docs/dist/signetjs/chain-adapters/evm/finalize-transaction-signing/index.html +41 -0
- package/docs/dist/signetjs/chain-adapters/evm/finalize-typed-data-signing/index.html +39 -0
- package/docs/dist/signetjs/chain-adapters/evm/index.html +129 -0
- package/docs/dist/signetjs/chain-adapters/evm/prepare-message-for-signing/index.html +31 -0
- package/docs/dist/signetjs/chain-adapters/evm/prepare-transaction-for-signing/index.html +34 -0
- package/docs/dist/signetjs/chain-adapters/evm/prepare-typed-data-for-signing/index.html +49 -0
- package/docs/dist/signetjs/chain-adapters/get-balance/index.html +30 -0
- package/docs/dist/signetjs/contracts/evm/constructor/index.html +45 -0
- package/docs/dist/signetjs/contracts/evm/get-current-signature-deposit/index.html +26 -0
- package/docs/dist/signetjs/contracts/evm/get-derived-public-key/index.html +31 -0
- package/docs/dist/signetjs/contracts/evm/get-latest-key-version/index.html +26 -0
- package/docs/dist/signetjs/contracts/evm/get-public-key/index.html +26 -0
- package/docs/dist/signetjs/contracts/evm/sign/index.html +32 -0
- package/docs/dist/signetjs/contracts/near/constructor/index.html +34 -0
- package/docs/dist/signetjs/contracts/near/get-current-signature-deposit/index.html +26 -0
- package/docs/dist/signetjs/contracts/near/get-derived-public-key/index.html +31 -0
- package/docs/dist/signetjs/contracts/near/get-public-key/index.html +26 -0
- package/docs/dist/signetjs/contracts/near/sign/index.html +32 -0
- package/docs/pages/examples/arbitrary-hash.mdx +73 -0
- package/docs/pages/examples/sponsor-foreign-chain-gas.mdx +1 -0
- package/docs/pages/index.mdx +36 -0
- package/docs/pages/introduction/signet-quick-start.mdx +88 -0
- package/docs/pages/primitives/chain-adapter-interface.mdx +45 -0
- package/docs/pages/primitives/chain-contract-interface.mdx +52 -0
- package/docs/pages/primitives/contract-addresses.mdx +27 -0
- package/docs/pages/signetjs/chain-adapters/bitcoin/btc-rpc-adapter.mdx +26 -0
- package/docs/pages/signetjs/chain-adapters/bitcoin/finalize-transaction-signing.mdx +47 -0
- package/docs/pages/signetjs/chain-adapters/bitcoin/index.mdx +119 -0
- package/docs/pages/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing.mdx +30 -0
- package/docs/pages/signetjs/chain-adapters/broadcast-tx.mdx +23 -0
- package/docs/pages/signetjs/chain-adapters/cosmos/finalize-transaction-signing.mdx +53 -0
- package/docs/pages/signetjs/chain-adapters/cosmos/index.mdx +108 -0
- package/docs/pages/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing.mdx +39 -0
- package/docs/pages/signetjs/chain-adapters/derive-address-and-public-key.mdx +28 -0
- package/docs/pages/signetjs/chain-adapters/evm/finalize-message-signing.mdx +33 -0
- package/docs/pages/signetjs/chain-adapters/evm/finalize-transaction-signing.mdx +44 -0
- package/docs/pages/signetjs/chain-adapters/evm/finalize-typed-data-signing.mdx +34 -0
- package/docs/pages/signetjs/chain-adapters/evm/index.mdx +84 -0
- package/docs/pages/signetjs/chain-adapters/evm/prepare-message-for-signing.mdx +26 -0
- package/docs/pages/signetjs/chain-adapters/evm/prepare-transaction-for-signing.mdx +30 -0
- package/docs/pages/signetjs/chain-adapters/evm/prepare-typed-data-for-signing.mdx +44 -0
- package/docs/pages/signetjs/chain-adapters/get-balance.mdx +26 -0
- package/docs/pages/signetjs/contracts/evm/constructor.mdx +38 -0
- package/docs/pages/signetjs/contracts/evm/get-current-signature-deposit.mdx +17 -0
- package/docs/pages/signetjs/contracts/evm/get-derived-public-key.mdx +28 -0
- package/docs/pages/signetjs/contracts/evm/get-latest-key-version.mdx +17 -0
- package/docs/pages/signetjs/contracts/evm/get-public-key.mdx +17 -0
- package/docs/pages/signetjs/contracts/evm/sign.mdx +36 -0
- package/docs/pages/signetjs/contracts/near/constructor.mdx +29 -0
- package/docs/pages/signetjs/contracts/near/get-current-signature-deposit.mdx +17 -0
- package/docs/pages/signetjs/contracts/near/get-derived-public-key.mdx +28 -0
- package/docs/pages/signetjs/contracts/near/get-public-key.mdx +17 -0
- package/docs/pages/signetjs/contracts/near/sign.mdx +32 -0
- package/docs/public/signet-logo.png +0 -0
- package/docs/snippets/code/chains.ts +42 -0
- package/docs/snippets/code/contract.ts +44 -0
- package/docs/snippets/code/evm/contract.ts +24 -0
- package/docs/snippets/code/evm/env.ts +16 -0
- package/docs/snippets/code/near/env.ts +13 -0
- package/hardhat.config.mts +19 -0
- package/package.json +18 -19
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +15 -0
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +101 -0
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/index.ts +1 -0
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types.ts +72 -0
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/index.ts +6 -0
- package/src/chain-adapters/Bitcoin/Bitcoin.ts +287 -0
- package/src/chain-adapters/Bitcoin/index.ts +13 -0
- package/src/chain-adapters/Bitcoin/types.ts +48 -0
- package/src/chain-adapters/Bitcoin/utils.ts +14 -0
- package/src/chain-adapters/ChainAdapter.ts +92 -0
- package/src/chain-adapters/Cosmos/Cosmos.ts +258 -0
- package/src/chain-adapters/Cosmos/index.ts +8 -0
- package/src/chain-adapters/Cosmos/types.ts +35 -0
- package/src/chain-adapters/Cosmos/utils.ts +45 -0
- package/src/chain-adapters/EVM/EVM.test.ts +238 -0
- package/src/chain-adapters/EVM/EVM.ts +337 -0
- package/src/chain-adapters/EVM/index.ts +11 -0
- package/src/chain-adapters/EVM/types.ts +53 -0
- package/src/chain-adapters/EVM/utils.ts +27 -0
- package/src/chain-adapters/index.ts +5 -0
- package/src/constants.ts +62 -0
- package/src/contracts/ChainSignatureContract.ts +65 -0
- package/src/contracts/evm/ChainSignaturesContract.ts +323 -0
- package/src/contracts/evm/ChainSignaturesContractABI.ts +359 -0
- package/src/contracts/evm/errors.ts +52 -0
- package/src/contracts/evm/index.ts +10 -0
- package/src/contracts/evm/types.ts +39 -0
- package/src/contracts/evm/utils.ts +41 -0
- package/src/contracts/index.ts +4 -0
- package/src/contracts/near/ChainSignatureContract.ts +196 -0
- package/src/contracts/near/account.ts +42 -0
- package/src/contracts/near/constants.ts +4 -0
- package/src/contracts/near/index.ts +10 -0
- package/src/contracts/near/signAndSend/index.ts +1 -0
- package/src/contracts/near/signAndSend/keypair.ts +178 -0
- package/src/contracts/near/transaction.ts +202 -0
- package/src/contracts/near/types.ts +71 -0
- package/src/index.ts +5 -0
- package/src/types.ts +46 -0
- package/src/utils/cryptography.ts +141 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/publicKey.ts +17 -0
- package/tsconfig.eslint.json +8 -0
- package/tsconfig.json +126 -0
- package/tsup.config.ts +58 -0
- package/vitest.config.ts +19 -0
- package/vocs.config.ts +213 -0
- package/browser/index.browser.cjs +0 -3
- package/browser/index.browser.cjs.map +0 -1
- package/browser/index.browser.js +0 -3
- package/browser/index.browser.js.map +0 -1
- package/node/index.node.cjs +0 -3
- package/node/index.node.cjs.map +0 -1
- package/node/index.node.js +0 -3
- package/node/index.node.js.map +0 -1
- package/types/index.d.cts +0 -1048
- package/types/index.d.ts +0 -1048
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
export const abi = [
|
|
2
|
+
{
|
|
3
|
+
inputs: [
|
|
4
|
+
{ internalType: 'address', name: '_mpc_network', type: 'address' },
|
|
5
|
+
{ internalType: 'uint256', name: '_signatureDeposit', type: 'uint256' },
|
|
6
|
+
],
|
|
7
|
+
stateMutability: 'nonpayable',
|
|
8
|
+
type: 'constructor',
|
|
9
|
+
},
|
|
10
|
+
{ inputs: [], name: 'AccessControlBadConfirmation', type: 'error' },
|
|
11
|
+
{
|
|
12
|
+
inputs: [
|
|
13
|
+
{ internalType: 'address', name: 'account', type: 'address' },
|
|
14
|
+
{ internalType: 'bytes32', name: 'neededRole', type: 'bytes32' },
|
|
15
|
+
],
|
|
16
|
+
name: 'AccessControlUnauthorizedAccount',
|
|
17
|
+
type: 'error',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
anonymous: false,
|
|
21
|
+
inputs: [
|
|
22
|
+
{ indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
23
|
+
{
|
|
24
|
+
indexed: true,
|
|
25
|
+
internalType: 'bytes32',
|
|
26
|
+
name: 'previousAdminRole',
|
|
27
|
+
type: 'bytes32',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
indexed: true,
|
|
31
|
+
internalType: 'bytes32',
|
|
32
|
+
name: 'newAdminRole',
|
|
33
|
+
type: 'bytes32',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
name: 'RoleAdminChanged',
|
|
37
|
+
type: 'event',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
anonymous: false,
|
|
41
|
+
inputs: [
|
|
42
|
+
{ indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
43
|
+
{
|
|
44
|
+
indexed: true,
|
|
45
|
+
internalType: 'address',
|
|
46
|
+
name: 'account',
|
|
47
|
+
type: 'address',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
indexed: true,
|
|
51
|
+
internalType: 'address',
|
|
52
|
+
name: 'sender',
|
|
53
|
+
type: 'address',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
name: 'RoleGranted',
|
|
57
|
+
type: 'event',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
anonymous: false,
|
|
61
|
+
inputs: [
|
|
62
|
+
{ indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
63
|
+
{
|
|
64
|
+
indexed: true,
|
|
65
|
+
internalType: 'address',
|
|
66
|
+
name: 'account',
|
|
67
|
+
type: 'address',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
indexed: true,
|
|
71
|
+
internalType: 'address',
|
|
72
|
+
name: 'sender',
|
|
73
|
+
type: 'address',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
name: 'RoleRevoked',
|
|
77
|
+
type: 'event',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
anonymous: false,
|
|
81
|
+
inputs: [
|
|
82
|
+
{
|
|
83
|
+
indexed: true,
|
|
84
|
+
internalType: 'bytes32',
|
|
85
|
+
name: 'requestId',
|
|
86
|
+
type: 'bytes32',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
indexed: false,
|
|
90
|
+
internalType: 'address',
|
|
91
|
+
name: 'responder',
|
|
92
|
+
type: 'address',
|
|
93
|
+
},
|
|
94
|
+
{ indexed: false, internalType: 'string', name: 'error', type: 'string' },
|
|
95
|
+
],
|
|
96
|
+
name: 'SignatureError',
|
|
97
|
+
type: 'event',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
anonymous: false,
|
|
101
|
+
inputs: [
|
|
102
|
+
{
|
|
103
|
+
indexed: false,
|
|
104
|
+
internalType: 'address',
|
|
105
|
+
name: 'sender',
|
|
106
|
+
type: 'address',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
indexed: false,
|
|
110
|
+
internalType: 'bytes32',
|
|
111
|
+
name: 'payload',
|
|
112
|
+
type: 'bytes32',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
indexed: false,
|
|
116
|
+
internalType: 'uint32',
|
|
117
|
+
name: 'keyVersion',
|
|
118
|
+
type: 'uint32',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
indexed: false,
|
|
122
|
+
internalType: 'uint256',
|
|
123
|
+
name: 'deposit',
|
|
124
|
+
type: 'uint256',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
indexed: false,
|
|
128
|
+
internalType: 'uint256',
|
|
129
|
+
name: 'chainId',
|
|
130
|
+
type: 'uint256',
|
|
131
|
+
},
|
|
132
|
+
{ indexed: false, internalType: 'string', name: 'path', type: 'string' },
|
|
133
|
+
{ indexed: false, internalType: 'string', name: 'algo', type: 'string' },
|
|
134
|
+
{ indexed: false, internalType: 'string', name: 'dest', type: 'string' },
|
|
135
|
+
{
|
|
136
|
+
indexed: false,
|
|
137
|
+
internalType: 'string',
|
|
138
|
+
name: 'params',
|
|
139
|
+
type: 'string',
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
name: 'SignatureRequested',
|
|
143
|
+
type: 'event',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
anonymous: false,
|
|
147
|
+
inputs: [
|
|
148
|
+
{
|
|
149
|
+
indexed: true,
|
|
150
|
+
internalType: 'bytes32',
|
|
151
|
+
name: 'requestId',
|
|
152
|
+
type: 'bytes32',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
indexed: false,
|
|
156
|
+
internalType: 'address',
|
|
157
|
+
name: 'responder',
|
|
158
|
+
type: 'address',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
components: [
|
|
162
|
+
{
|
|
163
|
+
components: [
|
|
164
|
+
{ internalType: 'uint256', name: 'x', type: 'uint256' },
|
|
165
|
+
{ internalType: 'uint256', name: 'y', type: 'uint256' },
|
|
166
|
+
],
|
|
167
|
+
internalType: 'struct ChainSignatures.AffinePoint',
|
|
168
|
+
name: 'bigR',
|
|
169
|
+
type: 'tuple',
|
|
170
|
+
},
|
|
171
|
+
{ internalType: 'uint256', name: 's', type: 'uint256' },
|
|
172
|
+
{ internalType: 'uint8', name: 'recoveryId', type: 'uint8' },
|
|
173
|
+
],
|
|
174
|
+
indexed: false,
|
|
175
|
+
internalType: 'struct ChainSignatures.Signature',
|
|
176
|
+
name: 'signature',
|
|
177
|
+
type: 'tuple',
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
name: 'SignatureResponded',
|
|
181
|
+
type: 'event',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
anonymous: false,
|
|
185
|
+
inputs: [
|
|
186
|
+
{
|
|
187
|
+
indexed: true,
|
|
188
|
+
internalType: 'address',
|
|
189
|
+
name: 'owner',
|
|
190
|
+
type: 'address',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
indexed: false,
|
|
194
|
+
internalType: 'uint256',
|
|
195
|
+
name: 'amount',
|
|
196
|
+
type: 'uint256',
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
name: 'Withdraw',
|
|
200
|
+
type: 'event',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
inputs: [],
|
|
204
|
+
name: 'DEFAULT_ADMIN_ROLE',
|
|
205
|
+
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
|
206
|
+
stateMutability: 'view',
|
|
207
|
+
type: 'function',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
inputs: [{ internalType: 'bytes32', name: 'role', type: 'bytes32' }],
|
|
211
|
+
name: 'getRoleAdmin',
|
|
212
|
+
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
|
|
213
|
+
stateMutability: 'view',
|
|
214
|
+
type: 'function',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
inputs: [],
|
|
218
|
+
name: 'getSignatureDeposit',
|
|
219
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
220
|
+
stateMutability: 'view',
|
|
221
|
+
type: 'function',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
inputs: [
|
|
225
|
+
{ internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
226
|
+
{ internalType: 'address', name: 'account', type: 'address' },
|
|
227
|
+
],
|
|
228
|
+
name: 'grantRole',
|
|
229
|
+
outputs: [],
|
|
230
|
+
stateMutability: 'nonpayable',
|
|
231
|
+
type: 'function',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
inputs: [
|
|
235
|
+
{ internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
236
|
+
{ internalType: 'address', name: 'account', type: 'address' },
|
|
237
|
+
],
|
|
238
|
+
name: 'hasRole',
|
|
239
|
+
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
|
240
|
+
stateMutability: 'view',
|
|
241
|
+
type: 'function',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
inputs: [
|
|
245
|
+
{ internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
246
|
+
{ internalType: 'address', name: 'callerConfirmation', type: 'address' },
|
|
247
|
+
],
|
|
248
|
+
name: 'renounceRole',
|
|
249
|
+
outputs: [],
|
|
250
|
+
stateMutability: 'nonpayable',
|
|
251
|
+
type: 'function',
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
inputs: [
|
|
255
|
+
{
|
|
256
|
+
components: [
|
|
257
|
+
{ internalType: 'bytes32', name: 'requestId', type: 'bytes32' },
|
|
258
|
+
{
|
|
259
|
+
components: [
|
|
260
|
+
{
|
|
261
|
+
components: [
|
|
262
|
+
{ internalType: 'uint256', name: 'x', type: 'uint256' },
|
|
263
|
+
{ internalType: 'uint256', name: 'y', type: 'uint256' },
|
|
264
|
+
],
|
|
265
|
+
internalType: 'struct ChainSignatures.AffinePoint',
|
|
266
|
+
name: 'bigR',
|
|
267
|
+
type: 'tuple',
|
|
268
|
+
},
|
|
269
|
+
{ internalType: 'uint256', name: 's', type: 'uint256' },
|
|
270
|
+
{ internalType: 'uint8', name: 'recoveryId', type: 'uint8' },
|
|
271
|
+
],
|
|
272
|
+
internalType: 'struct ChainSignatures.Signature',
|
|
273
|
+
name: 'signature',
|
|
274
|
+
type: 'tuple',
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
internalType: 'struct ChainSignatures.Response[]',
|
|
278
|
+
name: '_responses',
|
|
279
|
+
type: 'tuple[]',
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
name: 'respond',
|
|
283
|
+
outputs: [],
|
|
284
|
+
stateMutability: 'nonpayable',
|
|
285
|
+
type: 'function',
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
inputs: [
|
|
289
|
+
{
|
|
290
|
+
components: [
|
|
291
|
+
{ internalType: 'bytes32', name: 'requestId', type: 'bytes32' },
|
|
292
|
+
{ internalType: 'string', name: 'errorMessage', type: 'string' },
|
|
293
|
+
],
|
|
294
|
+
internalType: 'struct ChainSignatures.ErrorResponse[]',
|
|
295
|
+
name: '_errors',
|
|
296
|
+
type: 'tuple[]',
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
name: 'respondError',
|
|
300
|
+
outputs: [],
|
|
301
|
+
stateMutability: 'nonpayable',
|
|
302
|
+
type: 'function',
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
inputs: [
|
|
306
|
+
{ internalType: 'bytes32', name: 'role', type: 'bytes32' },
|
|
307
|
+
{ internalType: 'address', name: 'account', type: 'address' },
|
|
308
|
+
],
|
|
309
|
+
name: 'revokeRole',
|
|
310
|
+
outputs: [],
|
|
311
|
+
stateMutability: 'nonpayable',
|
|
312
|
+
type: 'function',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
|
|
316
|
+
name: 'setSignatureDeposit',
|
|
317
|
+
outputs: [],
|
|
318
|
+
stateMutability: 'nonpayable',
|
|
319
|
+
type: 'function',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
inputs: [
|
|
323
|
+
{
|
|
324
|
+
components: [
|
|
325
|
+
{ internalType: 'bytes32', name: 'payload', type: 'bytes32' },
|
|
326
|
+
{ internalType: 'string', name: 'path', type: 'string' },
|
|
327
|
+
{ internalType: 'uint32', name: 'keyVersion', type: 'uint32' },
|
|
328
|
+
{ internalType: 'string', name: 'algo', type: 'string' },
|
|
329
|
+
{ internalType: 'string', name: 'dest', type: 'string' },
|
|
330
|
+
{ internalType: 'string', name: 'params', type: 'string' },
|
|
331
|
+
],
|
|
332
|
+
internalType: 'struct ChainSignatures.SignRequest',
|
|
333
|
+
name: '_request',
|
|
334
|
+
type: 'tuple',
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
name: 'sign',
|
|
338
|
+
outputs: [],
|
|
339
|
+
stateMutability: 'payable',
|
|
340
|
+
type: 'function',
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
inputs: [{ internalType: 'bytes4', name: 'interfaceId', type: 'bytes4' }],
|
|
344
|
+
name: 'supportsInterface',
|
|
345
|
+
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
|
346
|
+
stateMutability: 'view',
|
|
347
|
+
type: 'function',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
inputs: [
|
|
351
|
+
{ internalType: 'uint256', name: '_amount', type: 'uint256' },
|
|
352
|
+
{ internalType: 'address', name: '_receiver', type: 'address' },
|
|
353
|
+
],
|
|
354
|
+
name: 'withdraw',
|
|
355
|
+
outputs: [],
|
|
356
|
+
stateMutability: 'nonpayable',
|
|
357
|
+
type: 'function',
|
|
358
|
+
},
|
|
359
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TransactionReceipt } from 'viem'
|
|
2
|
+
|
|
3
|
+
export class ChainSignatureError extends Error {
|
|
4
|
+
requestId: `0x${string}`
|
|
5
|
+
receipt: TransactionReceipt
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
message: string,
|
|
9
|
+
requestId: `0x${string}`,
|
|
10
|
+
receipt: TransactionReceipt
|
|
11
|
+
) {
|
|
12
|
+
super(message)
|
|
13
|
+
this.name = 'ChainSignatureError'
|
|
14
|
+
this.requestId = requestId
|
|
15
|
+
this.receipt = receipt
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SignatureNotFoundError extends ChainSignatureError {
|
|
20
|
+
constructor(requestId: `0x${string}`, receipt: TransactionReceipt) {
|
|
21
|
+
super('Signature not found after maximum retries', requestId, receipt)
|
|
22
|
+
this.name = 'SignatureNotFoundError'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class SignatureContractError extends ChainSignatureError {
|
|
27
|
+
errorCode: string
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
errorCode: string,
|
|
31
|
+
requestId: `0x${string}`,
|
|
32
|
+
receipt: TransactionReceipt
|
|
33
|
+
) {
|
|
34
|
+
super(`Signature error: ${errorCode}`, requestId, receipt)
|
|
35
|
+
this.name = 'SignatureContractError'
|
|
36
|
+
this.errorCode = errorCode
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class SigningError extends ChainSignatureError {
|
|
41
|
+
originalError?: Error
|
|
42
|
+
|
|
43
|
+
constructor(
|
|
44
|
+
requestId: `0x${string}`,
|
|
45
|
+
receipt: TransactionReceipt,
|
|
46
|
+
originalError?: Error
|
|
47
|
+
) {
|
|
48
|
+
super('Error signing request', requestId, receipt)
|
|
49
|
+
this.name = 'SigningError'
|
|
50
|
+
this.originalError = originalError
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem'
|
|
2
|
+
|
|
3
|
+
export interface SignOptions {
|
|
4
|
+
sign: {
|
|
5
|
+
algo?: string
|
|
6
|
+
dest?: string
|
|
7
|
+
params?: string
|
|
8
|
+
}
|
|
9
|
+
retry: {
|
|
10
|
+
delay?: number
|
|
11
|
+
retryCount?: number
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SignatureErrorData {
|
|
16
|
+
requestId: string
|
|
17
|
+
responder: string
|
|
18
|
+
error: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SignRequest {
|
|
22
|
+
payload: Hex
|
|
23
|
+
path: string
|
|
24
|
+
keyVersion: number
|
|
25
|
+
algo: string
|
|
26
|
+
dest: string
|
|
27
|
+
params: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RequestIdArgs {
|
|
31
|
+
address: Address
|
|
32
|
+
payload: Hex
|
|
33
|
+
path: string
|
|
34
|
+
keyVersion: number
|
|
35
|
+
chainId: bigint
|
|
36
|
+
algo: string
|
|
37
|
+
dest: string
|
|
38
|
+
params: string
|
|
39
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256 } from 'viem'
|
|
2
|
+
import * as chains from 'viem/chains'
|
|
3
|
+
import type { Chain } from 'viem/chains'
|
|
4
|
+
|
|
5
|
+
import { type RequestIdArgs } from './types'
|
|
6
|
+
|
|
7
|
+
export const getChain = (chainId: number): Chain => {
|
|
8
|
+
for (const chain of Object.values(chains)) {
|
|
9
|
+
if (chain.id === chainId) {
|
|
10
|
+
return chain
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
throw new Error('Chain not found')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getRequestId = (request: RequestIdArgs): `0x${string}` => {
|
|
17
|
+
const encoded = encodeAbiParameters(
|
|
18
|
+
[
|
|
19
|
+
{ type: 'address' },
|
|
20
|
+
{ type: 'bytes' },
|
|
21
|
+
{ type: 'string' },
|
|
22
|
+
{ type: 'uint32' },
|
|
23
|
+
{ type: 'uint256' },
|
|
24
|
+
{ type: 'string' },
|
|
25
|
+
{ type: 'string' },
|
|
26
|
+
{ type: 'string' },
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
request.address,
|
|
30
|
+
request.payload,
|
|
31
|
+
request.path,
|
|
32
|
+
Number(request.keyVersion),
|
|
33
|
+
request.chainId,
|
|
34
|
+
request.algo,
|
|
35
|
+
request.dest,
|
|
36
|
+
request.params,
|
|
37
|
+
]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return keccak256(encoded)
|
|
41
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Contract } from '@near-js/accounts'
|
|
2
|
+
import { KeyPair } from '@near-js/crypto'
|
|
3
|
+
import { actionCreators } from '@near-js/transactions'
|
|
4
|
+
import { najToUncompressedPubKeySEC1 } from '@utils/cryptography'
|
|
5
|
+
import { getRootPublicKey } from '@utils/publicKey'
|
|
6
|
+
import BN from 'bn.js'
|
|
7
|
+
|
|
8
|
+
import { CHAINS, KDF_CHAIN_IDS } from '@constants'
|
|
9
|
+
import { ChainSignatureContract as AbstractChainSignatureContract } from '@contracts/ChainSignatureContract'
|
|
10
|
+
import type { SignArgs } from '@contracts/ChainSignatureContract'
|
|
11
|
+
import { getNearAccount } from '@contracts/near/account'
|
|
12
|
+
import { DONT_CARE_ACCOUNT_ID, NEAR_MAX_GAS } from '@contracts/near/constants'
|
|
13
|
+
import {
|
|
14
|
+
responseToMpcSignature,
|
|
15
|
+
type SendTransactionOptions,
|
|
16
|
+
sendTransactionUntil,
|
|
17
|
+
} from '@contracts/near/transaction'
|
|
18
|
+
import {
|
|
19
|
+
type NearNetworkIds,
|
|
20
|
+
type ChainSignatureContractIds,
|
|
21
|
+
} from '@contracts/near/types'
|
|
22
|
+
import type { RSVSignature, UncompressedPubKeySEC1, NajPublicKey } from '@types'
|
|
23
|
+
import { cryptography } from '@utils'
|
|
24
|
+
|
|
25
|
+
type NearContract = Contract & {
|
|
26
|
+
public_key: () => Promise<NajPublicKey>
|
|
27
|
+
experimental_signature_deposit: () => Promise<number>
|
|
28
|
+
derived_public_key: (args: {
|
|
29
|
+
path: string
|
|
30
|
+
predecessor: string
|
|
31
|
+
}) => Promise<NajPublicKey>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ChainSignatureContractArgs {
|
|
35
|
+
networkId: NearNetworkIds
|
|
36
|
+
contractId: ChainSignatureContractIds
|
|
37
|
+
accountId?: string
|
|
38
|
+
keypair?: KeyPair
|
|
39
|
+
rootPublicKey?: NajPublicKey
|
|
40
|
+
sendTransactionOptions?: SendTransactionOptions
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Implementation of the ChainSignatureContract for NEAR chains.
|
|
45
|
+
*
|
|
46
|
+
* This class provides an interface to interact with the ChainSignatures contract
|
|
47
|
+
* deployed on NEAR. It supports both view methods (which don't require authentication)
|
|
48
|
+
* and change methods (which require a valid NEAR account and keypair).
|
|
49
|
+
*
|
|
50
|
+
* @extends AbstractChainSignatureContract
|
|
51
|
+
*/
|
|
52
|
+
export class ChainSignatureContract extends AbstractChainSignatureContract {
|
|
53
|
+
private readonly networkId: NearNetworkIds
|
|
54
|
+
private readonly contractId: ChainSignatureContractIds
|
|
55
|
+
private readonly accountId: string
|
|
56
|
+
private readonly keypair: KeyPair
|
|
57
|
+
private readonly rootPublicKey?: NajPublicKey
|
|
58
|
+
private readonly sendTransactionOptions?: SendTransactionOptions
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new instance of the ChainSignatureContract for NEAR chains.
|
|
61
|
+
*
|
|
62
|
+
* @param args - Configuration options for the contract
|
|
63
|
+
* @param args.networkId - The NEAR network ID (e.g. 'testnet', 'mainnet')
|
|
64
|
+
* @param args.contractId - The contract ID of the deployed ChainSignatures contract
|
|
65
|
+
* @param args.accountId - Optional NEAR account ID for signing transactions. Required for change methods.
|
|
66
|
+
* @param args.keypair - Optional NEAR KeyPair for signing transactions. Required for change methods.
|
|
67
|
+
* @param args.rootPublicKey - Optional root public key for the contract. If not provided, it will be derived from the contract ID.
|
|
68
|
+
* @param args.sendTransactionOptions - Optional configuration for transaction sending behavior.
|
|
69
|
+
*/
|
|
70
|
+
constructor({
|
|
71
|
+
networkId,
|
|
72
|
+
contractId,
|
|
73
|
+
accountId = DONT_CARE_ACCOUNT_ID,
|
|
74
|
+
keypair = KeyPair.fromRandom('ed25519'),
|
|
75
|
+
rootPublicKey,
|
|
76
|
+
sendTransactionOptions,
|
|
77
|
+
}: ChainSignatureContractArgs) {
|
|
78
|
+
super()
|
|
79
|
+
|
|
80
|
+
this.networkId = networkId
|
|
81
|
+
this.contractId = contractId
|
|
82
|
+
this.accountId = accountId
|
|
83
|
+
this.keypair = keypair
|
|
84
|
+
this.sendTransactionOptions = sendTransactionOptions
|
|
85
|
+
|
|
86
|
+
this.rootPublicKey =
|
|
87
|
+
rootPublicKey || getRootPublicKey(this.contractId, CHAINS.NEAR)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private async getContract(): Promise<NearContract> {
|
|
91
|
+
const account = await getNearAccount({
|
|
92
|
+
networkId: this.networkId,
|
|
93
|
+
accountId: this.accountId,
|
|
94
|
+
keypair: this.keypair,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
return new Contract(account, this.contractId, {
|
|
98
|
+
viewMethods: [
|
|
99
|
+
'public_key',
|
|
100
|
+
'experimental_signature_deposit',
|
|
101
|
+
'derived_public_key',
|
|
102
|
+
],
|
|
103
|
+
// Change methods use the sendTransactionUntil because the internal retry of the Contract class
|
|
104
|
+
// throws on NodeJs.
|
|
105
|
+
changeMethods: [],
|
|
106
|
+
useLocalViewExecution: false,
|
|
107
|
+
}) as unknown as NearContract
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async getCurrentSignatureDeposit(): Promise<BN> {
|
|
111
|
+
const contract = await this.getContract()
|
|
112
|
+
return new BN(
|
|
113
|
+
(await contract.experimental_signature_deposit()).toLocaleString(
|
|
114
|
+
'fullwide',
|
|
115
|
+
{
|
|
116
|
+
useGrouping: false,
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getDerivedPublicKey(args: {
|
|
123
|
+
path: string
|
|
124
|
+
predecessor: string
|
|
125
|
+
}): Promise<UncompressedPubKeySEC1> {
|
|
126
|
+
if (this.rootPublicKey) {
|
|
127
|
+
const pubKey = cryptography.deriveChildPublicKey(
|
|
128
|
+
await this.getPublicKey(),
|
|
129
|
+
args.predecessor.toLowerCase(),
|
|
130
|
+
args.path,
|
|
131
|
+
KDF_CHAIN_IDS.NEAR
|
|
132
|
+
)
|
|
133
|
+
return pubKey
|
|
134
|
+
} else {
|
|
135
|
+
// Support for legacy contract
|
|
136
|
+
const contract = await this.getContract()
|
|
137
|
+
const najPubKey = await contract.derived_public_key(args)
|
|
138
|
+
return najToUncompressedPubKeySEC1(najPubKey)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async getPublicKey(): Promise<UncompressedPubKeySEC1> {
|
|
143
|
+
if (this.rootPublicKey) {
|
|
144
|
+
return najToUncompressedPubKeySEC1(this.rootPublicKey)
|
|
145
|
+
} else {
|
|
146
|
+
// Support for legacy contract
|
|
147
|
+
const contract = await this.getContract()
|
|
148
|
+
const najPubKey = await contract.public_key()
|
|
149
|
+
return najToUncompressedPubKeySEC1(najPubKey)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async sign(
|
|
154
|
+
args: SignArgs,
|
|
155
|
+
options?: {
|
|
156
|
+
nonce?: number
|
|
157
|
+
}
|
|
158
|
+
): Promise<RSVSignature> {
|
|
159
|
+
this.requireAccount()
|
|
160
|
+
|
|
161
|
+
const deposit = await this.getCurrentSignatureDeposit()
|
|
162
|
+
|
|
163
|
+
const result = await sendTransactionUntil({
|
|
164
|
+
accountId: this.accountId,
|
|
165
|
+
keypair: this.keypair,
|
|
166
|
+
networkId: this.networkId,
|
|
167
|
+
receiverId: this.contractId,
|
|
168
|
+
actions: [
|
|
169
|
+
actionCreators.functionCall(
|
|
170
|
+
'sign',
|
|
171
|
+
{ request: args },
|
|
172
|
+
BigInt(NEAR_MAX_GAS.toString()),
|
|
173
|
+
BigInt(deposit.toString())
|
|
174
|
+
),
|
|
175
|
+
],
|
|
176
|
+
nonce: options?.nonce,
|
|
177
|
+
options: this.sendTransactionOptions,
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
const signature = responseToMpcSignature({ response: result })
|
|
181
|
+
|
|
182
|
+
if (!signature) {
|
|
183
|
+
throw new Error('Transaction failed')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return signature
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private requireAccount(): void {
|
|
190
|
+
if (this.accountId === DONT_CARE_ACCOUNT_ID) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
'A valid account ID and keypair are required for change methods. Please instantiate a new contract with valid credentials.'
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|