ox 0.6.12 → 0.7.1
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/CHANGELOG.md +16 -0
- package/Keystore/package.json +6 -0
- package/_cjs/core/Keystore.js +127 -0
- package/_cjs/core/Keystore.js.map +1 -0
- package/_cjs/core/Provider.js +209 -1
- package/_cjs/core/Provider.js.map +1 -1
- package/_cjs/index.js +3 -2
- package/_cjs/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_cjs/version.js.map +1 -1
- package/_esm/core/Keystore.js +248 -0
- package/_esm/core/Keystore.js.map +1 -0
- package/_esm/core/Provider.js +208 -0
- package/_esm/core/Provider.js.map +1 -1
- package/_esm/index.js +47 -0
- package/_esm/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_esm/version.js.map +1 -1
- package/_types/core/Keystore.d.ts +267 -0
- package/_types/core/Keystore.d.ts.map +1 -0
- package/_types/core/Provider.d.ts +73 -1
- package/_types/core/Provider.d.ts.map +1 -1
- package/_types/core/internal/rpcSchemas/wallet.d.ts +23 -4
- package/_types/core/internal/rpcSchemas/wallet.d.ts.map +1 -1
- package/_types/index.d.ts +47 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/_types/version.d.ts.map +1 -1
- package/core/Keystore.ts +414 -0
- package/core/Provider.ts +168 -0
- package/core/internal/rpcSchemas/wallet.ts +28 -4
- package/index.ts +48 -0
- package/package.json +7 -1
- package/version.ts +1 -1
package/core/Keystore.ts
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { ctr } from '@noble/ciphers/aes'
|
|
2
|
+
import {
|
|
3
|
+
pbkdf2Async as pbkdf2Async_noble,
|
|
4
|
+
pbkdf2 as pbkdf2_noble,
|
|
5
|
+
} from '@noble/hashes/pbkdf2'
|
|
6
|
+
import {
|
|
7
|
+
scryptAsync as scryptAsync_noble,
|
|
8
|
+
scrypt as scrypt_noble,
|
|
9
|
+
} from '@noble/hashes/scrypt'
|
|
10
|
+
import { sha256 } from '@noble/hashes/sha2'
|
|
11
|
+
import * as Bytes from './Bytes.js'
|
|
12
|
+
import type * as Errors from './Errors.js'
|
|
13
|
+
import * as Hash from './Hash.js'
|
|
14
|
+
import type * as Hex from './Hex.js'
|
|
15
|
+
|
|
16
|
+
/** Base Key. */
|
|
17
|
+
type BaseKey<
|
|
18
|
+
kdf extends string = string,
|
|
19
|
+
kdfparams extends Record<string, unknown> = Record<string, unknown>,
|
|
20
|
+
> = {
|
|
21
|
+
iv: Bytes.Bytes
|
|
22
|
+
key: () => string
|
|
23
|
+
kdfparams: kdfparams
|
|
24
|
+
kdf: kdf
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Keystore. */
|
|
28
|
+
export type Keystore = {
|
|
29
|
+
crypto: {
|
|
30
|
+
cipher: 'aes-128-ctr'
|
|
31
|
+
ciphertext: string
|
|
32
|
+
cipherparams: {
|
|
33
|
+
iv: string
|
|
34
|
+
}
|
|
35
|
+
mac: string
|
|
36
|
+
} & Pick<Key, 'kdf' | 'kdfparams'>
|
|
37
|
+
id: string
|
|
38
|
+
version: 3
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Key. */
|
|
42
|
+
export type Key = Pbkdf2Key | ScryptKey
|
|
43
|
+
|
|
44
|
+
/** PBKDF2 Key. */
|
|
45
|
+
export type Pbkdf2Key = BaseKey<
|
|
46
|
+
'pbkdf2',
|
|
47
|
+
{
|
|
48
|
+
c: number
|
|
49
|
+
dklen: number
|
|
50
|
+
prf: 'hmac-sha256'
|
|
51
|
+
salt: string
|
|
52
|
+
}
|
|
53
|
+
>
|
|
54
|
+
|
|
55
|
+
/** Scrypt Key. */
|
|
56
|
+
export type ScryptKey = BaseKey<
|
|
57
|
+
'scrypt',
|
|
58
|
+
{
|
|
59
|
+
dklen: number
|
|
60
|
+
n: number
|
|
61
|
+
p: number
|
|
62
|
+
r: number
|
|
63
|
+
salt: string
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decrypts a [JSON keystore](https://ethereum.org/en/developers/docs/data-structures-and-encoding/web3-secret-storage/)
|
|
69
|
+
* into a private key.
|
|
70
|
+
*
|
|
71
|
+
* Supports the following key derivation functions (KDFs):
|
|
72
|
+
* - {@link ox#Keystore.(pbkdf2:function)}
|
|
73
|
+
* - {@link ox#Keystore.(scrypt:function)}
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts twoslash
|
|
77
|
+
* // @noErrors
|
|
78
|
+
* import { Keystore, Secp256k1 } from 'ox'
|
|
79
|
+
*
|
|
80
|
+
* // JSON keystore.
|
|
81
|
+
* const keystore = { crypto: { ... }, id: '...', version: 3 }
|
|
82
|
+
*
|
|
83
|
+
* // Derive key from password.
|
|
84
|
+
* const key = Keystore.pbkdf2({ password: 'testpassword' })
|
|
85
|
+
*
|
|
86
|
+
* // Decrypt the private key.
|
|
87
|
+
* const privateKey = await Keystore.decrypt(keystore, key)
|
|
88
|
+
* // @log: "0x..."
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param keystore - JSON keystore.
|
|
92
|
+
* @param key - Key to use for decryption.
|
|
93
|
+
* @param options - Decryption options.
|
|
94
|
+
* @returns Decrypted private key.
|
|
95
|
+
*/
|
|
96
|
+
export async function decrypt<as extends 'Hex' | 'Bytes' = 'Hex'>(
|
|
97
|
+
keystore: Keystore,
|
|
98
|
+
key: Key,
|
|
99
|
+
options: decrypt.Options<as> = {},
|
|
100
|
+
): Promise<decrypt.ReturnType<as>> {
|
|
101
|
+
const { as = 'Hex' } = options
|
|
102
|
+
const key_ = Bytes.from(`0x${key.key()}`)
|
|
103
|
+
|
|
104
|
+
const encKey = Bytes.slice(key_, 0, 16)
|
|
105
|
+
const macKey = Bytes.slice(key_, 16, 32)
|
|
106
|
+
|
|
107
|
+
const ciphertext = Bytes.from(`0x${keystore.crypto.ciphertext}`)
|
|
108
|
+
const mac = Hash.keccak256(Bytes.concat(macKey, ciphertext))
|
|
109
|
+
|
|
110
|
+
if (!Bytes.isEqual(mac, Bytes.from(`0x${keystore.crypto.mac}`)))
|
|
111
|
+
throw new Error('corrupt keystore')
|
|
112
|
+
|
|
113
|
+
const data = ctr(encKey, key.iv).decrypt(ciphertext)
|
|
114
|
+
|
|
115
|
+
if (as === 'Hex') return Bytes.toHex(data) as never
|
|
116
|
+
return data as never
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare namespace decrypt {
|
|
120
|
+
type Options<as extends 'Hex' | 'Bytes' = 'Hex' | 'Bytes'> = {
|
|
121
|
+
/** Output format. @default 'Hex' */
|
|
122
|
+
as?: as | 'Hex' | 'Bytes' | undefined
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
type ReturnType<as extends 'Hex' | 'Bytes' = 'Hex' | 'Bytes'> =
|
|
126
|
+
| (as extends 'Hex' ? Hex.Hex : never)
|
|
127
|
+
| (as extends 'Bytes' ? Bytes.Bytes : never)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Encrypts a private key as a [JSON keystore](https://ethereum.org/en/developers/docs/data-structures-and-encoding/web3-secret-storage/)
|
|
132
|
+
* using a derived key.
|
|
133
|
+
*
|
|
134
|
+
* Supports the following key derivation functions (KDFs):
|
|
135
|
+
* - {@link ox#Keystore.(pbkdf2:function)}
|
|
136
|
+
* - {@link ox#Keystore.(scrypt:function)}
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts twoslash
|
|
140
|
+
* import { Keystore, Secp256k1 } from 'ox'
|
|
141
|
+
*
|
|
142
|
+
* // Generate a random private key.
|
|
143
|
+
* const privateKey = Secp256k1.randomPrivateKey()
|
|
144
|
+
*
|
|
145
|
+
* // Derive key from password.
|
|
146
|
+
* const key = Keystore.pbkdf2({ password: 'testpassword' })
|
|
147
|
+
*
|
|
148
|
+
* // Encrypt the private key.
|
|
149
|
+
* const encrypted = await Keystore.encrypt(privateKey, key)
|
|
150
|
+
* // @log: {
|
|
151
|
+
* // @log: "crypto": {
|
|
152
|
+
* // @log: "cipher": "aes-128-ctr",
|
|
153
|
+
* // @log: "ciphertext": "...",
|
|
154
|
+
* // @log: "cipherparams": {
|
|
155
|
+
* // @log: "iv": "...",
|
|
156
|
+
* // @log: },
|
|
157
|
+
* // @log: "kdf": "pbkdf2",
|
|
158
|
+
* // @log: "kdfparams": {
|
|
159
|
+
* // @log: "salt": "...",
|
|
160
|
+
* // @log: "dklen": 32,
|
|
161
|
+
* // @log: "prf": "hmac-sha256",
|
|
162
|
+
* // @log: "c": 262144,
|
|
163
|
+
* // @log: },
|
|
164
|
+
* // @log: "mac": "...",
|
|
165
|
+
* // @log: },
|
|
166
|
+
* // @log: "id": "...",
|
|
167
|
+
* // @log: "version": 3,
|
|
168
|
+
* // @log: }
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @param privateKey - Private key to encrypt.
|
|
172
|
+
* @param key - Key to use for encryption.
|
|
173
|
+
* @param options - Encryption options.
|
|
174
|
+
* @returns Encrypted keystore.
|
|
175
|
+
*/
|
|
176
|
+
export async function encrypt(
|
|
177
|
+
privateKey: Bytes.Bytes | Hex.Hex,
|
|
178
|
+
key: Key,
|
|
179
|
+
options: encrypt.Options = {},
|
|
180
|
+
): Promise<Keystore> {
|
|
181
|
+
const { id = crypto.randomUUID() } = options
|
|
182
|
+
|
|
183
|
+
const key_ = Bytes.from(`0x${key.key()}`)
|
|
184
|
+
const value_ = Bytes.from(privateKey)
|
|
185
|
+
|
|
186
|
+
const encKey = Bytes.slice(key_, 0, 16)
|
|
187
|
+
const macKey = Bytes.slice(key_, 16, 32)
|
|
188
|
+
|
|
189
|
+
const ciphertext = ctr(encKey, key.iv).encrypt(value_)
|
|
190
|
+
const mac = Hash.keccak256(Bytes.concat(macKey, ciphertext))
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
crypto: {
|
|
194
|
+
cipher: 'aes-128-ctr',
|
|
195
|
+
ciphertext: Bytes.toHex(ciphertext).slice(2),
|
|
196
|
+
cipherparams: { iv: Bytes.toHex(key.iv).slice(2) },
|
|
197
|
+
kdf: key.kdf,
|
|
198
|
+
kdfparams: key.kdfparams,
|
|
199
|
+
mac: Bytes.toHex(mac).slice(2),
|
|
200
|
+
} as Keystore['crypto'],
|
|
201
|
+
id,
|
|
202
|
+
version: 3,
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export declare namespace encrypt {
|
|
207
|
+
type Options = {
|
|
208
|
+
/** UUID. */
|
|
209
|
+
id?: string | undefined
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Derives a key from a password using [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2).
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts twoslash
|
|
218
|
+
* import { Keystore } from 'ox'
|
|
219
|
+
*
|
|
220
|
+
* const key = Keystore.pbkdf2({ password: 'testpassword' })
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @param options - PBKDF2 options.
|
|
224
|
+
* @returns PBKDF2 key.
|
|
225
|
+
*/
|
|
226
|
+
export function pbkdf2(options: pbkdf2.Options) {
|
|
227
|
+
const { iv, iterations = 262_144, password } = options
|
|
228
|
+
|
|
229
|
+
const salt = options.salt ? Bytes.from(options.salt) : Bytes.random(32)
|
|
230
|
+
const key = Bytes.toHex(
|
|
231
|
+
pbkdf2_noble(sha256, password, salt, { c: iterations, dkLen: 32 }),
|
|
232
|
+
).slice(2)
|
|
233
|
+
|
|
234
|
+
return defineKey({
|
|
235
|
+
iv,
|
|
236
|
+
key: () => key,
|
|
237
|
+
kdfparams: {
|
|
238
|
+
c: iterations,
|
|
239
|
+
dklen: 32,
|
|
240
|
+
prf: 'hmac-sha256',
|
|
241
|
+
salt: Bytes.toHex(salt).slice(2),
|
|
242
|
+
},
|
|
243
|
+
kdf: 'pbkdf2',
|
|
244
|
+
}) satisfies Pbkdf2Key
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export declare namespace pbkdf2 {
|
|
248
|
+
type Options = {
|
|
249
|
+
/** The counter to use for the AES-CTR encryption. */
|
|
250
|
+
iv?: Bytes.Bytes | Hex.Hex | undefined
|
|
251
|
+
/** The number of iterations to use. @default 262_144 */
|
|
252
|
+
iterations?: number | undefined
|
|
253
|
+
/** Password to derive key from. */
|
|
254
|
+
password: string
|
|
255
|
+
/** Salt to use for key derivation. @default `Bytes.random(32)` */
|
|
256
|
+
salt?: Bytes.Bytes | Hex.Hex | undefined
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Derives a key from a password using [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2).
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts twoslash
|
|
265
|
+
* import { Keystore } from 'ox'
|
|
266
|
+
*
|
|
267
|
+
* const key = await Keystore.pbkdf2Async({ password: 'testpassword' })
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @param options - PBKDF2 options.
|
|
271
|
+
* @returns PBKDF2 key.
|
|
272
|
+
*/
|
|
273
|
+
export async function pbkdf2Async(options: pbkdf2.Options) {
|
|
274
|
+
const { iv, iterations = 262_144, password } = options
|
|
275
|
+
|
|
276
|
+
const salt = options.salt ? Bytes.from(options.salt) : Bytes.random(32)
|
|
277
|
+
const key = Bytes.toHex(
|
|
278
|
+
await pbkdf2Async_noble(sha256, password, salt, {
|
|
279
|
+
c: iterations,
|
|
280
|
+
dkLen: 32,
|
|
281
|
+
}),
|
|
282
|
+
).slice(2)
|
|
283
|
+
|
|
284
|
+
return defineKey({
|
|
285
|
+
iv,
|
|
286
|
+
key: () => key,
|
|
287
|
+
kdfparams: {
|
|
288
|
+
c: iterations,
|
|
289
|
+
dklen: 32,
|
|
290
|
+
prf: 'hmac-sha256',
|
|
291
|
+
salt: Bytes.toHex(salt).slice(2),
|
|
292
|
+
},
|
|
293
|
+
kdf: 'pbkdf2',
|
|
294
|
+
}) satisfies Pbkdf2Key
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export declare namespace pbkdf2Async {
|
|
298
|
+
type Options = pbkdf2.Options
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Derives a key from a password using [scrypt](https://en.wikipedia.org/wiki/Scrypt).
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts twoslash
|
|
306
|
+
* import { Keystore } from 'ox'
|
|
307
|
+
*
|
|
308
|
+
* const key = Keystore.scrypt({ password: 'testpassword' })
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @param options - Scrypt options.
|
|
312
|
+
* @returns Scrypt key.
|
|
313
|
+
*/
|
|
314
|
+
export function scrypt(options: scrypt.Options) {
|
|
315
|
+
const { iv, n = 262_144, password } = options
|
|
316
|
+
|
|
317
|
+
const p = 8
|
|
318
|
+
const r = 1
|
|
319
|
+
|
|
320
|
+
const salt = options.salt ? Bytes.from(options.salt) : Bytes.random(32)
|
|
321
|
+
const key = Bytes.toHex(
|
|
322
|
+
scrypt_noble(password, salt, { N: n, dkLen: 32, r, p }),
|
|
323
|
+
).slice(2)
|
|
324
|
+
|
|
325
|
+
return defineKey({
|
|
326
|
+
iv,
|
|
327
|
+
key: () => key,
|
|
328
|
+
kdfparams: {
|
|
329
|
+
dklen: 32,
|
|
330
|
+
n,
|
|
331
|
+
p,
|
|
332
|
+
r,
|
|
333
|
+
salt: Bytes.toHex(salt).slice(2),
|
|
334
|
+
},
|
|
335
|
+
kdf: 'scrypt',
|
|
336
|
+
}) satisfies ScryptKey
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export declare namespace scrypt {
|
|
340
|
+
type Options = {
|
|
341
|
+
/** The counter to use for the AES-CTR encryption. */
|
|
342
|
+
iv?: Bytes.Bytes | Hex.Hex | undefined
|
|
343
|
+
/** Cost factor. @default 262_144 */
|
|
344
|
+
n?: number | undefined
|
|
345
|
+
/** Password to derive key from. */
|
|
346
|
+
password: string
|
|
347
|
+
/** Salt to use for key derivation. @default `Bytes.random(32)` */
|
|
348
|
+
salt?: Bytes.Bytes | Hex.Hex | undefined
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Derives a key from a password using [scrypt](https://en.wikipedia.org/wiki/Scrypt).
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts twoslash
|
|
357
|
+
* import { Keystore } from 'ox'
|
|
358
|
+
*
|
|
359
|
+
* const key = await Keystore.scryptAsync({ password: 'testpassword' })
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* @param options - Scrypt options.
|
|
363
|
+
* @returns Scrypt key.
|
|
364
|
+
*/
|
|
365
|
+
export async function scryptAsync(options: scrypt.Options) {
|
|
366
|
+
const { iv, n = 262_144, password } = options
|
|
367
|
+
|
|
368
|
+
const p = 8
|
|
369
|
+
const r = 1
|
|
370
|
+
|
|
371
|
+
const salt = options.salt ? Bytes.from(options.salt) : Bytes.random(32)
|
|
372
|
+
const key = Bytes.toHex(
|
|
373
|
+
await scryptAsync_noble(password, salt, { N: n, dkLen: 32, r, p }),
|
|
374
|
+
).slice(2)
|
|
375
|
+
|
|
376
|
+
return defineKey({
|
|
377
|
+
iv,
|
|
378
|
+
key: () => key,
|
|
379
|
+
kdfparams: {
|
|
380
|
+
dklen: 32,
|
|
381
|
+
n,
|
|
382
|
+
p,
|
|
383
|
+
r,
|
|
384
|
+
salt: Bytes.toHex(salt).slice(2),
|
|
385
|
+
},
|
|
386
|
+
kdf: 'scrypt',
|
|
387
|
+
}) satisfies ScryptKey
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export declare namespace scryptAsync {
|
|
391
|
+
type Options = scrypt.Options
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
///////////////////////////////////////////////////////////////////////////
|
|
395
|
+
|
|
396
|
+
/** @internal */
|
|
397
|
+
function defineKey<const key extends defineKey.Value>(
|
|
398
|
+
key: key,
|
|
399
|
+
): key & { iv: Bytes.Bytes } {
|
|
400
|
+
const iv = key.iv ? Bytes.from(key.iv) : Bytes.random(16)
|
|
401
|
+
return { ...key, iv }
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** @internal */
|
|
405
|
+
declare namespace defineKey {
|
|
406
|
+
type Value<
|
|
407
|
+
kdf extends string = string,
|
|
408
|
+
kdfparams extends Record<string, unknown> = Record<string, unknown>,
|
|
409
|
+
> = Omit<BaseKey<kdf, kdfparams>, 'iv'> & {
|
|
410
|
+
iv?: Bytes.Bytes | Hex.Hex | undefined
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
type ErrorType = Errors.GlobalErrorType
|
|
414
|
+
}
|
package/core/Provider.ts
CHANGED
|
@@ -154,6 +154,110 @@ export class ChainDisconnectedError extends ProviderRpcError {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/** An error occurred when attempting to switch chain. */
|
|
158
|
+
export class SwitchChainError extends ProviderRpcError {
|
|
159
|
+
static readonly code = 4902
|
|
160
|
+
override readonly code = 4902
|
|
161
|
+
override readonly name = 'Provider.SwitchChainError'
|
|
162
|
+
|
|
163
|
+
constructor({
|
|
164
|
+
message = 'An error occurred when attempting to switch chain.',
|
|
165
|
+
}: { message?: string | undefined } = {}) {
|
|
166
|
+
super(4902, message)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** This Wallet does not support a capability that was not marked as optional. */
|
|
171
|
+
export class UnsupportedNonOptionalCapabilityError extends ProviderRpcError {
|
|
172
|
+
static readonly code = 5700
|
|
173
|
+
override readonly code = 5700
|
|
174
|
+
override readonly name = 'Provider.UnsupportedNonOptionalCapabilityError'
|
|
175
|
+
|
|
176
|
+
constructor({
|
|
177
|
+
message = 'This Wallet does not support a capability that was not marked as optional.',
|
|
178
|
+
}: { message?: string | undefined } = {}) {
|
|
179
|
+
super(5700, message)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** This Wallet does not support the requested chain ID. */
|
|
184
|
+
export class UnsupportedChainIdError extends ProviderRpcError {
|
|
185
|
+
static readonly code = 5710
|
|
186
|
+
override readonly code = 5710
|
|
187
|
+
override readonly name = 'Provider.UnsupportedChainIdError'
|
|
188
|
+
|
|
189
|
+
constructor({
|
|
190
|
+
message = 'This Wallet does not support the requested chain ID.',
|
|
191
|
+
}: { message?: string | undefined } = {}) {
|
|
192
|
+
super(5710, message)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** There is already a bundle submitted with this ID. */
|
|
197
|
+
export class DuplicateIdError extends ProviderRpcError {
|
|
198
|
+
static readonly code = 5720
|
|
199
|
+
override readonly code = 5720
|
|
200
|
+
override readonly name = 'Provider.DuplicateIdError'
|
|
201
|
+
|
|
202
|
+
constructor({
|
|
203
|
+
message = 'There is already a bundle submitted with this ID.',
|
|
204
|
+
}: { message?: string | undefined } = {}) {
|
|
205
|
+
super(5720, message)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** This bundle id is unknown / has not been submitted. */
|
|
210
|
+
export class UnknownBundleIdError extends ProviderRpcError {
|
|
211
|
+
static readonly code = 5730
|
|
212
|
+
override readonly code = 5730
|
|
213
|
+
override readonly name = 'Provider.UnknownBundleIdError'
|
|
214
|
+
|
|
215
|
+
constructor({
|
|
216
|
+
message = 'This bundle id is unknown / has not been submitted.',
|
|
217
|
+
}: { message?: string | undefined } = {}) {
|
|
218
|
+
super(5730, message)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The call bundle is too large for the Wallet to process. */
|
|
223
|
+
export class BundleTooLargeError extends ProviderRpcError {
|
|
224
|
+
static readonly code = 5740
|
|
225
|
+
override readonly code = 5740
|
|
226
|
+
override readonly name = 'Provider.BundleTooLargeError'
|
|
227
|
+
|
|
228
|
+
constructor({
|
|
229
|
+
message = 'The call bundle is too large for the Wallet to process.',
|
|
230
|
+
}: { message?: string | undefined } = {}) {
|
|
231
|
+
super(5740, message)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The Wallet can support atomicity after an upgrade, but the user rejected the upgrade. */
|
|
236
|
+
export class AtomicReadyWalletRejectedUpgradeError extends ProviderRpcError {
|
|
237
|
+
static readonly code = 5750
|
|
238
|
+
override readonly code = 5750
|
|
239
|
+
override readonly name = 'Provider.AtomicReadyWalletRejectedUpgradeError'
|
|
240
|
+
|
|
241
|
+
constructor({
|
|
242
|
+
message = 'The Wallet can support atomicity after an upgrade, but the user rejected the upgrade.',
|
|
243
|
+
}: { message?: string | undefined } = {}) {
|
|
244
|
+
super(5750, message)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The wallet does not support atomic execution but the request requires it. */
|
|
249
|
+
export class AtomicityNotSupportedError extends ProviderRpcError {
|
|
250
|
+
static readonly code = 5760
|
|
251
|
+
override readonly code = 5760
|
|
252
|
+
override readonly name = 'Provider.AtomicityNotSupportedError'
|
|
253
|
+
|
|
254
|
+
constructor({
|
|
255
|
+
message = 'The wallet does not support atomic execution but the request requires it.',
|
|
256
|
+
}: { message?: string | undefined } = {}) {
|
|
257
|
+
super(5760, message)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
157
261
|
/**
|
|
158
262
|
* Creates an EIP-1193 flavored event emitter to be injected onto a Provider.
|
|
159
263
|
*
|
|
@@ -447,6 +551,22 @@ export function parseError<
|
|
|
447
551
|
return new UnauthorizedError(error_) as never
|
|
448
552
|
if (code === UnsupportedMethodError.code)
|
|
449
553
|
return new UnsupportedMethodError(error_) as never
|
|
554
|
+
if (code === SwitchChainError.code)
|
|
555
|
+
return new SwitchChainError(error_) as never
|
|
556
|
+
if (code === AtomicReadyWalletRejectedUpgradeError.code)
|
|
557
|
+
return new AtomicReadyWalletRejectedUpgradeError(error_) as never
|
|
558
|
+
if (code === AtomicityNotSupportedError.code)
|
|
559
|
+
return new AtomicityNotSupportedError(error_) as never
|
|
560
|
+
if (code === BundleTooLargeError.code)
|
|
561
|
+
return new BundleTooLargeError(error_) as never
|
|
562
|
+
if (code === UnknownBundleIdError.code)
|
|
563
|
+
return new UnknownBundleIdError(error_) as never
|
|
564
|
+
if (code === DuplicateIdError.code)
|
|
565
|
+
return new DuplicateIdError(error_) as never
|
|
566
|
+
if (code === UnsupportedChainIdError.code)
|
|
567
|
+
return new UnsupportedChainIdError(error_) as never
|
|
568
|
+
if (code === UnsupportedNonOptionalCapabilityError.code)
|
|
569
|
+
return new UnsupportedNonOptionalCapabilityError(error_) as never
|
|
450
570
|
}
|
|
451
571
|
return error_ as never
|
|
452
572
|
}
|
|
@@ -487,6 +607,54 @@ export declare namespace parseError {
|
|
|
487
607
|
| (IsNarrowable<errorObject['code'], number> extends false
|
|
488
608
|
? UnsupportedMethodError
|
|
489
609
|
: never)
|
|
610
|
+
| (errorObject['code'] extends SwitchChainError['code']
|
|
611
|
+
? SwitchChainError
|
|
612
|
+
: never)
|
|
613
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
614
|
+
? SwitchChainError
|
|
615
|
+
: never)
|
|
616
|
+
| (errorObject['code'] extends AtomicReadyWalletRejectedUpgradeError['code']
|
|
617
|
+
? AtomicReadyWalletRejectedUpgradeError
|
|
618
|
+
: never)
|
|
619
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
620
|
+
? AtomicReadyWalletRejectedUpgradeError
|
|
621
|
+
: never)
|
|
622
|
+
| (errorObject['code'] extends AtomicityNotSupportedError['code']
|
|
623
|
+
? AtomicityNotSupportedError
|
|
624
|
+
: never)
|
|
625
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
626
|
+
? AtomicityNotSupportedError
|
|
627
|
+
: never)
|
|
628
|
+
| (errorObject['code'] extends BundleTooLargeError['code']
|
|
629
|
+
? BundleTooLargeError
|
|
630
|
+
: never)
|
|
631
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
632
|
+
? BundleTooLargeError
|
|
633
|
+
: never)
|
|
634
|
+
| (errorObject['code'] extends UnknownBundleIdError['code']
|
|
635
|
+
? UnknownBundleIdError
|
|
636
|
+
: never)
|
|
637
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
638
|
+
? UnknownBundleIdError
|
|
639
|
+
: never)
|
|
640
|
+
| (errorObject['code'] extends DuplicateIdError['code']
|
|
641
|
+
? DuplicateIdError
|
|
642
|
+
: never)
|
|
643
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
644
|
+
? DuplicateIdError
|
|
645
|
+
: never)
|
|
646
|
+
| (errorObject['code'] extends UnsupportedChainIdError['code']
|
|
647
|
+
? UnsupportedChainIdError
|
|
648
|
+
: never)
|
|
649
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
650
|
+
? UnsupportedChainIdError
|
|
651
|
+
: never)
|
|
652
|
+
| (errorObject['code'] extends UnsupportedNonOptionalCapabilityError['code']
|
|
653
|
+
? UnsupportedNonOptionalCapabilityError
|
|
654
|
+
: never)
|
|
655
|
+
| (IsNarrowable<errorObject['code'], number> extends false
|
|
656
|
+
? UnsupportedNonOptionalCapabilityError
|
|
657
|
+
: never)
|
|
490
658
|
: RpcResponse.parseError.ReturnType<RpcResponse.ErrorObject>,
|
|
491
659
|
> = IsNever<error> extends true
|
|
492
660
|
? RpcResponse.parseError.ReturnType<errorObject>
|
|
@@ -157,7 +157,14 @@ export type Wallet = RpcSchema.From<
|
|
|
157
157
|
| {
|
|
158
158
|
Request: {
|
|
159
159
|
method: 'wallet_getCapabilities'
|
|
160
|
-
params?:
|
|
160
|
+
params?:
|
|
161
|
+
| readonly []
|
|
162
|
+
| readonly [Address.Address | undefined]
|
|
163
|
+
| readonly [
|
|
164
|
+
Address.Address | undefined,
|
|
165
|
+
readonly Hex.Hex[] | undefined,
|
|
166
|
+
]
|
|
167
|
+
| undefined
|
|
161
168
|
}
|
|
162
169
|
ReturnType: Compute<WalletCapabilitiesMap>
|
|
163
170
|
}
|
|
@@ -219,7 +226,7 @@ export type Wallet = RpcSchema.From<
|
|
|
219
226
|
method: 'wallet_sendCalls'
|
|
220
227
|
params: Compute<WalletSendCallsParameters>
|
|
221
228
|
}
|
|
222
|
-
ReturnType:
|
|
229
|
+
ReturnType: WalletSendCallsReturnType
|
|
223
230
|
}
|
|
224
231
|
/**
|
|
225
232
|
* Requests for the wallet to show information about a call batch
|
|
@@ -303,7 +310,10 @@ type WalletCapabilitiesMap = {
|
|
|
303
310
|
* @internal
|
|
304
311
|
*/
|
|
305
312
|
type WalletGetCallsStatusReturnType = {
|
|
306
|
-
|
|
313
|
+
atomic: boolean
|
|
314
|
+
capabilities?: WalletCapabilities | undefined
|
|
315
|
+
chainId: Hex.Hex
|
|
316
|
+
id: string
|
|
307
317
|
receipts?:
|
|
308
318
|
| readonly {
|
|
309
319
|
logs: {
|
|
@@ -318,6 +328,8 @@ type WalletGetCallsStatusReturnType = {
|
|
|
318
328
|
transactionHash: Hex.Hex
|
|
319
329
|
}[]
|
|
320
330
|
| undefined
|
|
331
|
+
status: number
|
|
332
|
+
version: string
|
|
321
333
|
}
|
|
322
334
|
|
|
323
335
|
/**
|
|
@@ -396,18 +408,30 @@ type WalletGrantPermissionsReturnType = {
|
|
|
396
408
|
*/
|
|
397
409
|
type WalletSendCallsParameters = [
|
|
398
410
|
{
|
|
411
|
+
atomicRequired: boolean
|
|
399
412
|
calls: readonly {
|
|
413
|
+
capabilities?: WalletCapabilities | undefined
|
|
400
414
|
to?: Address.Address | undefined
|
|
401
415
|
data?: Hex.Hex | undefined
|
|
402
416
|
value?: Hex.Hex | undefined
|
|
403
417
|
}[]
|
|
404
418
|
capabilities?: WalletCapabilities | undefined
|
|
405
419
|
chainId?: Hex.Hex | undefined
|
|
406
|
-
|
|
420
|
+
id?: string | undefined
|
|
421
|
+
from?: Address.Address | undefined
|
|
407
422
|
version: string
|
|
408
423
|
},
|
|
409
424
|
]
|
|
410
425
|
|
|
426
|
+
/**
|
|
427
|
+
* Return type for `wallet_sendCalls`. [See more](https://eips.ethereum.org/EIPS/eip-5792#wallet_sendcalls).
|
|
428
|
+
* @internal
|
|
429
|
+
*/
|
|
430
|
+
type WalletSendCallsReturnType = {
|
|
431
|
+
capabilities?: WalletCapabilities | undefined
|
|
432
|
+
id: string
|
|
433
|
+
}
|
|
434
|
+
|
|
411
435
|
/**
|
|
412
436
|
* Parameters for `wallet_watchAsset`. [See more](https://eips.ethereum.org/EIPS/eip-747).
|
|
413
437
|
* @internal
|