ox 1.8.14 → 1.8.15
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 +6 -0
- package/dist/tempo/SignaturePreAuthorized.d.ts +192 -0
- package/dist/tempo/SignaturePreAuthorized.d.ts.map +1 -0
- package/dist/tempo/SignaturePreAuthorized.js +299 -0
- package/dist/tempo/SignaturePreAuthorized.js.map +1 -0
- package/dist/tempo/index.d.ts +26 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +26 -0
- package/dist/tempo/index.js.map +1 -1
- package/package.json +6 -1
- package/src/tempo/SignaturePreAuthorized.test-d.ts +29 -0
- package/src/tempo/SignaturePreAuthorized.test.ts +410 -0
- package/src/tempo/SignaturePreAuthorized.ts +370 -0
- package/src/tempo/index.ts +26 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { Address, Hash, Hex, P256, Rlp, Secp256k1 } from 'ox'
|
|
2
|
+
import { describe, expect, test } from 'vp/test'
|
|
3
|
+
import * as KeyAuthorization from './KeyAuthorization.js'
|
|
4
|
+
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
5
|
+
import * as SignaturePreAuthorized from './SignaturePreAuthorized.js'
|
|
6
|
+
|
|
7
|
+
// TIP-1165 example. Both keys are public test keys.
|
|
8
|
+
const rootKey =
|
|
9
|
+
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' as const
|
|
10
|
+
const accessKey =
|
|
11
|
+
'0x59c6995e998f97a5a0044966f0945389dc9d86dae88c7a8412f4603b6b78690d' as const
|
|
12
|
+
|
|
13
|
+
const vector = {
|
|
14
|
+
hash: '0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8',
|
|
15
|
+
keychainSignature:
|
|
16
|
+
'0x04f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1c',
|
|
17
|
+
signedKeyAuthorization:
|
|
18
|
+
'0xf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b',
|
|
19
|
+
} as const
|
|
20
|
+
const vectorWrapped = Hex.concat(
|
|
21
|
+
'0xf8fab856',
|
|
22
|
+
vector.keychainSignature,
|
|
23
|
+
vector.signedKeyAuthorization,
|
|
24
|
+
'0x1165116511651165116511651165116511651165116511651165116511651165',
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const account = Address.fromPublicKey(
|
|
28
|
+
Secp256k1.getPublicKey({ privateKey: rootKey }),
|
|
29
|
+
)
|
|
30
|
+
const hash = Hash.keccak256(Hex.fromString('hello'))
|
|
31
|
+
|
|
32
|
+
const authorization = KeyAuthorization.from({
|
|
33
|
+
address: Address.fromPublicKey(
|
|
34
|
+
Secp256k1.getPublicKey({ privateKey: accessKey }),
|
|
35
|
+
),
|
|
36
|
+
chainId: 4217n,
|
|
37
|
+
expiry: 1_900_000_000,
|
|
38
|
+
limits: [
|
|
39
|
+
{
|
|
40
|
+
limit: 10_000_000n,
|
|
41
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
type: 'secp256k1',
|
|
45
|
+
witness: '0xe55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5',
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const keyAuthorization = KeyAuthorization.from(authorization, {
|
|
49
|
+
signature: SignatureEnvelope.from(
|
|
50
|
+
Secp256k1.sign({
|
|
51
|
+
payload: KeyAuthorization.getSignPayload(authorization),
|
|
52
|
+
privateKey: rootKey,
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const inner = SignatureEnvelope.from(
|
|
58
|
+
Secp256k1.sign({
|
|
59
|
+
payload: Hash.keccak256(Hex.concat('0x04', hash, account)),
|
|
60
|
+
privateKey: accessKey,
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const signature: SignatureEnvelope.Keychain = {
|
|
65
|
+
inner,
|
|
66
|
+
type: 'keychain',
|
|
67
|
+
userAddress: account,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const wrapped = SignaturePreAuthorized.wrap({ keyAuthorization, signature })
|
|
71
|
+
|
|
72
|
+
const signatureSerialized = SignatureEnvelope.serialize(signature)
|
|
73
|
+
const keyAuthorizationTuple = KeyAuthorization.toTuple(keyAuthorization)
|
|
74
|
+
|
|
75
|
+
function wrapRaw(body: Hex.Hex) {
|
|
76
|
+
return Hex.concat(body, SignaturePreAuthorized.magicBytes)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
describe('magicBytes', () => {
|
|
80
|
+
test('default', () => {
|
|
81
|
+
expect(SignaturePreAuthorized.magicBytes).toMatchInlineSnapshot(
|
|
82
|
+
'"0x1165116511651165116511651165116511651165116511651165116511651165"',
|
|
83
|
+
)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('wrap', () => {
|
|
88
|
+
test('TIP-1165 example vector', () => {
|
|
89
|
+
expect(hash).toBe(vector.hash)
|
|
90
|
+
expect(signatureSerialized).toBe(vector.keychainSignature)
|
|
91
|
+
expect(KeyAuthorization.serialize(keyAuthorization)).toBe(
|
|
92
|
+
vector.signedKeyAuthorization,
|
|
93
|
+
)
|
|
94
|
+
expect(wrapped).toBe(vectorWrapped)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('behavior: p256 inner signature', () => {
|
|
98
|
+
const privateKey = P256.randomPrivateKey()
|
|
99
|
+
const publicKey = P256.getPublicKey({ privateKey })
|
|
100
|
+
const signature = SignatureEnvelope.from({
|
|
101
|
+
inner: SignatureEnvelope.from({
|
|
102
|
+
prehash: false,
|
|
103
|
+
publicKey,
|
|
104
|
+
signature: P256.sign({
|
|
105
|
+
payload: Hash.keccak256(Hex.concat('0x04', hash, account)),
|
|
106
|
+
privateKey,
|
|
107
|
+
}),
|
|
108
|
+
}),
|
|
109
|
+
userAddress: account,
|
|
110
|
+
}) as SignatureEnvelope.Keychain
|
|
111
|
+
const wrapped = SignaturePreAuthorized.wrap({ keyAuthorization, signature })
|
|
112
|
+
const unwrapped = SignaturePreAuthorized.unwrap(wrapped)
|
|
113
|
+
expect(unwrapped.keyAuthorization).toEqual(keyAuthorization)
|
|
114
|
+
expect(SignatureEnvelope.serialize(unwrapped.signature)).toBe(
|
|
115
|
+
SignatureEnvelope.serialize(signature),
|
|
116
|
+
)
|
|
117
|
+
expect(SignaturePreAuthorized.wrap(unwrapped)).toBe(wrapped)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('error: malformed constituents', () => {
|
|
121
|
+
const { keyAuthorization, signature } =
|
|
122
|
+
SignaturePreAuthorized.unwrap(vectorWrapped)
|
|
123
|
+
expect(() =>
|
|
124
|
+
SignaturePreAuthorized.assert({
|
|
125
|
+
keyAuthorization: { signature: {} } as never,
|
|
126
|
+
signature: { inner: { type: 'secp256k1' }, type: 'keychain' } as never,
|
|
127
|
+
}),
|
|
128
|
+
).toThrowError(SignaturePreAuthorized.InvalidUnwrappedSignatureError)
|
|
129
|
+
expect(() =>
|
|
130
|
+
SignaturePreAuthorized.assert({
|
|
131
|
+
keyAuthorization,
|
|
132
|
+
signature: { ...signature, inner: { type: 'secp256k1' } } as never,
|
|
133
|
+
}),
|
|
134
|
+
).toThrowError(/malformed keychain signature/)
|
|
135
|
+
expect(() =>
|
|
136
|
+
SignaturePreAuthorized.assert({
|
|
137
|
+
keyAuthorization: { ...keyAuthorization, signature: {} } as never,
|
|
138
|
+
signature,
|
|
139
|
+
}),
|
|
140
|
+
).toThrowError(/malformed signed key authorization/)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('error: keychain V1', () => {
|
|
144
|
+
expect(() =>
|
|
145
|
+
SignaturePreAuthorized.wrap({
|
|
146
|
+
keyAuthorization,
|
|
147
|
+
signature: { ...signature, version: 'v1' },
|
|
148
|
+
}),
|
|
149
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
150
|
+
`[SignaturePreAuthorized.InvalidUnwrappedSignatureError: Value is an invalid unwrapped pre-authorized signature: keychain V1 signatures are not supported.]`,
|
|
151
|
+
)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('error: non-keychain signature', () => {
|
|
155
|
+
expect(() =>
|
|
156
|
+
SignaturePreAuthorized.wrap({
|
|
157
|
+
keyAuthorization,
|
|
158
|
+
signature: inner as never,
|
|
159
|
+
}),
|
|
160
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
161
|
+
`[SignaturePreAuthorized.InvalidUnwrappedSignatureError: Value is an invalid unwrapped pre-authorized signature: expected a keychain signature, got \`secp256k1\`.]`,
|
|
162
|
+
)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('error: configurable inner signature', () => {
|
|
166
|
+
expect(() =>
|
|
167
|
+
SignaturePreAuthorized.wrap({
|
|
168
|
+
keyAuthorization,
|
|
169
|
+
signature: {
|
|
170
|
+
...signature,
|
|
171
|
+
inner: {
|
|
172
|
+
account,
|
|
173
|
+
config: {} as never,
|
|
174
|
+
signatures: [],
|
|
175
|
+
type: 'configurable',
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
180
|
+
`[SignaturePreAuthorized.InvalidUnwrappedSignatureError: Value is an invalid unwrapped pre-authorized signature: expected a secp256k1, p256, or webAuthn inner signature, got \`configurable\`.]`,
|
|
181
|
+
)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('error: unsigned key authorization', () => {
|
|
185
|
+
expect(() =>
|
|
186
|
+
SignaturePreAuthorized.wrap({
|
|
187
|
+
keyAuthorization: authorization as never,
|
|
188
|
+
signature,
|
|
189
|
+
}),
|
|
190
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
191
|
+
`[SignaturePreAuthorized.InvalidUnwrappedSignatureError: Value is an invalid unwrapped pre-authorized signature: key authorization is not signed.]`,
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
describe('unwrap', () => {
|
|
197
|
+
test('TIP-1165 example vector', () => {
|
|
198
|
+
const unwrapped = SignaturePreAuthorized.unwrap(vectorWrapped)
|
|
199
|
+
expect(unwrapped).toEqual({
|
|
200
|
+
keyAuthorization,
|
|
201
|
+
signature: { ...signature, version: 'v2' },
|
|
202
|
+
})
|
|
203
|
+
expect(SignaturePreAuthorized.wrap(unwrapped)).toBe(vectorWrapped)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test('error: missing magic', () => {
|
|
207
|
+
expect(() =>
|
|
208
|
+
SignaturePreAuthorized.unwrap(Hex.slice(vectorWrapped, 0, -32)),
|
|
209
|
+
).toThrowError(SignaturePreAuthorized.InvalidWrappedSignatureError)
|
|
210
|
+
expect(() =>
|
|
211
|
+
SignaturePreAuthorized.unwrap(SignaturePreAuthorized.magicBytes),
|
|
212
|
+
).toThrowError(SignaturePreAuthorized.InvalidWrappedSignatureError)
|
|
213
|
+
expect(() =>
|
|
214
|
+
SignaturePreAuthorized.unwrap('0xdeadbeef'),
|
|
215
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
216
|
+
`[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xdeadbeef\` is an invalid pre-authorized signature.]`,
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('error: trailing bytes', () => {
|
|
221
|
+
expect(() =>
|
|
222
|
+
SignaturePreAuthorized.unwrap(
|
|
223
|
+
wrapRaw(Hex.concat(Hex.slice(vectorWrapped, 0, -32), '0x00')),
|
|
224
|
+
),
|
|
225
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
226
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8fab85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b001165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
227
|
+
|
|
228
|
+
Details: RLP payload encodes a single item, but \`1\` trailing byte remains.]
|
|
229
|
+
`)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
test('error: non-canonical list header', () => {
|
|
233
|
+
expect(() =>
|
|
234
|
+
SignaturePreAuthorized.unwrap(
|
|
235
|
+
Hex.concat('0xf900fa', Hex.slice(vectorWrapped, 2)),
|
|
236
|
+
),
|
|
237
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
238
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf900fab85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
239
|
+
|
|
240
|
+
Details: RLP payload is not canonically encoded: length \`250\` fits in fewer length-bytes and must not use a two-byte length prefix.]
|
|
241
|
+
`)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
test('error: three items', () => {
|
|
245
|
+
expect(() =>
|
|
246
|
+
SignaturePreAuthorized.unwrap(
|
|
247
|
+
wrapRaw(
|
|
248
|
+
Rlp.fromHex([
|
|
249
|
+
signatureSerialized,
|
|
250
|
+
keyAuthorizationTuple as never,
|
|
251
|
+
'0x',
|
|
252
|
+
]),
|
|
253
|
+
),
|
|
254
|
+
),
|
|
255
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
256
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8fbb85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b801165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
257
|
+
|
|
258
|
+
Details: expected an RLP list of exactly two items]
|
|
259
|
+
`)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('error: one item', () => {
|
|
263
|
+
expect(() =>
|
|
264
|
+
SignaturePreAuthorized.unwrap(
|
|
265
|
+
wrapRaw(Rlp.fromHex([signatureSerialized])),
|
|
266
|
+
),
|
|
267
|
+
).toThrowError(SignaturePreAuthorized.InvalidWrappedSignatureError)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('error: wrong item shapes', () => {
|
|
271
|
+
expect(() =>
|
|
272
|
+
SignaturePreAuthorized.unwrap(
|
|
273
|
+
wrapRaw(
|
|
274
|
+
Rlp.fromHex([[signatureSerialized], keyAuthorizationTuple as never]),
|
|
275
|
+
),
|
|
276
|
+
),
|
|
277
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
278
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8fcf858b85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
279
|
+
|
|
280
|
+
Details: keychain signature is not an RLP string]
|
|
281
|
+
`)
|
|
282
|
+
expect(() =>
|
|
283
|
+
SignaturePreAuthorized.unwrap(
|
|
284
|
+
wrapRaw(
|
|
285
|
+
Rlp.fromHex([
|
|
286
|
+
signatureSerialized,
|
|
287
|
+
KeyAuthorization.serialize(keyAuthorization),
|
|
288
|
+
]),
|
|
289
|
+
),
|
|
290
|
+
),
|
|
291
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
292
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8fcb85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cb8a2f8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
293
|
+
|
|
294
|
+
Details: signed key authorization is not an RLP list]
|
|
295
|
+
`)
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
test('error: unsigned key authorization', () => {
|
|
299
|
+
expect(() =>
|
|
300
|
+
SignaturePreAuthorized.unwrap(
|
|
301
|
+
wrapRaw(
|
|
302
|
+
Rlp.fromHex([
|
|
303
|
+
signatureSerialized,
|
|
304
|
+
KeyAuthorization.toTuple(authorization) as never,
|
|
305
|
+
]),
|
|
306
|
+
),
|
|
307
|
+
),
|
|
308
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
309
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8b7b85604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf85df85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c51165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
310
|
+
|
|
311
|
+
Details: key authorization is not signed]
|
|
312
|
+
`)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('error: keychain V1', () => {
|
|
316
|
+
expect(() =>
|
|
317
|
+
SignaturePreAuthorized.unwrap(
|
|
318
|
+
wrapRaw(
|
|
319
|
+
Rlp.fromHex([
|
|
320
|
+
Hex.concat('0x03', Hex.slice(signatureSerialized, 1)),
|
|
321
|
+
keyAuthorizationTuple as never,
|
|
322
|
+
]),
|
|
323
|
+
),
|
|
324
|
+
),
|
|
325
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
326
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8fab85603f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
327
|
+
|
|
328
|
+
Details: keychain V1 signatures are not supported]
|
|
329
|
+
`)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
test('error: non-keychain signature', () => {
|
|
333
|
+
expect(() =>
|
|
334
|
+
SignaturePreAuthorized.unwrap(
|
|
335
|
+
wrapRaw(
|
|
336
|
+
Rlp.fromHex([
|
|
337
|
+
SignatureEnvelope.serialize(inner),
|
|
338
|
+
keyAuthorizationTuple as never,
|
|
339
|
+
]),
|
|
340
|
+
),
|
|
341
|
+
),
|
|
342
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
343
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf8e5b8413dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1cf8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
344
|
+
|
|
345
|
+
Details: expected a keychain signature, got \`secp256k1\`]
|
|
346
|
+
`)
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
test('error: keychain signature with envelope magic', () => {
|
|
350
|
+
expect(() =>
|
|
351
|
+
SignaturePreAuthorized.unwrap(
|
|
352
|
+
wrapRaw(
|
|
353
|
+
Rlp.fromHex([
|
|
354
|
+
SignatureEnvelope.serialize(signature, { magic: true }),
|
|
355
|
+
keyAuthorizationTuple as never,
|
|
356
|
+
]),
|
|
357
|
+
),
|
|
358
|
+
),
|
|
359
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
360
|
+
[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xf9011ab87604f39fd6e51aad88f6f4ce6ab8827279cfffb922663dc3ccd3e78382806b81f811192a9afa9f38335c19a3897a2676008ab611d8a61c73da6988f81a2cc37c5c712f67280aeb732e45688c9347458092b772306c6c1c7777777777777777777777777777777777777777777777777777777777777777f8a0f85b821079809472989d24e6e1f0bbe29a5f304d0db21a318c012e84713fb300dad99420c00000000000000000000000000000000000018398968080a0e55f870744098e6baf2f15e0faa6f8f9de283280f26f416dee8dcf9189a553c5b841c026ad99f18042ef3ac0d7a88ffbcd910eb4ccaf435b1acf684f6eb63425909642b07095e6f94edbf489ac1909caa41b0e3eee6971862939e8403c1ab4e617ca1b1165116511651165116511651165116511651165116511651165116511651165\` is an invalid pre-authorized signature.
|
|
361
|
+
|
|
362
|
+
Details: keychain signature is not canonical]
|
|
363
|
+
`)
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
describe('assert', () => {
|
|
368
|
+
test('default', () => {
|
|
369
|
+
SignaturePreAuthorized.assert(wrapped)
|
|
370
|
+
SignaturePreAuthorized.assert({ keyAuthorization, signature })
|
|
371
|
+
expect(() =>
|
|
372
|
+
SignaturePreAuthorized.assert('0xdeadbeef'),
|
|
373
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
374
|
+
`[SignaturePreAuthorized.InvalidWrappedSignatureError: Value \`0xdeadbeef\` is an invalid pre-authorized signature.]`,
|
|
375
|
+
)
|
|
376
|
+
expect(() =>
|
|
377
|
+
SignaturePreAuthorized.assert(null as never),
|
|
378
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
379
|
+
`[SignaturePreAuthorized.InvalidUnwrappedSignatureError: Value is an invalid unwrapped pre-authorized signature: expected an object.]`,
|
|
380
|
+
)
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
describe('from', () => {
|
|
385
|
+
test('default', () => {
|
|
386
|
+
const value = { keyAuthorization, signature }
|
|
387
|
+
expect(SignaturePreAuthorized.from(value)).toBe(value)
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
test('behavior: hex', () => {
|
|
391
|
+
expect(SignaturePreAuthorized.from(wrapped)).toEqual(
|
|
392
|
+
SignaturePreAuthorized.unwrap(wrapped),
|
|
393
|
+
)
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
describe('validate', () => {
|
|
398
|
+
test('default', () => {
|
|
399
|
+
expect(SignaturePreAuthorized.validate(wrapped)).toBe(true)
|
|
400
|
+
expect(SignaturePreAuthorized.validate('0xdeadbeef')).toBe(false)
|
|
401
|
+
expect(
|
|
402
|
+
SignaturePreAuthorized.validate(
|
|
403
|
+
wrapRaw(Hex.concat(Hex.slice(wrapped, 0, -32), '0x00')),
|
|
404
|
+
),
|
|
405
|
+
).toBe(false)
|
|
406
|
+
expect(SignaturePreAuthorized.validate(Hex.concat(wrapped, '0x00'))).toBe(
|
|
407
|
+
false,
|
|
408
|
+
)
|
|
409
|
+
})
|
|
410
|
+
})
|