ox 1.8.8 → 1.8.9
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 +19 -0
- package/dist/tempo/AccountConfig.d.ts +46 -3
- package/dist/tempo/AccountConfig.d.ts.map +1 -1
- package/dist/tempo/AccountConfig.js +58 -9
- package/dist/tempo/AccountConfig.js.map +1 -1
- package/dist/tempo/AccountSimulation.d.ts +6 -2
- package/dist/tempo/AccountSimulation.d.ts.map +1 -1
- package/dist/tempo/AccountSimulation.js +15 -5
- package/dist/tempo/AccountSimulation.js.map +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +14 -9
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +8 -12
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +3 -3
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +10 -6
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/zod/tempo/AccountSimulation.d.ts +4 -0
- package/dist/zod/tempo/AccountSimulation.d.ts.map +1 -1
- package/dist/zod/tempo/AccountSimulation.js +2 -0
- package/dist/zod/tempo/AccountSimulation.js.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.d.ts +5 -5
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +10 -13
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +16 -8
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +6 -6
- package/dist/zod/tempo/TransactionRequest.d.ts +23 -9
- package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/zod/tempo/TransactionRequest.js +13 -9
- package/dist/zod/tempo/TransactionRequest.js.map +1 -1
- package/package.json +1 -1
- package/src/tempo/AccountConfig.test-d.ts +10 -0
- package/src/tempo/AccountConfig.test.ts +143 -10
- package/src/tempo/AccountConfig.ts +80 -9
- package/src/tempo/AccountOperation.test.ts +32 -32
- package/src/tempo/AccountSimulation.test.ts +43 -0
- package/src/tempo/AccountSimulation.ts +19 -5
- package/src/tempo/KeyAuthorization.test.ts +91 -32
- package/src/tempo/KeyAuthorization.ts +16 -39
- package/src/tempo/RpcSchemaTempo.test-d.ts +2 -2
- package/src/tempo/TransactionRequest.test-d.ts +5 -5
- package/src/tempo/TransactionRequest.test.ts +11 -9
- package/src/tempo/TransactionRequest.ts +13 -9
- package/src/version.ts +1 -1
- package/src/zod/tempo/AccountSimulation.ts +2 -0
- package/src/zod/tempo/KeyAuthorization.ts +28 -46
- package/src/zod/tempo/TransactionRequest.ts +17 -9
- package/src/zod/tempo/_test/AccountOperation.test.ts +1 -1
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +5 -5
- package/src/zod/tempo/_test/TransactionRequest.test.ts +12 -7
|
@@ -38,7 +38,7 @@ export type KeyAuthorization<
|
|
|
38
38
|
bigintType = bigint,
|
|
39
39
|
numberType = number,
|
|
40
40
|
> = {
|
|
41
|
-
/** Account address this authorization is bound to. Required
|
|
41
|
+
/** Account address this authorization is bound to. Required when an admin access key signs the grant (TIP-1049). */
|
|
42
42
|
account?: Address.Address | undefined
|
|
43
43
|
/** Address derived from the public key of the key type. */
|
|
44
44
|
address: Address.Address
|
|
@@ -116,8 +116,8 @@ export type Rpc = {
|
|
|
116
116
|
isAdmin?: boolean | null | undefined
|
|
117
117
|
/** Key identifier. */
|
|
118
118
|
keyId: Address.Address
|
|
119
|
-
/** Key type. Configurable accounts use the node's `
|
|
120
|
-
keyType: SignatureEnvelope.Type | '
|
|
119
|
+
/** Key type. Configurable accounts use the node's `configurableAccount` key type. */
|
|
120
|
+
keyType: SignatureEnvelope.Type | 'configurableAccount'
|
|
121
121
|
/** Token spending limits (`null`/`undefined` = unlimited, `[]` = no spending allowed). */
|
|
122
122
|
limits?: readonly RpcTokenLimit[] | null | undefined
|
|
123
123
|
/** Primitive or configurable account signature authorizing this key. */
|
|
@@ -445,7 +445,6 @@ export function from<
|
|
|
445
445
|
options: from.Options<signature> = {},
|
|
446
446
|
): from.ReturnType<authorization, signature> {
|
|
447
447
|
if ('keyId' in authorization) return fromRpc(authorization as Rpc) as never
|
|
448
|
-
assertAccountBinding(authorization.type, authorization.account)
|
|
449
448
|
const auth = authorization as KeyAuthorization & {
|
|
450
449
|
limits?: readonly { limit: bigint; token: Address.Address }[]
|
|
451
450
|
scopes?: readonly {
|
|
@@ -509,10 +508,7 @@ export declare namespace from {
|
|
|
509
508
|
: {})
|
|
510
509
|
>
|
|
511
510
|
|
|
512
|
-
type ErrorType =
|
|
513
|
-
| InvalidSignatureTypeError
|
|
514
|
-
| MissingAccountError
|
|
515
|
-
| Errors.GlobalErrorType
|
|
511
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
|
|
516
512
|
}
|
|
517
513
|
|
|
518
514
|
/**
|
|
@@ -551,8 +547,7 @@ export function fromRpc(authorization: Rpc): Signed {
|
|
|
551
547
|
const witness = authorization.witness ?? undefined
|
|
552
548
|
const isAdmin = authorization.isAdmin ?? undefined
|
|
553
549
|
const account = authorization.account ?? undefined
|
|
554
|
-
const type = keyType === '
|
|
555
|
-
assertAccountBinding(type, account)
|
|
550
|
+
const type = keyType === 'configurableAccount' ? 'configurable' : keyType
|
|
556
551
|
const signature = SignatureEnvelope.fromRpc(authorization.signature)
|
|
557
552
|
assertSignature(signature)
|
|
558
553
|
if (witness !== undefined) assertWitness(witness)
|
|
@@ -595,10 +590,7 @@ export function fromRpc(authorization: Rpc): Signed {
|
|
|
595
590
|
}
|
|
596
591
|
|
|
597
592
|
export declare namespace fromRpc {
|
|
598
|
-
type ErrorType =
|
|
599
|
-
| InvalidSignatureTypeError
|
|
600
|
-
| MissingAccountError
|
|
601
|
-
| Errors.GlobalErrorType
|
|
593
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
|
|
602
594
|
}
|
|
603
595
|
|
|
604
596
|
/**
|
|
@@ -728,7 +720,6 @@ export function fromTuple<const tuple extends Tuple>(
|
|
|
728
720
|
const account = isAbsent(rawAccount)
|
|
729
721
|
? undefined
|
|
730
722
|
: (rawAccount as Address.Address)
|
|
731
|
-
assertAccountBinding(keyType, account)
|
|
732
723
|
const args: KeyAuthorization = {
|
|
733
724
|
address: keyId,
|
|
734
725
|
chainId: chainId === '0x' ? 0n : Hex.toBigInt(chainId),
|
|
@@ -753,10 +744,7 @@ export declare namespace fromTuple {
|
|
|
753
744
|
KeyAuthorization<authorization extends Tuple<true> ? true : false>
|
|
754
745
|
>
|
|
755
746
|
|
|
756
|
-
type ErrorType =
|
|
757
|
-
| InvalidSignatureTypeError
|
|
758
|
-
| MissingAccountError
|
|
759
|
-
| Errors.GlobalErrorType
|
|
747
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
|
|
760
748
|
}
|
|
761
749
|
|
|
762
750
|
/**
|
|
@@ -962,7 +950,6 @@ export declare namespace serialize {
|
|
|
962
950
|
* @returns An RPC-formatted Key Authorization.
|
|
963
951
|
*/
|
|
964
952
|
export function toRpc(authorization: toRpc.Input): Rpc {
|
|
965
|
-
assertAccountBinding(authorization.type, authorization.account)
|
|
966
953
|
const {
|
|
967
954
|
address,
|
|
968
955
|
scopes,
|
|
@@ -1008,7 +995,7 @@ export function toRpc(authorization: toRpc.Input): Rpc {
|
|
|
1008
995
|
chainId: chainIdHex === '0x0' ? '0x' : chainIdHex,
|
|
1009
996
|
expiry: expiry != null ? Quantity.fromNumberish(expiry) : null,
|
|
1010
997
|
keyId: address,
|
|
1011
|
-
keyType: type === 'configurable' ? '
|
|
998
|
+
keyType: type === 'configurable' ? 'configurableAccount' : type,
|
|
1012
999
|
limits: limits?.map(({ token, limit, period }) => ({
|
|
1013
1000
|
token,
|
|
1014
1001
|
limit: Quantity.fromNumberish(limit),
|
|
@@ -1028,10 +1015,7 @@ export declare namespace toRpc {
|
|
|
1028
1015
|
/** Numberish input accepted by {@link ox#KeyAuthorization.(toRpc:function)}. */
|
|
1029
1016
|
type Input = Signed<Hex.Hex | bigint | number, Hex.Hex | number>
|
|
1030
1017
|
|
|
1031
|
-
type ErrorType =
|
|
1032
|
-
| InvalidSignatureTypeError
|
|
1033
|
-
| MissingAccountError
|
|
1034
|
-
| Errors.GlobalErrorType
|
|
1018
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
|
|
1035
1019
|
}
|
|
1036
1020
|
|
|
1037
1021
|
/**
|
|
@@ -1070,7 +1054,6 @@ export declare namespace toRpc {
|
|
|
1070
1054
|
export function toTuple<const authorization extends KeyAuthorization>(
|
|
1071
1055
|
authorization: authorization,
|
|
1072
1056
|
): toTuple.ReturnType<authorization> {
|
|
1073
|
-
assertAccountBinding(authorization.type, authorization.account)
|
|
1074
1057
|
const {
|
|
1075
1058
|
address,
|
|
1076
1059
|
chainId,
|
|
@@ -1178,10 +1161,7 @@ export declare namespace toTuple {
|
|
|
1178
1161
|
type ReturnType<authorization extends KeyAuthorization = KeyAuthorization> =
|
|
1179
1162
|
Compute<Tuple<authorization extends KeyAuthorization<true> ? true : false>>
|
|
1180
1163
|
|
|
1181
|
-
type ErrorType =
|
|
1182
|
-
| InvalidSignatureTypeError
|
|
1183
|
-
| MissingAccountError
|
|
1184
|
-
| Errors.GlobalErrorType
|
|
1164
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
|
|
1185
1165
|
}
|
|
1186
1166
|
|
|
1187
1167
|
function bigintToHex(value: bigint): Hex.Hex {
|
|
@@ -1215,14 +1195,6 @@ function resolveSelector(
|
|
|
1215
1195
|
return AbiItem.getSelector(selector)
|
|
1216
1196
|
}
|
|
1217
1197
|
|
|
1218
|
-
function assertAccountBinding(
|
|
1219
|
-
type: KeyAuthorization['type'],
|
|
1220
|
-
account: Address.Address | null | undefined,
|
|
1221
|
-
): void {
|
|
1222
|
-
if (type === 'configurable' && account == null)
|
|
1223
|
-
throw new MissingAccountError()
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
1198
|
function assertWitness(witness: Hex.Hex): void {
|
|
1227
1199
|
if (Hex.size(witness) !== 32) throw new InvalidWitnessSizeError(witness)
|
|
1228
1200
|
}
|
|
@@ -1270,7 +1242,12 @@ export class InvalidSignatureTypeError extends Error {
|
|
|
1270
1242
|
}
|
|
1271
1243
|
}
|
|
1272
1244
|
|
|
1273
|
-
/**
|
|
1245
|
+
/**
|
|
1246
|
+
* Thrown when a configurable account key grant omits its parent account binding.
|
|
1247
|
+
*
|
|
1248
|
+
* @deprecated No longer thrown. The Tempo node only requires `account` on grants
|
|
1249
|
+
* signed by an admin access key, which it checks against the transaction sender.
|
|
1250
|
+
*/
|
|
1274
1251
|
export class MissingAccountError extends Error {
|
|
1275
1252
|
override readonly name = 'KeyAuthorization.MissingAccountError'
|
|
1276
1253
|
constructor() {
|
|
@@ -17,7 +17,7 @@ declare const tempoProvider: Provider.Provider<{
|
|
|
17
17
|
declare const address: Address.Address
|
|
18
18
|
declare const hash: Hex.Hex
|
|
19
19
|
declare const keyAuthorization: KeyAuthorization.Rpc
|
|
20
|
-
declare const
|
|
20
|
+
declare const configurableAccountSimulation: AccountSimulation.Rpc
|
|
21
21
|
declare const serializedTransaction: Hex.Hex
|
|
22
22
|
declare const signature: Hex.Hex
|
|
23
23
|
|
|
@@ -79,7 +79,7 @@ test('tempo simulation accepts account simulation specs', () => {
|
|
|
79
79
|
{
|
|
80
80
|
calls: [
|
|
81
81
|
{
|
|
82
|
-
|
|
82
|
+
configurableAccountSimulation,
|
|
83
83
|
},
|
|
84
84
|
],
|
|
85
85
|
},
|
|
@@ -53,19 +53,19 @@ describe('TransactionRequest type', () => {
|
|
|
53
53
|
expectTypeOf<
|
|
54
54
|
TransactionRequest.TransactionRequest['accountSimulation']
|
|
55
55
|
>().toEqualTypeOf<AccountSimulation.Spec | undefined>()
|
|
56
|
-
expectTypeOf<
|
|
57
|
-
|
|
58
|
-
>()
|
|
56
|
+
expectTypeOf<
|
|
57
|
+
TransactionRequest.Rpc['configurableAccountSimulation']
|
|
58
|
+
>().toEqualTypeOf<AccountSimulation.Rpc | undefined>()
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
test('maps the configurable key type to the RPC
|
|
61
|
+
test('maps the configurable key type to the RPC configurableAccount key type', () => {
|
|
62
62
|
expectTypeOf<
|
|
63
63
|
TransactionRequest.TransactionRequest['keyType']
|
|
64
64
|
>().toEqualTypeOf<
|
|
65
65
|
'configurable' | 'p256' | 'secp256k1' | 'webAuthn' | undefined
|
|
66
66
|
>()
|
|
67
67
|
expectTypeOf<TransactionRequest.Rpc['keyType']>().toEqualTypeOf<
|
|
68
|
-
'
|
|
68
|
+
'configurableAccount' | 'p256' | 'secp256k1' | 'webAuthn' | undefined
|
|
69
69
|
>()
|
|
70
70
|
})
|
|
71
71
|
})
|
|
@@ -139,9 +139,9 @@ describe('fromRpc', () => {
|
|
|
139
139
|
`)
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
-
test('behavior:
|
|
142
|
+
test('behavior: configurableAccount key type decodes as configurable', () => {
|
|
143
143
|
const request = TransactionRequest.fromRpc({
|
|
144
|
-
keyType: '
|
|
144
|
+
keyType: 'configurableAccount',
|
|
145
145
|
type: '0x76',
|
|
146
146
|
})
|
|
147
147
|
expect(request.keyType).toMatchInlineSnapshot(`"configurable"`)
|
|
@@ -150,7 +150,7 @@ describe('fromRpc', () => {
|
|
|
150
150
|
test('behavior: account simulation', () => {
|
|
151
151
|
const request = TransactionRequest.fromRpc({
|
|
152
152
|
from: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
153
|
-
|
|
153
|
+
configurableAccountSimulation: accountSimulationRpc,
|
|
154
154
|
type: '0x76',
|
|
155
155
|
})
|
|
156
156
|
|
|
@@ -266,11 +266,11 @@ describe('toRpc', () => {
|
|
|
266
266
|
`)
|
|
267
267
|
})
|
|
268
268
|
|
|
269
|
-
test('behavior: configurable key type encodes as
|
|
269
|
+
test('behavior: configurable key type encodes as configurableAccount', () => {
|
|
270
270
|
const request = TransactionRequest.toRpc({
|
|
271
271
|
keyType: 'configurable',
|
|
272
272
|
})
|
|
273
|
-
expect(request.keyType).toMatchInlineSnapshot(`"
|
|
273
|
+
expect(request.keyType).toMatchInlineSnapshot(`"configurableAccount"`)
|
|
274
274
|
})
|
|
275
275
|
|
|
276
276
|
test('behavior: account simulation', () => {
|
|
@@ -288,8 +288,7 @@ describe('toRpc', () => {
|
|
|
288
288
|
"value": "0x",
|
|
289
289
|
},
|
|
290
290
|
],
|
|
291
|
-
"
|
|
292
|
-
"multisigSimulation": {
|
|
291
|
+
"configurableAccountSimulation": {
|
|
293
292
|
"approvals": [
|
|
294
293
|
{
|
|
295
294
|
"keyData": "0x0005",
|
|
@@ -299,6 +298,7 @@ describe('toRpc', () => {
|
|
|
299
298
|
],
|
|
300
299
|
"config": "0xf852a011111111111111111111111111111111111111111111111111111111111111118002eed694111111111111111111111111111111111111111101d694bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb01",
|
|
301
300
|
},
|
|
301
|
+
"from": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
302
302
|
"type": "0x76",
|
|
303
303
|
}
|
|
304
304
|
`)
|
|
@@ -445,7 +445,7 @@ describe('roundtrip', () => {
|
|
|
445
445
|
nonceKey: '0xff',
|
|
446
446
|
gas: '0x186a0',
|
|
447
447
|
keyAuthorizationSimulation: accountSimulationRpc,
|
|
448
|
-
|
|
448
|
+
configurableAccountSimulation: accountSimulationRpc,
|
|
449
449
|
type: '0x76',
|
|
450
450
|
}
|
|
451
451
|
|
|
@@ -461,7 +461,9 @@ describe('roundtrip', () => {
|
|
|
461
461
|
expect(rpc.keyAuthorizationSimulation).toEqual(
|
|
462
462
|
original.keyAuthorizationSimulation,
|
|
463
463
|
)
|
|
464
|
-
expect(rpc.
|
|
464
|
+
expect(rpc.configurableAccountSimulation).toEqual(
|
|
465
|
+
original.configurableAccountSimulation,
|
|
466
|
+
)
|
|
465
467
|
expect(rpc.type).toBe('0x76')
|
|
466
468
|
})
|
|
467
469
|
})
|
|
@@ -70,9 +70,9 @@ export type Rpc = Omit<
|
|
|
70
70
|
feeToken?: Hex.Hex | undefined
|
|
71
71
|
keyAuthorization?: KeyAuthorization.Rpc | undefined
|
|
72
72
|
keyAuthorizationSimulation?: AccountSimulation.Rpc | undefined
|
|
73
|
-
/** Key type. Configurable accounts use the node's `
|
|
74
|
-
keyType?: SignatureEnvelope.Type | '
|
|
75
|
-
|
|
73
|
+
/** Key type. Configurable accounts use the node's `configurableAccount` key type. */
|
|
74
|
+
keyType?: SignatureEnvelope.Type | 'configurableAccount' | undefined
|
|
75
|
+
configurableAccountSimulation?: AccountSimulation.Rpc | undefined
|
|
76
76
|
nonceKey?: Hex.Hex | undefined
|
|
77
77
|
signature?: SignatureEnvelope.SignatureEnvelopeRpc | undefined
|
|
78
78
|
}
|
|
@@ -104,7 +104,7 @@ export function fromRpc(request: Rpc): TransactionRequest {
|
|
|
104
104
|
authorizationList: _,
|
|
105
105
|
keyAuthorizationSimulation: __,
|
|
106
106
|
keyType: ___,
|
|
107
|
-
|
|
107
|
+
configurableAccountSimulation: ____,
|
|
108
108
|
...rest
|
|
109
109
|
} = request
|
|
110
110
|
const request_ = ox_TransactionRequest.fromRpc(
|
|
@@ -147,10 +147,12 @@ export function fromRpc(request: Rpc): TransactionRequest {
|
|
|
147
147
|
)
|
|
148
148
|
if (typeof request.keyType !== 'undefined')
|
|
149
149
|
request_.keyType =
|
|
150
|
-
request.keyType === '
|
|
151
|
-
|
|
150
|
+
request.keyType === 'configurableAccount'
|
|
151
|
+
? 'configurable'
|
|
152
|
+
: request.keyType
|
|
153
|
+
if (request.configurableAccountSimulation)
|
|
152
154
|
request_.accountSimulation = AccountSimulation.fromRpc(
|
|
153
|
-
request.
|
|
155
|
+
request.configurableAccountSimulation,
|
|
154
156
|
)
|
|
155
157
|
if (typeof request.validBefore !== 'undefined')
|
|
156
158
|
request_.validBefore = Hex.toNumber(request.validBefore as Hex.Hex)
|
|
@@ -292,13 +294,15 @@ export function toRpc(request: toRpc.Input): Rpc {
|
|
|
292
294
|
if (typeof request.keyId !== 'undefined') request_rpc.keyId = request.keyId
|
|
293
295
|
if (typeof request.keyType !== 'undefined')
|
|
294
296
|
request_rpc.keyType =
|
|
295
|
-
request.keyType === 'configurable'
|
|
297
|
+
request.keyType === 'configurable'
|
|
298
|
+
? 'configurableAccount'
|
|
299
|
+
: request.keyType
|
|
296
300
|
if (typeof request.keyAuthorizationSimulation !== 'undefined')
|
|
297
301
|
request_rpc.keyAuthorizationSimulation = AccountSimulation.toRpc(
|
|
298
302
|
request.keyAuthorizationSimulation,
|
|
299
303
|
)
|
|
300
304
|
if (typeof request.accountSimulation !== 'undefined')
|
|
301
|
-
request_rpc.
|
|
305
|
+
request_rpc.configurableAccountSimulation = AccountSimulation.toRpc(
|
|
302
306
|
request.accountSimulation,
|
|
303
307
|
)
|
|
304
308
|
if (typeof request.validBefore !== 'undefined')
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.8.
|
|
2
|
+
export const version = '1.8.9'
|
|
@@ -21,6 +21,7 @@ export const Domain = z.object({
|
|
|
21
21
|
.check(z.maxLength(core_AccountConfig.maxSignatures)),
|
|
22
22
|
),
|
|
23
23
|
config: z_AccountConfig.Config,
|
|
24
|
+
signer: z.optional(z_Address.Address),
|
|
24
25
|
})
|
|
25
26
|
|
|
26
27
|
const Rpc_ = z
|
|
@@ -31,6 +32,7 @@ const Rpc_ = z
|
|
|
31
32
|
.check(z.maxLength(core_AccountConfig.maxSignatures)),
|
|
32
33
|
),
|
|
33
34
|
config: z_Hex.Hex,
|
|
35
|
+
signer: z.optional(z_Address.Address),
|
|
34
36
|
})
|
|
35
37
|
.check(
|
|
36
38
|
z.refine((value) => {
|
|
@@ -29,28 +29,24 @@ export const RpcCallScope = z.object({
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
/** RPC key authorization schema. */
|
|
32
|
-
export const Rpc = z
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
(value) => value.keyType !== 'multisig' || value.account != null,
|
|
51
|
-
'configurable account key grants require a parent account binding',
|
|
52
|
-
),
|
|
53
|
-
)
|
|
32
|
+
export const Rpc = z.object({
|
|
33
|
+
account: z.optional(z.nullable(z_Address.Address)),
|
|
34
|
+
allowedCalls: z.optional(z.nullable(z.readonly(z.array(RpcCallScope)))),
|
|
35
|
+
chainId: z_Hex.Hex,
|
|
36
|
+
expiry: z.optional(z.nullable(z_Hex.Hex)),
|
|
37
|
+
isAdmin: z.optional(z.nullable(z.boolean())),
|
|
38
|
+
keyId: z_Address.Address,
|
|
39
|
+
keyType: z.union([
|
|
40
|
+
z_SignatureEnvelope.Type,
|
|
41
|
+
z.literal('configurableAccount'),
|
|
42
|
+
]),
|
|
43
|
+
limits: z.optional(z.nullable(z.readonly(z.array(RpcTokenLimit)))),
|
|
44
|
+
signature: z.union([
|
|
45
|
+
z_SignatureEnvelope.PrimitiveRpc,
|
|
46
|
+
z_SignatureEnvelope.ConfigurableRpc,
|
|
47
|
+
]),
|
|
48
|
+
witness: z.optional(z.nullable(z_Hex.Hex)),
|
|
49
|
+
})
|
|
54
50
|
|
|
55
51
|
/** Token spending limit schema. */
|
|
56
52
|
export const TokenLimit = z.object({
|
|
@@ -88,18 +84,11 @@ const domainShape = {
|
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
/** Decoded key authorization schema. */
|
|
91
|
-
export const Domain = z
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
.check(
|
|
98
|
-
z.refine(
|
|
99
|
-
(value) => value.type !== 'configurable' || value.account != null,
|
|
100
|
-
'configurable account key grants require a parent account binding',
|
|
101
|
-
),
|
|
102
|
-
)
|
|
87
|
+
export const Domain = z.object({
|
|
88
|
+
...domainShape,
|
|
89
|
+
account: z.optional(z_Address.Address),
|
|
90
|
+
isAdmin: z.optional(z.boolean()),
|
|
91
|
+
})
|
|
103
92
|
|
|
104
93
|
const domainToRpcShape = {
|
|
105
94
|
...domainShape,
|
|
@@ -109,18 +98,11 @@ const domainToRpcShape = {
|
|
|
109
98
|
}
|
|
110
99
|
|
|
111
100
|
/** Encode-only decoded key authorization schema accepting numberish `toRpc` inputs. */
|
|
112
|
-
export const DomainToRpc = z
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
.check(
|
|
119
|
-
z.refine(
|
|
120
|
-
(value) => value.type !== 'configurable' || value.account != null,
|
|
121
|
-
'configurable account key grants require a parent account binding',
|
|
122
|
-
),
|
|
123
|
-
)
|
|
101
|
+
export const DomainToRpc = z.object({
|
|
102
|
+
...domainToRpcShape,
|
|
103
|
+
account: z.optional(z_Address.Address),
|
|
104
|
+
isAdmin: z.optional(z.boolean()),
|
|
105
|
+
})
|
|
124
106
|
|
|
125
107
|
/** Codec decoding an RPC key authorization into a signed key authorization. */
|
|
126
108
|
export const KeyAuthorization = z.codec(Rpc, Domain, {
|
|
@@ -26,12 +26,12 @@ const KeyType = z.union([
|
|
|
26
26
|
z.literal('configurable'),
|
|
27
27
|
])
|
|
28
28
|
|
|
29
|
-
// The node's wire format names the configurable account key type `
|
|
29
|
+
// The node's wire format names the configurable account key type `configurableAccount`.
|
|
30
30
|
const KeyTypeRpc = z.union([
|
|
31
31
|
z.literal('secp256k1'),
|
|
32
32
|
z.literal('p256'),
|
|
33
33
|
z.literal('webAuthn'),
|
|
34
|
-
z.literal('
|
|
34
|
+
z.literal('configurableAccount'),
|
|
35
35
|
])
|
|
36
36
|
|
|
37
37
|
const SignatureRpc = z.object({
|
|
@@ -93,7 +93,7 @@ export const Rpc = z.object({
|
|
|
93
93
|
maxFeePerGas: z.optional(z_Hex.Hex),
|
|
94
94
|
maxPriorityFeePerGas: z.optional(z_Hex.Hex),
|
|
95
95
|
keyAuthorizationSimulation: z.optional(z_AccountSimulation.Rpc),
|
|
96
|
-
|
|
96
|
+
configurableAccountSimulation: z.optional(z_AccountSimulation.Rpc),
|
|
97
97
|
nonce: z.optional(z_Hex.Hex),
|
|
98
98
|
nonceKey: z.optional(z_Hex.Hex),
|
|
99
99
|
r: z.optional(z_Hex.Hex),
|
|
@@ -218,7 +218,11 @@ export const TransactionRequestToRpc = z.codec(Rpc, DomainToRpc, {
|
|
|
218
218
|
function fromRpc(
|
|
219
219
|
request: core_TransactionRequest.Rpc,
|
|
220
220
|
): core_TransactionRequest.TransactionRequest {
|
|
221
|
-
const {
|
|
221
|
+
const {
|
|
222
|
+
authorizationList: _,
|
|
223
|
+
configurableAccountSimulation: __,
|
|
224
|
+
...rest
|
|
225
|
+
} = request
|
|
222
226
|
const request_ = z.decode(
|
|
223
227
|
z_TransactionRequest.TransactionRequest,
|
|
224
228
|
rest as never,
|
|
@@ -263,16 +267,18 @@ function fromRpc(
|
|
|
263
267
|
if (typeof request.keyId !== 'undefined') request_.keyId = request.keyId
|
|
264
268
|
if (typeof request.keyType !== 'undefined')
|
|
265
269
|
request_.keyType =
|
|
266
|
-
request.keyType === '
|
|
270
|
+
request.keyType === 'configurableAccount'
|
|
271
|
+
? 'configurable'
|
|
272
|
+
: request.keyType
|
|
267
273
|
if (typeof request.keyAuthorizationSimulation !== 'undefined')
|
|
268
274
|
request_.keyAuthorizationSimulation = z.decode(
|
|
269
275
|
z_AccountSimulation.AccountSimulation,
|
|
270
276
|
request.keyAuthorizationSimulation,
|
|
271
277
|
)
|
|
272
|
-
if (typeof request.
|
|
278
|
+
if (typeof request.configurableAccountSimulation !== 'undefined')
|
|
273
279
|
request_.accountSimulation = z.decode(
|
|
274
280
|
z_AccountSimulation.AccountSimulation,
|
|
275
|
-
request.
|
|
281
|
+
request.configurableAccountSimulation,
|
|
276
282
|
)
|
|
277
283
|
if (typeof request.validBefore !== 'undefined')
|
|
278
284
|
request_.validBefore = core_Hex.toNumber(request.validBefore)
|
|
@@ -357,14 +363,16 @@ function toRpc(
|
|
|
357
363
|
if (typeof request.keyId !== 'undefined') request_rpc.keyId = request.keyId
|
|
358
364
|
if (typeof request.keyType !== 'undefined')
|
|
359
365
|
request_rpc.keyType =
|
|
360
|
-
request.keyType === 'configurable'
|
|
366
|
+
request.keyType === 'configurable'
|
|
367
|
+
? 'configurableAccount'
|
|
368
|
+
: request.keyType
|
|
361
369
|
if (typeof request.keyAuthorizationSimulation !== 'undefined')
|
|
362
370
|
request_rpc.keyAuthorizationSimulation = z.encode(
|
|
363
371
|
z_AccountSimulation.AccountSimulation,
|
|
364
372
|
request.keyAuthorizationSimulation,
|
|
365
373
|
)
|
|
366
374
|
if (typeof request.accountSimulation !== 'undefined')
|
|
367
|
-
request_rpc.
|
|
375
|
+
request_rpc.configurableAccountSimulation = z.encode(
|
|
368
376
|
z_AccountSimulation.AccountSimulation,
|
|
369
377
|
request.accountSimulation,
|
|
370
378
|
)
|
|
@@ -24,7 +24,7 @@ const rpc = {
|
|
|
24
24
|
version: '0x1',
|
|
25
25
|
},
|
|
26
26
|
createdAt: 1,
|
|
27
|
-
hash: '
|
|
27
|
+
hash: '0x2b7a9f98ab46088ccfbd145553b5ec804cd6a24eab46a21f023cbe68385f0fb4',
|
|
28
28
|
signatureCount: 1,
|
|
29
29
|
status: 'pending',
|
|
30
30
|
threshold: 2,
|
|
@@ -21,7 +21,7 @@ const rpc = {
|
|
|
21
21
|
} as const
|
|
22
22
|
|
|
23
23
|
describe('KeyAuthorization', () => {
|
|
24
|
-
test('
|
|
24
|
+
test('accepts unbound configurable grants through every schema', () => {
|
|
25
25
|
const domain = {
|
|
26
26
|
...z.decode(z_KeyAuthorization.KeyAuthorization, rpc),
|
|
27
27
|
type: 'configurable',
|
|
@@ -30,15 +30,15 @@ describe('KeyAuthorization', () => {
|
|
|
30
30
|
expect(
|
|
31
31
|
z.safeDecode(z_KeyAuthorization.KeyAuthorization, {
|
|
32
32
|
...rpc,
|
|
33
|
-
keyType: '
|
|
33
|
+
keyType: 'configurableAccount',
|
|
34
34
|
account,
|
|
35
35
|
}).success,
|
|
36
|
-
).toMatchInlineSnapshot(`
|
|
36
|
+
).toMatchInlineSnapshot(`true`)
|
|
37
37
|
for (const schema of [
|
|
38
38
|
z_KeyAuthorization.Domain,
|
|
39
39
|
z_KeyAuthorization.DomainToRpc,
|
|
40
40
|
]) {
|
|
41
|
-
expect(z.safeParse(schema, domain).success).toMatchInlineSnapshot(`
|
|
41
|
+
expect(z.safeParse(schema, domain).success).toMatchInlineSnapshot(`true`)
|
|
42
42
|
expect(
|
|
43
43
|
z.safeParse(schema, { ...domain, account: rpc.keyId }).success,
|
|
44
44
|
).toMatchInlineSnapshot(`true`)
|
|
@@ -47,7 +47,7 @@ describe('KeyAuthorization', () => {
|
|
|
47
47
|
z_KeyAuthorization.KeyAuthorization,
|
|
48
48
|
z_KeyAuthorization.KeyAuthorizationToRpc,
|
|
49
49
|
])
|
|
50
|
-
expect(z.safeEncode(codec, domain).success).toMatchInlineSnapshot(`
|
|
50
|
+
expect(z.safeEncode(codec, domain).success).toMatchInlineSnapshot(`true`)
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
test('decodes an RPC key authorization', () => {
|
|
@@ -79,13 +79,13 @@ describe('TransactionRequest', () => {
|
|
|
79
79
|
const decoded = z.decode(z_TransactionRequest.TransactionRequest, {
|
|
80
80
|
...rpc,
|
|
81
81
|
keyAuthorizationSimulation: accountSimulationRpc,
|
|
82
|
-
|
|
82
|
+
configurableAccountSimulation: accountSimulationRpc,
|
|
83
83
|
})
|
|
84
84
|
expect(decoded).toEqual(
|
|
85
85
|
core_TransactionRequest.fromRpc({
|
|
86
86
|
...rpc,
|
|
87
87
|
keyAuthorizationSimulation: accountSimulationRpc,
|
|
88
|
-
|
|
88
|
+
configurableAccountSimulation: accountSimulationRpc,
|
|
89
89
|
}),
|
|
90
90
|
)
|
|
91
91
|
expect(decoded.accountSimulation).toEqual(
|
|
@@ -96,22 +96,27 @@ describe('TransactionRequest', () => {
|
|
|
96
96
|
expect(encoded.keyAuthorizationSimulation).toStrictEqual(
|
|
97
97
|
accountSimulationRpc,
|
|
98
98
|
)
|
|
99
|
-
expect(encoded.
|
|
99
|
+
expect(encoded.configurableAccountSimulation).toStrictEqual(
|
|
100
|
+
accountSimulationRpc,
|
|
101
|
+
)
|
|
100
102
|
expect(encoded).toEqual(core_TransactionRequest.toRpc(decoded))
|
|
101
103
|
})
|
|
102
104
|
|
|
103
|
-
test('configurable key type maps to the
|
|
105
|
+
test('configurable key type maps to the configurableAccount RPC key type', () => {
|
|
104
106
|
const decoded = z.decode(z_TransactionRequest.TransactionRequest, {
|
|
105
107
|
...rpc,
|
|
106
|
-
keyType: '
|
|
108
|
+
keyType: 'configurableAccount',
|
|
107
109
|
})
|
|
108
110
|
expect(decoded.keyType).toBe('configurable')
|
|
109
111
|
expect(decoded).toEqual(
|
|
110
|
-
core_TransactionRequest.fromRpc({
|
|
112
|
+
core_TransactionRequest.fromRpc({
|
|
113
|
+
...rpc,
|
|
114
|
+
keyType: 'configurableAccount',
|
|
115
|
+
}),
|
|
111
116
|
)
|
|
112
117
|
|
|
113
118
|
const encoded = z.encode(z_TransactionRequest.TransactionRequest, decoded)
|
|
114
|
-
expect(encoded.keyType).toBe('
|
|
119
|
+
expect(encoded.keyType).toBe('configurableAccount')
|
|
115
120
|
expect(encoded).toEqual(core_TransactionRequest.toRpc(decoded))
|
|
116
121
|
})
|
|
117
122
|
|