rise-wallet 0.3.0 → 0.3.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/dist/cli/bin/commands-DupUUwJ9.js +50 -0
- package/dist/cli/bin/index.js +1 -1
- package/dist/core/Dialog.d.ts.map +1 -1
- package/dist/core/Dialog.js +8 -0
- package/dist/core/Dialog.js.map +1 -1
- package/dist/core/Porto.d.ts +187 -10
- package/dist/core/Porto.d.ts.map +1 -1
- package/dist/core/internal/mode.d.ts +4 -0
- package/dist/core/internal/mode.d.ts.map +1 -1
- package/dist/core/internal/mode.js.map +1 -1
- package/dist/core/internal/modes/dialog.d.ts +47 -7
- package/dist/core/internal/modes/dialog.d.ts.map +1 -1
- package/dist/core/internal/modes/reactNative.d.ts +187 -10
- package/dist/core/internal/modes/reactNative.d.ts.map +1 -1
- package/dist/core/internal/modes/relay.d.ts +140 -3
- package/dist/core/internal/modes/relay.d.ts.map +1 -1
- package/dist/core/internal/modes/relay.js +102 -26
- package/dist/core/internal/modes/relay.js.map +1 -1
- package/dist/core/internal/permissions.d.ts +1 -1
- package/dist/core/internal/permissionsRequest.d.ts +1 -1
- package/dist/core/internal/provider.d.ts.map +1 -1
- package/dist/core/internal/provider.js +12 -1
- package/dist/core/internal/provider.js.map +1 -1
- package/dist/core/internal/relay/rpcSchema.d.ts +3 -0
- package/dist/core/internal/relay/rpcSchema.d.ts.map +1 -1
- package/dist/core/internal/relay/schema/rpc.d.ts +23 -0
- package/dist/core/internal/relay/schema/rpc.d.ts.map +1 -1
- package/dist/core/internal/relay/schema/rpc.js +18 -0
- package/dist/core/internal/relay/schema/rpc.js.map +1 -1
- package/dist/core/internal/schema/capabilities.d.ts +2 -2
- package/dist/core/internal/schema/key.d.ts +2 -2
- package/dist/core/internal/schema/key.d.ts.map +1 -1
- package/dist/core/internal/schema/key.js +1 -0
- package/dist/core/internal/schema/key.js.map +1 -1
- package/dist/core/internal/schema/permissions.d.ts +2 -2
- package/dist/core/internal/schema/request.d.ts +18 -16
- package/dist/core/internal/schema/request.d.ts.map +1 -1
- package/dist/core/internal/schema/rpc.d.ts +52 -46
- package/dist/core/internal/schema/rpc.d.ts.map +1 -1
- package/dist/core/internal/schema/rpc.js +1 -0
- package/dist/core/internal/schema/rpc.js.map +1 -1
- package/dist/core/react-native/Porto.d.ts +187 -10
- package/dist/core/react-native/Porto.d.ts.map +1 -1
- package/dist/remote/Events.d.ts.map +1 -1
- package/dist/remote/Events.js +5 -1
- package/dist/remote/Events.js.map +1 -1
- package/dist/remote/Hooks.d.ts +42 -38
- package/dist/remote/Hooks.d.ts.map +1 -1
- package/dist/remote/Porto.d.ts +140 -3
- package/dist/remote/Porto.d.ts.map +1 -1
- package/dist/trusted-hosts.d.ts.map +1 -1
- package/dist/trusted-hosts.js +5 -0
- package/dist/trusted-hosts.js.map +1 -1
- package/dist/tsconfig.tmp.tsbuildinfo +1 -1
- package/dist/viem/Account.d.ts +3 -0
- package/dist/viem/Account.d.ts.map +1 -1
- package/dist/viem/Account.js +16 -12
- package/dist/viem/Account.js.map +1 -1
- package/dist/viem/Key.d.ts +96 -1
- package/dist/viem/Key.d.ts.map +1 -1
- package/dist/viem/Key.js +102 -3
- package/dist/viem/Key.js.map +1 -1
- package/dist/viem/RelayActions.d.ts +12 -1
- package/dist/viem/RelayActions.d.ts.map +1 -1
- package/dist/viem/RelayActions.js +8 -3
- package/dist/viem/RelayActions.js.map +1 -1
- package/dist/viem/internal/provider.d.ts +9 -0
- package/dist/viem/internal/provider.d.ts.map +1 -0
- package/dist/viem/internal/provider.js +15 -0
- package/dist/viem/internal/provider.js.map +1 -0
- package/dist/viem/internal/relayActions.d.ts +16 -0
- package/dist/viem/internal/relayActions.d.ts.map +1 -1
- package/dist/viem/internal/relayActions.js +29 -0
- package/dist/viem/internal/relayActions.js.map +1 -1
- package/package.json +3 -2
- package/src/core/Dialog.ts +10 -0
- package/src/core/internal/mode.ts +5 -1
- package/src/core/internal/modes/relay.ts +158 -56
- package/src/core/internal/provider.ts +14 -0
- package/src/core/internal/relay/rpcSchema.ts +4 -0
- package/src/core/internal/relay/schema/rpc.ts +23 -0
- package/src/core/internal/schema/key.ts +1 -0
- package/src/core/internal/schema/rpc.ts +1 -0
- package/src/remote/Events.ts +5 -1
- package/src/trusted-hosts.ts +5 -0
- package/src/viem/Account.ts +30 -12
- package/src/viem/Key.ts +163 -4
- package/src/viem/RelayActions.ts +30 -8
- package/src/viem/internal/provider.ts +19 -0
- package/src/viem/internal/relayActions.ts +42 -0
- package/dist/cli/bin/commands-GxQUW4ck.js +0 -50
|
@@ -62,6 +62,7 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
62
62
|
permissions,
|
|
63
63
|
internal,
|
|
64
64
|
signInWithEthereum,
|
|
65
|
+
providerRdns,
|
|
65
66
|
} = parameters
|
|
66
67
|
const { client } = internal
|
|
67
68
|
|
|
@@ -70,14 +71,16 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
70
71
|
const feeTokens = await Tokens.getTokens(client)
|
|
71
72
|
|
|
72
73
|
const adminKey = !mock
|
|
73
|
-
?
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
? providerRdns
|
|
75
|
+
? await Key.createEip1193Provider({ rdns: providerRdns })
|
|
76
|
+
: await Key.createWebAuthnP256({
|
|
77
|
+
createFn: webAuthn?.createFn,
|
|
78
|
+
label:
|
|
79
|
+
label ||
|
|
80
|
+
`${eoa.address.slice(0, 8)}\u2026${eoa.address.slice(-6)}`,
|
|
81
|
+
rpId: keystoreHost,
|
|
82
|
+
userId: Bytes.from(eoa.address),
|
|
83
|
+
})
|
|
81
84
|
: Key.createHeadlessWebAuthnP256()
|
|
82
85
|
const sessionKey = await PermissionsRequest.toKey(permissions, {
|
|
83
86
|
chainId: client.chain.id,
|
|
@@ -86,14 +89,47 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
86
89
|
|
|
87
90
|
const adminKeys = admins?.map((admin) => Key.from(admin))
|
|
88
91
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
const { address: existingAccount } = providerRdns
|
|
93
|
+
? await RelayActions.getAccount(client, { keyHash: adminKey.hash })
|
|
94
|
+
: { address: null }
|
|
95
|
+
|
|
96
|
+
const account = existingAccount
|
|
97
|
+
? Account.from({
|
|
98
|
+
address: existingAccount,
|
|
99
|
+
keys: [
|
|
100
|
+
adminKey,
|
|
101
|
+
...(adminKeys ?? []),
|
|
102
|
+
...(sessionKey ? [sessionKey] : []),
|
|
103
|
+
],
|
|
104
|
+
})
|
|
105
|
+
: await RelayActions.upgradeAccount(client, {
|
|
106
|
+
account: eoa,
|
|
107
|
+
authorizeKeys: [
|
|
108
|
+
adminKey,
|
|
109
|
+
...(adminKeys ?? []),
|
|
110
|
+
...(sessionKey ? [sessionKey] : []),
|
|
111
|
+
],
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
if (existingAccount && sessionKey) {
|
|
115
|
+
const { context, digest, typedData } =
|
|
116
|
+
await RelayActions.prepareCalls(client, {
|
|
117
|
+
account,
|
|
118
|
+
authorizeKeys: [sessionKey],
|
|
119
|
+
key: adminKey,
|
|
120
|
+
preCalls: true,
|
|
121
|
+
})
|
|
122
|
+
const signature = await Key.sign(adminKey, {
|
|
123
|
+
address: null,
|
|
124
|
+
payload: digest,
|
|
125
|
+
typedData,
|
|
126
|
+
})
|
|
127
|
+
await RelayActions.sendPreparedCalls(client, {
|
|
128
|
+
context,
|
|
129
|
+
key: adminKey,
|
|
130
|
+
signature,
|
|
131
|
+
})
|
|
132
|
+
}
|
|
97
133
|
|
|
98
134
|
address_internal = eoa.address
|
|
99
135
|
|
|
@@ -306,15 +342,19 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
306
342
|
)
|
|
307
343
|
if (!adminKey) throw new Error('admin key not found.')
|
|
308
344
|
|
|
309
|
-
const { context, digest } = await RelayActions.prepareCalls(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
345
|
+
const { context, digest, typedData } = await RelayActions.prepareCalls(
|
|
346
|
+
client,
|
|
347
|
+
{
|
|
348
|
+
account,
|
|
349
|
+
authorizeKeys: [authorizeKey],
|
|
350
|
+
key: adminKey,
|
|
351
|
+
preCalls: true,
|
|
352
|
+
},
|
|
353
|
+
)
|
|
315
354
|
const signature = await Key.sign(adminKey, {
|
|
316
355
|
address: null,
|
|
317
356
|
payload: digest,
|
|
357
|
+
typedData,
|
|
318
358
|
})
|
|
319
359
|
await RelayActions.sendPreparedCalls(client, {
|
|
320
360
|
context,
|
|
@@ -326,7 +366,12 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
326
366
|
},
|
|
327
367
|
|
|
328
368
|
async loadAccounts(parameters) {
|
|
329
|
-
const {
|
|
369
|
+
const {
|
|
370
|
+
internal,
|
|
371
|
+
permissions,
|
|
372
|
+
signInWithEthereum,
|
|
373
|
+
providerRdns: _providerRdns,
|
|
374
|
+
} = parameters
|
|
330
375
|
const { client } = internal
|
|
331
376
|
|
|
332
377
|
const feeTokens = await Tokens.getTokens(client)
|
|
@@ -362,42 +407,86 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
362
407
|
} as const
|
|
363
408
|
})()
|
|
364
409
|
|
|
365
|
-
const {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
410
|
+
const {
|
|
411
|
+
address,
|
|
412
|
+
credentialId,
|
|
413
|
+
webAuthnSignature,
|
|
414
|
+
rdns,
|
|
415
|
+
providerSignature,
|
|
416
|
+
} = await (async () => {
|
|
417
|
+
if (mock) {
|
|
418
|
+
if (!address_internal)
|
|
419
|
+
throw new Error('address_internal not found.')
|
|
420
|
+
return {
|
|
421
|
+
address: address_internal,
|
|
422
|
+
credentialId: undefined,
|
|
423
|
+
} as const
|
|
424
|
+
}
|
|
375
425
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
426
|
+
// If the address and credentialId are provided, we can skip the
|
|
427
|
+
// WebAuthn discovery step.
|
|
428
|
+
if (parameters.address && parameters.key) {
|
|
429
|
+
if ('credentialId' in parameters.key)
|
|
379
430
|
return {
|
|
380
431
|
address: parameters.address,
|
|
381
432
|
credentialId: parameters.key.credentialId,
|
|
382
433
|
}
|
|
434
|
+
if ('rdns' in parameters.key)
|
|
435
|
+
return {
|
|
436
|
+
address: parameters.address,
|
|
437
|
+
rdns: parameters.key.rdns,
|
|
438
|
+
}
|
|
439
|
+
}
|
|
383
440
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
// a session key if the user has provided one.
|
|
388
|
-
const webAuthnSignature = await WebAuthnP256.sign({
|
|
389
|
-
challenge: digest,
|
|
390
|
-
getFn: webAuthn?.getFn,
|
|
391
|
-
rpId: keystoreHost,
|
|
441
|
+
if (_providerRdns) {
|
|
442
|
+
const key = await Key.createEip1193Provider({
|
|
443
|
+
rdns: _providerRdns,
|
|
392
444
|
})
|
|
393
|
-
const response = webAuthnSignature.raw
|
|
394
|
-
.response as AuthenticatorAssertionResponse
|
|
395
445
|
|
|
396
|
-
const
|
|
397
|
-
|
|
446
|
+
const account = await RelayActions.getAccount(client, {
|
|
447
|
+
keyHash: key.hash,
|
|
448
|
+
})
|
|
398
449
|
|
|
399
|
-
|
|
400
|
-
|
|
450
|
+
if (account.address) {
|
|
451
|
+
const signature =
|
|
452
|
+
digest !== '0x'
|
|
453
|
+
? await Key.sign(key, {
|
|
454
|
+
address: null,
|
|
455
|
+
payload: message as Hex.Hex,
|
|
456
|
+
wrap: true,
|
|
457
|
+
})
|
|
458
|
+
: undefined
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
address: account.address,
|
|
462
|
+
providerSignature: signature,
|
|
463
|
+
rdns: _providerRdns,
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
throw new Error(
|
|
467
|
+
`No account found for external wallet ${key.publicKey}`,
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Discovery step. We need to do this to extract the key id
|
|
472
|
+
// to query for the Account.
|
|
473
|
+
// We will also optionally sign over a digest to authorize
|
|
474
|
+
// a session key if the user has provided one.
|
|
475
|
+
const webAuthnSignature = await WebAuthnP256.sign({
|
|
476
|
+
challenge: digest,
|
|
477
|
+
getFn: webAuthn?.getFn,
|
|
478
|
+
rpId: keystoreHost,
|
|
479
|
+
})
|
|
480
|
+
const response = webAuthnSignature.raw
|
|
481
|
+
.response as AuthenticatorAssertionResponse
|
|
482
|
+
|
|
483
|
+
const address = Bytes.toHex(new Uint8Array(response.userHandle!))
|
|
484
|
+
const credentialId = webAuthnSignature.raw.id
|
|
485
|
+
|
|
486
|
+
return { address, credentialId, webAuthnSignature }
|
|
487
|
+
})()
|
|
488
|
+
|
|
489
|
+
const providerRdns = rdns ?? _providerRdns
|
|
401
490
|
|
|
402
491
|
const keys = await RelayActions.getKeys(client, {
|
|
403
492
|
account: address,
|
|
@@ -421,6 +510,12 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
421
510
|
id: address,
|
|
422
511
|
rpId: keystoreHost,
|
|
423
512
|
})
|
|
513
|
+
if (key.type === 'address' && providerRdns)
|
|
514
|
+
return Key.fromEip1193Provider({
|
|
515
|
+
...key,
|
|
516
|
+
account: key.publicKey,
|
|
517
|
+
rdns: providerRdns,
|
|
518
|
+
})
|
|
424
519
|
}
|
|
425
520
|
return key
|
|
426
521
|
},
|
|
@@ -446,6 +541,8 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
446
541
|
},
|
|
447
542
|
)
|
|
448
543
|
|
|
544
|
+
if (providerSignature) return providerSignature
|
|
545
|
+
|
|
449
546
|
// Otherwise, we will sign over the digest for authorizing
|
|
450
547
|
// the session key.
|
|
451
548
|
return await Key.sign(adminKey, {
|
|
@@ -456,14 +553,16 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
456
553
|
|
|
457
554
|
// Prepare and send the authorize key pre-call.
|
|
458
555
|
if (authorizeKey) {
|
|
459
|
-
const { context, digest } =
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
556
|
+
const { context, digest, typedData } =
|
|
557
|
+
await RelayActions.prepareCalls(client, {
|
|
558
|
+
account,
|
|
559
|
+
authorizeKeys: [authorizeKey],
|
|
560
|
+
preCalls: true,
|
|
561
|
+
})
|
|
464
562
|
const signature = await Key.sign(adminKey, {
|
|
465
563
|
address: null,
|
|
466
564
|
payload: digest,
|
|
565
|
+
typedData,
|
|
467
566
|
})
|
|
468
567
|
await RelayActions.sendPreparedCalls(client, {
|
|
469
568
|
context,
|
|
@@ -492,7 +591,9 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
492
591
|
},
|
|
493
592
|
)
|
|
494
593
|
const signature = await Account.sign(account, {
|
|
495
|
-
payload:
|
|
594
|
+
payload: providerRdns
|
|
595
|
+
? (message as Hex.Hex)
|
|
596
|
+
: PersonalMessage.getSignPayload(Hex.fromString(message)),
|
|
496
597
|
role: 'admin',
|
|
497
598
|
})
|
|
498
599
|
const signature_erc8010 = await Erc8010.wrap(client, {
|
|
@@ -803,6 +904,7 @@ export function relay(parameters: relay.Parameters = {}) {
|
|
|
803
904
|
payload: TypedData.getSignPayload(data),
|
|
804
905
|
// If the domain is the Orchestrator, we don't need to replay-safe sign.
|
|
805
906
|
replaySafe: !isOrchestrator,
|
|
907
|
+
typedData: data,
|
|
806
908
|
webAuthn,
|
|
807
909
|
})
|
|
808
910
|
|
|
@@ -783,6 +783,7 @@ export function from<
|
|
|
783
783
|
grantPermissions: permissions,
|
|
784
784
|
selectAccount,
|
|
785
785
|
signInWithEthereum,
|
|
786
|
+
providerRdns,
|
|
786
787
|
} = capabilities ?? {}
|
|
787
788
|
|
|
788
789
|
const internal = {
|
|
@@ -802,6 +803,7 @@ export function from<
|
|
|
802
803
|
internal,
|
|
803
804
|
label,
|
|
804
805
|
permissions,
|
|
806
|
+
providerRdns,
|
|
805
807
|
signInWithEthereum,
|
|
806
808
|
})
|
|
807
809
|
return { accounts: [account] }
|
|
@@ -826,6 +828,17 @@ export function from<
|
|
|
826
828
|
publicKey: key.publicKey,
|
|
827
829
|
},
|
|
828
830
|
}
|
|
831
|
+
if (
|
|
832
|
+
key.type === 'eip1193provider' &&
|
|
833
|
+
key.role === 'admin' &&
|
|
834
|
+
!providerRdns
|
|
835
|
+
)
|
|
836
|
+
return {
|
|
837
|
+
address: account?.address,
|
|
838
|
+
key: {
|
|
839
|
+
rdns: key.privateKey?.rdns,
|
|
840
|
+
},
|
|
841
|
+
}
|
|
829
842
|
}
|
|
830
843
|
return {
|
|
831
844
|
address: undefined,
|
|
@@ -835,6 +848,7 @@ export function from<
|
|
|
835
848
|
const loadAccountsParams = {
|
|
836
849
|
internal,
|
|
837
850
|
permissions,
|
|
851
|
+
providerRdns,
|
|
838
852
|
signInWithEthereum,
|
|
839
853
|
}
|
|
840
854
|
try {
|
|
@@ -52,6 +52,10 @@ export type Schema = RpcSchema_ox.From<
|
|
|
52
52
|
Request: z.input<typeof Rpc.wallet_feeTokens.Request>
|
|
53
53
|
ReturnType: z.input<typeof Rpc.wallet_feeTokens.Response>
|
|
54
54
|
}
|
|
55
|
+
| {
|
|
56
|
+
Request: z.input<typeof Rpc.wallet_getAccount.Request>
|
|
57
|
+
ReturnType: z.input<typeof Rpc.wallet_getAccount.Response>
|
|
58
|
+
}
|
|
55
59
|
| {
|
|
56
60
|
Request: z.input<typeof Rpc.wallet_getAccounts.Request>
|
|
57
61
|
ReturnType: z.input<typeof Rpc.wallet_getAccounts.Response>
|
|
@@ -231,6 +231,29 @@ export namespace wallet_addFaucetFunds {
|
|
|
231
231
|
export type Response = z.infer<typeof Response>
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
export namespace wallet_getAccount {
|
|
235
|
+
/** Parameters for `wallet_getAccount` request. */
|
|
236
|
+
export const Parameters = z.object({
|
|
237
|
+
/** Key hash to look up account by. */
|
|
238
|
+
keyHash: u.hex(),
|
|
239
|
+
})
|
|
240
|
+
export type Parameters = z.infer<typeof Parameters>
|
|
241
|
+
|
|
242
|
+
/** Request for `wallet_getAccount`. */
|
|
243
|
+
export const Request = z.object({
|
|
244
|
+
method: z.literal('wallet_getAccount'),
|
|
245
|
+
params: z.readonly(z.tuple([Parameters])),
|
|
246
|
+
})
|
|
247
|
+
export type Request = z.infer<typeof Request>
|
|
248
|
+
|
|
249
|
+
/** Response for `wallet_getAccount`. */
|
|
250
|
+
export const Response = z.object({
|
|
251
|
+
/** Account address. */
|
|
252
|
+
address: z.nullable(u.address()),
|
|
253
|
+
})
|
|
254
|
+
export type Response = z.infer<typeof Response>
|
|
255
|
+
}
|
|
256
|
+
|
|
234
257
|
export namespace wallet_getAccounts {
|
|
235
258
|
/** Parameters for `wallet_getAccounts` request. */
|
|
236
259
|
export const Parameters = z.object({
|
package/src/remote/Events.ts
CHANGED
|
@@ -7,7 +7,11 @@ import type { Payload } from '../core/Messenger.js'
|
|
|
7
7
|
import * as Actions from './Actions.js'
|
|
8
8
|
import type * as Remote from './Porto.js'
|
|
9
9
|
|
|
10
|
-
const trustedOrigins = [
|
|
10
|
+
const trustedOrigins = [
|
|
11
|
+
'wallet.risechain.com',
|
|
12
|
+
'localhost:5174',
|
|
13
|
+
'localhost:5173',
|
|
14
|
+
]
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Event listener which is triggered when a request is ready
|
package/src/trusted-hosts.ts
CHANGED
package/src/viem/Account.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { toAccount } from 'viem/accounts'
|
|
14
14
|
import type { Assign, Compute } from '../core/internal/types.js'
|
|
15
15
|
import type * as Storage from '../core/Storage.js'
|
|
16
|
+
import type { prepareCalls } from './internal/relayActions.js'
|
|
16
17
|
import * as Key from './Key.js'
|
|
17
18
|
|
|
18
19
|
export type Account<
|
|
@@ -164,7 +165,9 @@ export function getKey(
|
|
|
164
165
|
if (account.keys && account.keys.length > 0) {
|
|
165
166
|
if (typeof key === 'number') return account.keys[key]
|
|
166
167
|
return account.keys.find(
|
|
167
|
-
(key) =>
|
|
168
|
+
(key) =>
|
|
169
|
+
(key.privateKey && (!role || key.role === role)) ||
|
|
170
|
+
key.type === 'eip1193provider',
|
|
168
171
|
)
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -191,24 +194,34 @@ export async function sign(
|
|
|
191
194
|
account: Account,
|
|
192
195
|
parameters: sign.Parameters,
|
|
193
196
|
): Promise<Compute<Hex.Hex>> {
|
|
194
|
-
const {
|
|
197
|
+
const {
|
|
198
|
+
storage,
|
|
199
|
+
replaySafe = true,
|
|
200
|
+
wrap = true,
|
|
201
|
+
webAuthn,
|
|
202
|
+
typedData,
|
|
203
|
+
} = parameters
|
|
195
204
|
|
|
196
205
|
const key = getKey(account, parameters)
|
|
197
206
|
|
|
207
|
+
const wrapped = {
|
|
208
|
+
domain: { verifyingContract: account.address },
|
|
209
|
+
message: {
|
|
210
|
+
digest: parameters.payload,
|
|
211
|
+
},
|
|
212
|
+
primaryType: 'ERC1271Sign',
|
|
213
|
+
types: {
|
|
214
|
+
ERC1271Sign: [{ name: 'digest', type: 'bytes32' }],
|
|
215
|
+
},
|
|
216
|
+
} as TypedData.Definition
|
|
217
|
+
|
|
198
218
|
const payload = (() => {
|
|
199
219
|
if (!replaySafe) return parameters.payload
|
|
200
|
-
return TypedData.getSignPayload(
|
|
201
|
-
domain: { verifyingContract: account.address },
|
|
202
|
-
message: {
|
|
203
|
-
digest: parameters.payload,
|
|
204
|
-
},
|
|
205
|
-
primaryType: 'ERC1271Sign',
|
|
206
|
-
types: {
|
|
207
|
-
ERC1271Sign: [{ name: 'digest', type: 'bytes32' }],
|
|
208
|
-
},
|
|
209
|
-
})
|
|
220
|
+
return TypedData.getSignPayload(wrapped)
|
|
210
221
|
})()
|
|
211
222
|
|
|
223
|
+
const typedDataPayload = !replaySafe ? typedData : wrapped
|
|
224
|
+
|
|
212
225
|
const sign = (() => {
|
|
213
226
|
if (!key) {
|
|
214
227
|
if (account.source === 'privateKey') return account.sign
|
|
@@ -219,6 +232,7 @@ export async function sign(
|
|
|
219
232
|
address: null,
|
|
220
233
|
payload: hash,
|
|
221
234
|
storage,
|
|
235
|
+
typedData: typedDataPayload,
|
|
222
236
|
webAuthn,
|
|
223
237
|
wrap,
|
|
224
238
|
})
|
|
@@ -274,5 +288,9 @@ export declare namespace sign {
|
|
|
274
288
|
getFn?: WebAuthnP256.sign.Options['getFn'] | undefined
|
|
275
289
|
}
|
|
276
290
|
| undefined
|
|
291
|
+
typedData?:
|
|
292
|
+
| prepareCalls.ReturnType['typedData']
|
|
293
|
+
| TypedData.Definition
|
|
294
|
+
| undefined
|
|
277
295
|
}
|
|
278
296
|
}
|