ox 1.8.15 → 1.8.18
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 +108 -0
- package/dist/core/AbiError.d.ts +52 -6
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +60 -4
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +5 -3
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +89 -58
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +48 -2
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +59 -3
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +15 -5
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/AbiParameters.d.ts +1 -1
- package/dist/core/AbiParameters.d.ts.map +1 -1
- package/dist/core/AbiParameters.js +8 -2
- package/dist/core/AbiParameters.js.map +1 -1
- package/dist/core/Address.d.ts +17 -2
- package/dist/core/Address.d.ts.map +1 -1
- package/dist/core/Address.js +17 -1
- package/dist/core/Address.js.map +1 -1
- package/dist/core/Authorization.d.ts +24 -2
- package/dist/core/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +29 -2
- package/dist/core/Authorization.js.map +1 -1
- package/dist/core/Base58.d.ts.map +1 -1
- package/dist/core/Base58.js +16 -4
- package/dist/core/Base58.js.map +1 -1
- package/dist/core/Blobs.d.ts +2 -3
- package/dist/core/Blobs.d.ts.map +1 -1
- package/dist/core/Blobs.js +38 -43
- package/dist/core/Blobs.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +10 -2
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Cbor.d.ts +13 -6
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +31 -18
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/Ens.js +2 -2
- package/dist/core/Ens.js.map +1 -1
- package/dist/core/FrameReceipt.d.ts.map +1 -1
- package/dist/core/FrameReceipt.js +4 -1
- package/dist/core/FrameReceipt.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +34 -31
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Keystore.d.ts +31 -2
- package/dist/core/Keystore.d.ts.map +1 -1
- package/dist/core/Keystore.js +28 -2
- package/dist/core/Keystore.js.map +1 -1
- package/dist/core/Rlp.d.ts +1 -1
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +107 -0
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +3 -1
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Secp256k1.d.ts.map +1 -1
- package/dist/core/Secp256k1.js +4 -1
- package/dist/core/Secp256k1.js.map +1 -1
- package/dist/core/Signature.d.ts +1 -1
- package/dist/core/Signature.d.ts.map +1 -1
- package/dist/core/Signature.js +4 -2
- package/dist/core/Signature.js.map +1 -1
- package/dist/core/Siwe.d.ts +4 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +29 -3
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +4 -2
- package/dist/core/Transaction.js.map +1 -1
- package/dist/core/TransactionReceipt.d.ts.map +1 -1
- package/dist/core/TransactionReceipt.js +8 -2
- package/dist/core/TransactionReceipt.js.map +1 -1
- package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip1559.js +2 -1
- package/dist/core/TxEnvelopeEip1559.js.map +1 -1
- package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip2930.js +2 -1
- package/dist/core/TxEnvelopeEip2930.js.map +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip7702.js +6 -1
- package/dist/core/TxEnvelopeEip7702.js.map +1 -1
- package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
- package/dist/core/TxEnvelopeLegacy.js +49 -7
- package/dist/core/TxEnvelopeLegacy.js.map +1 -1
- package/dist/core/TypedData.d.ts +3 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +23 -11
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +14 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +3 -3
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +99 -69
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/base58.d.ts.map +1 -1
- package/dist/core/internal/base58.js +9 -3
- package/dist/core/internal/base58.js.map +1 -1
- package/dist/core/internal/caches.d.ts +6 -0
- package/dist/core/internal/caches.d.ts.map +1 -1
- package/dist/core/internal/caches.js +3 -1
- package/dist/core/internal/caches.js.map +1 -1
- package/dist/core/internal/codec/hex.d.ts +13 -0
- package/dist/core/internal/codec/hex.d.ts.map +1 -1
- package/dist/core/internal/codec/hex.js +25 -2
- package/dist/core/internal/codec/hex.js.map +1 -1
- package/dist/core/internal/codec/int.d.ts.map +1 -1
- package/dist/core/internal/codec/int.js +48 -32
- package/dist/core/internal/codec/int.js.map +1 -1
- package/dist/core/internal/cursor.d.ts +24 -4
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +62 -11
- package/dist/core/internal/cursor.js.map +1 -1
- package/dist/core/internal/lru.d.ts +11 -12
- package/dist/core/internal/lru.d.ts.map +1 -1
- package/dist/core/internal/lru.js +22 -32
- package/dist/core/internal/lru.js.map +1 -1
- package/dist/core/internal/promise.d.ts.map +1 -1
- package/dist/core/internal/promise.js +13 -7
- package/dist/core/internal/promise.js.map +1 -1
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +1 -3
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts.map +1 -1
- package/dist/erc6492/SignatureErc6492.js +1 -1
- package/dist/erc6492/SignatureErc6492.js.map +1 -1
- package/dist/erc7821/Execute.d.ts +45 -0
- package/dist/erc7821/Execute.d.ts.map +1 -1
- package/dist/erc7821/Execute.js +70 -2
- package/dist/erc7821/Execute.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +9 -3
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +16 -0
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +53 -54
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
- package/dist/tempo/TransactionReceipt.js +4 -1
- package/dist/tempo/TransactionReceipt.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +1 -1
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +5 -2
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +51 -2
- package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/tempo/ZoneId.d.ts +3 -1
- package/dist/tempo/ZoneId.d.ts.map +1 -1
- package/dist/tempo/ZoneId.js +7 -1
- package/dist/tempo/ZoneId.js.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.d.ts.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.js +17 -6
- package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
- package/dist/tempo/internal/webauthnData.d.ts +23 -0
- package/dist/tempo/internal/webauthnData.d.ts.map +1 -0
- package/dist/tempo/internal/webauthnData.js +75 -0
- package/dist/tempo/internal/webauthnData.js.map +1 -0
- package/dist/webauthn/Registration.d.ts +2 -0
- package/dist/webauthn/Registration.d.ts.map +1 -1
- package/dist/webauthn/Registration.js +2 -6
- package/dist/webauthn/Registration.js.map +1 -1
- package/dist/zod/TypedData.d.ts +4 -4
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +4 -2
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +29 -29
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/package.json +2 -2
- package/src/core/AbiError.ts +82 -8
- package/src/core/AbiEvent.bench.ts +45 -0
- package/src/core/AbiEvent.ts +120 -68
- package/src/core/AbiFunction.bench.ts +16 -0
- package/src/core/AbiFunction.ts +76 -4
- package/src/core/AbiItem.ts +13 -4
- package/src/core/AbiParameters.bench.ts +33 -0
- package/src/core/AbiParameters.ts +8 -1
- package/src/core/Address.ts +18 -1
- package/src/core/Authorization.ts +34 -4
- package/src/core/Base58.bench.ts +28 -0
- package/src/core/Base58.ts +15 -4
- package/src/core/Blobs.bench.ts +40 -0
- package/src/core/Blobs.ts +47 -55
- package/src/core/Bytes.bench.ts +34 -0
- package/src/core/Bytes.ts +10 -2
- package/src/core/Cbor.ts +36 -14
- package/src/core/Ens.ts +2 -2
- package/src/core/FrameReceipt.ts +4 -1
- package/src/core/Hex.bench.ts +17 -0
- package/src/core/Hex.ts +29 -32
- package/src/core/Keystore.ts +40 -3
- package/src/core/Rlp.ts +139 -1
- package/src/core/Rlp_tx.bench.ts +55 -0
- package/src/core/RpcTransport.ts +3 -1
- package/src/core/Secp256k1.ts +4 -1
- package/src/core/Signature.ts +7 -3
- package/src/core/Siwe.ts +29 -3
- package/src/core/Transaction.ts +4 -2
- package/src/core/TransactionReceipt.ts +8 -2
- package/src/core/TxEnvelopeEip1559.ts +4 -1
- package/src/core/TxEnvelopeEip2930.ts +4 -1
- package/src/core/TxEnvelopeEip7702.ts +9 -2
- package/src/core/TxEnvelopeLegacy.ts +58 -7
- package/src/core/TypedData.bench.ts +50 -0
- package/src/core/TypedData.ts +24 -11
- package/src/core/Value.ts +14 -3
- package/src/core/_test/AbiError.test.ts +105 -2
- package/src/core/_test/AbiEvent.fuzz.ts +1 -1
- package/src/core/_test/AbiEvent.test-d.ts +46 -0
- package/src/core/_test/AbiEvent.test.ts +646 -11
- package/src/core/_test/AbiFunction.test.ts +79 -6
- package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
- package/src/core/_test/AbiParameters.decode.test.ts +143 -0
- package/src/core/_test/AbiParameters.encode.test.ts +36 -1
- package/src/core/_test/AbiParameters.test.ts +15 -0
- package/src/core/_test/Address.test.ts +41 -0
- package/src/core/_test/Authorization.test.ts +130 -0
- package/src/core/_test/Bytes.test.ts +33 -0
- package/src/core/_test/Caches.test.ts +20 -1
- package/src/core/_test/Cbor.test.ts +26 -0
- package/src/core/_test/FrameReceipt.test.ts +13 -0
- package/src/core/_test/Keystore.test.ts +65 -1
- package/src/core/_test/Rlp.fuzz.ts +55 -1
- package/src/core/_test/Rlp.test.ts +64 -0
- package/src/core/_test/RpcTransport.test.ts +15 -2
- package/src/core/_test/Secp256k1.test.ts +36 -0
- package/src/core/_test/Signature.test.ts +102 -0
- package/src/core/_test/Siwe.test.ts +123 -0
- package/src/core/_test/Transaction.test.ts +17 -0
- package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
- package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
- package/src/core/_test/TransactionReceipt.test.ts +41 -0
- package/src/core/_test/TypedData.test.ts +197 -0
- package/src/core/_test/Value.test.ts +21 -0
- package/src/core/_test/internal/cursor.test.ts +71 -0
- package/src/core/internal/abiParameters.ts +123 -81
- package/src/core/internal/base58.ts +9 -3
- package/src/core/internal/caches.ts +3 -1
- package/src/core/internal/codec/hex.ts +27 -2
- package/src/core/internal/codec/int.ts +45 -32
- package/src/core/internal/cursor.ts +84 -19
- package/src/core/internal/lru.ts +21 -35
- package/src/core/internal/promise.ts +11 -5
- package/src/erc4337/UserOperation.ts +3 -4
- package/src/erc4337/_test/UserOperation.test.ts +59 -1
- package/src/erc6492/SignatureErc6492.ts +1 -1
- package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
- package/src/erc7821/Execute.ts +83 -2
- package/src/erc7821/_test/Execute.test.ts +217 -1
- package/src/index.ts +1 -1
- package/src/tempo/KeyAuthorization.test.ts +91 -0
- package/src/tempo/KeyAuthorization.ts +32 -3
- package/src/tempo/SignatureEnvelope.test.ts +300 -28
- package/src/tempo/SignatureEnvelope.ts +62 -54
- package/src/tempo/TransactionReceipt.test.ts +8 -0
- package/src/tempo/TransactionReceipt.ts +4 -1
- package/src/tempo/TransactionRequest.test.ts +30 -0
- package/src/tempo/TransactionRequest.ts +7 -2
- package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
- package/src/tempo/TxEnvelopeTempo.ts +64 -1
- package/src/tempo/VirtualMaster.bench.ts +7 -0
- package/src/tempo/ZoneId.test.ts +11 -0
- package/src/tempo/ZoneId.ts +7 -1
- package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
- package/src/tempo/internal/virtualMasterPool.ts +20 -6
- package/src/tempo/internal/webauthnData.ts +84 -0
- package/src/version.ts +1 -1
- package/src/webauthn/Registration.ts +4 -6
- package/src/webauthn/_test/Registration.browser.test.ts +14 -0
- package/src/webauthn/_test/Registration.test.ts +60 -0
- package/src/zod/tempo/KeyAuthorization.ts +12 -5
- package/src/zod/tempo/SignatureEnvelope.ts +38 -32
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +138 -4
- package/src/core/_test/internal/lru.test.ts +0 -38
- package/src/core/_test/internal/uid.test.ts +0 -7
- package/src/core/internal/uid.ts +0 -15
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as Bytes from '../../core/Bytes.js'
|
|
2
|
+
import * as Hex from '../../core/Hex.js'
|
|
3
|
+
|
|
4
|
+
/** Minimum size of `authenticatorData`: rpIdHash (32) + flags (1) + signCount (4). */
|
|
5
|
+
const minAuthenticatorDataSize = 37
|
|
6
|
+
|
|
7
|
+
const backslash = 0x5c
|
|
8
|
+
const closeBrace = 0x7d
|
|
9
|
+
const openBrace = 0x7b
|
|
10
|
+
const quote = 0x22
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Splits WebAuthn data (`authenticatorData || clientDataJSON`) into its parts.
|
|
14
|
+
*
|
|
15
|
+
* `clientDataJSON` is the JSON object that ends at the last byte, so its
|
|
16
|
+
* opening brace is the one that pairs with the last byte. One backward pass
|
|
17
|
+
* finds that brace and one `JSON.parse` validates the object, which keeps the
|
|
18
|
+
* work linear in the size of the data.
|
|
19
|
+
*
|
|
20
|
+
* @param webauthnData - The concatenated WebAuthn data.
|
|
21
|
+
* @returns The parts, or `undefined` when the data does not end with a JSON
|
|
22
|
+
* object that starts at or after byte 37.
|
|
23
|
+
*/
|
|
24
|
+
export function split(webauthnData: Hex.Hex): split.ReturnType | undefined {
|
|
25
|
+
if (Hex.size(webauthnData) <= minAuthenticatorDataSize) return undefined
|
|
26
|
+
|
|
27
|
+
// `clientDataJSON` starts after the minimum `authenticatorData`.
|
|
28
|
+
const bytes = Bytes.fromHex(Hex.slice(webauthnData, minAuthenticatorDataSize))
|
|
29
|
+
const start = objectStart(bytes)
|
|
30
|
+
if (start === -1) return undefined
|
|
31
|
+
|
|
32
|
+
const clientDataJSON = Bytes.toString(bytes.subarray(start))
|
|
33
|
+
try {
|
|
34
|
+
JSON.parse(clientDataJSON)
|
|
35
|
+
} catch {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
authenticatorData: Hex.slice(
|
|
40
|
+
webauthnData,
|
|
41
|
+
0,
|
|
42
|
+
minAuthenticatorDataSize + start,
|
|
43
|
+
),
|
|
44
|
+
clientDataJSON,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export declare namespace split {
|
|
49
|
+
type ReturnType = {
|
|
50
|
+
/** Authenticator data. */
|
|
51
|
+
authenticatorData: Hex.Hex
|
|
52
|
+
/** Client data JSON. */
|
|
53
|
+
clientDataJSON: string
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Finds the opening brace that pairs with a closing brace in the last byte,
|
|
59
|
+
* or returns `-1`. Scans bytes rather than characters: UTF-8 never encodes a
|
|
60
|
+
* multi-byte character with an ASCII byte, so each structural byte is a
|
|
61
|
+
* structural character.
|
|
62
|
+
*/
|
|
63
|
+
function objectStart(bytes: Bytes.Bytes) {
|
|
64
|
+
if (bytes[bytes.length - 1] !== closeBrace) return -1
|
|
65
|
+
|
|
66
|
+
let depth = 0
|
|
67
|
+
let inString = false
|
|
68
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
69
|
+
const byte = bytes[i]
|
|
70
|
+
if (byte === quote) {
|
|
71
|
+
if (inString) {
|
|
72
|
+
// A quote inside a string follows an odd number of backslashes.
|
|
73
|
+
let escapes = 0
|
|
74
|
+
while (bytes[i - 1 - escapes] === backslash) escapes++
|
|
75
|
+
i -= escapes
|
|
76
|
+
if (escapes % 2 === 1) continue
|
|
77
|
+
}
|
|
78
|
+
inString = !inString
|
|
79
|
+
} else if (inString) continue
|
|
80
|
+
else if (byte === closeBrace) depth++
|
|
81
|
+
else if (byte === openBrace && --depth === 0) return i
|
|
82
|
+
}
|
|
83
|
+
return -1
|
|
84
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.8.
|
|
2
|
+
export const version = '1.8.18'
|
|
@@ -30,7 +30,9 @@ export type Response<serialized extends boolean = false> = {
|
|
|
30
30
|
credential: Credential_.Credential<serialized>
|
|
31
31
|
counter: number
|
|
32
32
|
userVerified?: true | undefined
|
|
33
|
+
/** Whether the credential is currently backed up (BS flag). */
|
|
33
34
|
backedUp?: boolean | undefined
|
|
35
|
+
/** `'multiDevice'` if the credential is backup eligible (BE flag), otherwise `'singleDevice'`. */
|
|
34
36
|
deviceType?: 'multiDevice' | 'singleDevice' | undefined
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -754,12 +756,8 @@ export function verify(options: verify.Options): verify.ReturnType {
|
|
|
754
756
|
},
|
|
755
757
|
counter,
|
|
756
758
|
...(uv ? { userVerified: true as const } : {}),
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
? {
|
|
760
|
-
deviceType: bs ? ('multiDevice' as const) : ('singleDevice' as const),
|
|
761
|
-
}
|
|
762
|
-
: {}),
|
|
759
|
+
backedUp: bs,
|
|
760
|
+
deviceType: be ? 'multiDevice' : 'singleDevice',
|
|
763
761
|
}
|
|
764
762
|
}
|
|
765
763
|
|
|
@@ -303,6 +303,20 @@ describe('behavior: BE/BS flag consistency', () => {
|
|
|
303
303
|
rpId,
|
|
304
304
|
})
|
|
305
305
|
|
|
306
|
+
expect(result.backedUp).toBe(false)
|
|
307
|
+
expect(result.deviceType).toBe('multiDevice')
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
test('accepts BE + BS both not set', () => {
|
|
311
|
+
const { credential, challenge } = buildPackedCredential({ flag: 0x45 })
|
|
312
|
+
|
|
313
|
+
const result = Registration.verify({
|
|
314
|
+
credential,
|
|
315
|
+
challenge,
|
|
316
|
+
origin: window.location.origin,
|
|
317
|
+
rpId,
|
|
318
|
+
})
|
|
319
|
+
|
|
306
320
|
expect(result.backedUp).toBe(false)
|
|
307
321
|
expect(result.deviceType).toBe('singleDevice')
|
|
308
322
|
})
|
|
@@ -988,6 +988,66 @@ describe('verify', () => {
|
|
|
988
988
|
).toThrow('Backup state (BS) flag is set but backup eligibility (BE)')
|
|
989
989
|
})
|
|
990
990
|
|
|
991
|
+
test('behavior: BE flag not set', async () => {
|
|
992
|
+
const { credential, challenge, origin, rpId } = await mockCreateCredential({
|
|
993
|
+
flag: 0x45,
|
|
994
|
+
}) // UP + UV + AT
|
|
995
|
+
|
|
996
|
+
const { backedUp, deviceType } = Registration.verify({
|
|
997
|
+
credential,
|
|
998
|
+
challenge,
|
|
999
|
+
origin,
|
|
1000
|
+
rpId,
|
|
1001
|
+
})
|
|
1002
|
+
|
|
1003
|
+
expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
|
|
1004
|
+
{
|
|
1005
|
+
"backedUp": false,
|
|
1006
|
+
"deviceType": "singleDevice",
|
|
1007
|
+
}
|
|
1008
|
+
`)
|
|
1009
|
+
})
|
|
1010
|
+
|
|
1011
|
+
test('behavior: BE flag set without BS flag', async () => {
|
|
1012
|
+
const { credential, challenge, origin, rpId } = await mockCreateCredential({
|
|
1013
|
+
flag: 0x4d,
|
|
1014
|
+
}) // UP + UV + AT + BE
|
|
1015
|
+
|
|
1016
|
+
const { backedUp, deviceType } = Registration.verify({
|
|
1017
|
+
credential,
|
|
1018
|
+
challenge,
|
|
1019
|
+
origin,
|
|
1020
|
+
rpId,
|
|
1021
|
+
})
|
|
1022
|
+
|
|
1023
|
+
expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
|
|
1024
|
+
{
|
|
1025
|
+
"backedUp": false,
|
|
1026
|
+
"deviceType": "multiDevice",
|
|
1027
|
+
}
|
|
1028
|
+
`)
|
|
1029
|
+
})
|
|
1030
|
+
|
|
1031
|
+
test('behavior: BE + BS flags set', async () => {
|
|
1032
|
+
const { credential, challenge, origin, rpId } = await mockCreateCredential({
|
|
1033
|
+
flag: 0x5d,
|
|
1034
|
+
}) // UP + UV + AT + BE + BS
|
|
1035
|
+
|
|
1036
|
+
const { backedUp, deviceType } = Registration.verify({
|
|
1037
|
+
credential,
|
|
1038
|
+
challenge,
|
|
1039
|
+
origin,
|
|
1040
|
+
rpId,
|
|
1041
|
+
})
|
|
1042
|
+
|
|
1043
|
+
expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
|
|
1044
|
+
{
|
|
1045
|
+
"backedUp": true,
|
|
1046
|
+
"deviceType": "multiDevice",
|
|
1047
|
+
}
|
|
1048
|
+
`)
|
|
1049
|
+
})
|
|
1050
|
+
|
|
991
1051
|
test('error: credential ID mismatch', async () => {
|
|
992
1052
|
const { credential, challenge, origin, rpId } = await mockCreateCredential()
|
|
993
1053
|
|
|
@@ -63,11 +63,18 @@ export const TokenLimitToRpc = z.object({
|
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
/** Call scope schema. */
|
|
66
|
-
export const Scope = z
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
export const Scope = z
|
|
67
|
+
.object({
|
|
68
|
+
address: z_Address.Address,
|
|
69
|
+
recipients: z.optional(z.readonly(z.array(z_Address.Address))),
|
|
70
|
+
selector: z.optional(z.union([z_Hex.Hex, z.string()])),
|
|
71
|
+
})
|
|
72
|
+
.check(
|
|
73
|
+
z.refine(
|
|
74
|
+
(value) => Boolean(value.selector) || !value.recipients?.length,
|
|
75
|
+
'recipients require a selector',
|
|
76
|
+
),
|
|
77
|
+
)
|
|
71
78
|
|
|
72
79
|
const domainShape = {
|
|
73
80
|
address: z_Address.Address,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as core_SignatureEnvelope from '../../tempo/SignatureEnvelope.js'
|
|
3
3
|
import * as core_Hex from '../../core/Hex.js'
|
|
4
4
|
import * as core_AccountConfig from '../../tempo/AccountConfig.js'
|
|
5
|
+
import * as core_WebauthnData from '../../tempo/internal/webauthnData.js'
|
|
5
6
|
import * as z_Address from '../Address.js'
|
|
6
7
|
import * as z_Hex from '../Hex.js'
|
|
7
8
|
import * as z_AccountConfig from './AccountConfig.js'
|
|
@@ -40,13 +41,24 @@ const Signature = z.object({
|
|
|
40
41
|
})
|
|
41
42
|
|
|
42
43
|
/** RPC secp256k1 signature envelope schema. */
|
|
43
|
-
export const Secp256k1Rpc = z
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
export const Secp256k1Rpc = z
|
|
45
|
+
.object({
|
|
46
|
+
r: z_Hex.Hex,
|
|
47
|
+
s: z_Hex.Hex,
|
|
48
|
+
type: z.literal('secp256k1'),
|
|
49
|
+
v: z.optional(z_Hex.Hex),
|
|
50
|
+
yParity: z.optional(z_Hex.Hex),
|
|
51
|
+
})
|
|
52
|
+
.check(
|
|
53
|
+
z.refine((value) => {
|
|
54
|
+
try {
|
|
55
|
+
toYParity(value.v, value.yParity)
|
|
56
|
+
return true
|
|
57
|
+
} catch {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
}, 'expected yParity or supported v'),
|
|
61
|
+
)
|
|
50
62
|
|
|
51
63
|
/** RPC P256 signature envelope schema. */
|
|
52
64
|
export const P256Rpc = z.object({
|
|
@@ -65,7 +77,13 @@ export const WebAuthnRpc = z.object({
|
|
|
65
77
|
r: z_Hex.Hex,
|
|
66
78
|
s: z_Hex.Hex,
|
|
67
79
|
type: z.literal('webAuthn'),
|
|
68
|
-
|
|
80
|
+
// 2048-byte WebAuthn signature limit minus the 128-byte signature and public key.
|
|
81
|
+
webauthnData: z_Hex.Hex.check(
|
|
82
|
+
z.refine(
|
|
83
|
+
(value) => core_Hex.size(value) <= 1920,
|
|
84
|
+
'expected at most 1920 bytes',
|
|
85
|
+
),
|
|
86
|
+
),
|
|
69
87
|
})
|
|
70
88
|
|
|
71
89
|
/** RPC primitive signature envelope schema. */
|
|
@@ -324,32 +342,20 @@ function toYParity(
|
|
|
324
342
|
v: core_Hex.Hex | undefined,
|
|
325
343
|
yParity: core_Hex.Hex | undefined,
|
|
326
344
|
) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
return yParity_ as 0 | 1
|
|
345
|
+
if (yParity) return Number(yParity) as 0 | 1
|
|
346
|
+
const v_ = v && v !== '0x' ? BigInt(v) : undefined
|
|
347
|
+
if (v_ === 0n || v_ === 27n) return 0
|
|
348
|
+
if (v_ === 1n || v_ === 28n) return 1
|
|
349
|
+
if (typeof v_ === 'bigint' && v_ >= 35n) return v_ % 2n === 0n ? 1 : 0
|
|
350
|
+
throw new Error('Unable to derive yParity: expected yParity or supported v')
|
|
335
351
|
}
|
|
336
352
|
|
|
337
353
|
/** Parses concatenated WebAuthn metadata into its component parts. */
|
|
338
354
|
function parseWebauthnData(webauthnData: core_Hex.Hex) {
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
authenticatorData: core_Hex.slice(webauthnData, 0, split),
|
|
347
|
-
clientDataJSON: potentialJson,
|
|
348
|
-
}
|
|
349
|
-
} catch {}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
throw new Error(
|
|
353
|
-
'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
|
|
354
|
-
)
|
|
355
|
+
const metadata = core_WebauthnData.split(webauthnData)
|
|
356
|
+
if (!metadata)
|
|
357
|
+
throw new Error(
|
|
358
|
+
'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
|
|
359
|
+
)
|
|
360
|
+
return metadata
|
|
355
361
|
}
|
|
@@ -171,6 +171,42 @@ describe('KeyAuthorization', () => {
|
|
|
171
171
|
).toBe(false)
|
|
172
172
|
})
|
|
173
173
|
|
|
174
|
+
test('rejects recipients without a selector', () => {
|
|
175
|
+
const address = '0x20c0000000000000000000000000000000000001'
|
|
176
|
+
const recipients = ['0x1111111111111111111111111111111111111111']
|
|
177
|
+
expect(
|
|
178
|
+
z.safeParse(z_KeyAuthorization.Scope, { address, recipients }).error
|
|
179
|
+
?.issues,
|
|
180
|
+
).toMatchInlineSnapshot(`
|
|
181
|
+
[
|
|
182
|
+
{
|
|
183
|
+
"code": "custom",
|
|
184
|
+
"message": "recipients require a selector",
|
|
185
|
+
"path": [],
|
|
186
|
+
},
|
|
187
|
+
]
|
|
188
|
+
`)
|
|
189
|
+
expect(
|
|
190
|
+
z.safeEncode(z_KeyAuthorization.KeyAuthorization, {
|
|
191
|
+
...core_KeyAuthorization.fromRpc(rpc),
|
|
192
|
+
scopes: [{ address, recipients }],
|
|
193
|
+
} as never).success,
|
|
194
|
+
).toBe(false)
|
|
195
|
+
expect(
|
|
196
|
+
[
|
|
197
|
+
{ address },
|
|
198
|
+
{ address, recipients: [] },
|
|
199
|
+
{ address, recipients, selector: '0xa9059cbb' },
|
|
200
|
+
].map((scope) => z.safeParse(z_KeyAuthorization.Scope, scope).success),
|
|
201
|
+
).toMatchInlineSnapshot(`
|
|
202
|
+
[
|
|
203
|
+
true,
|
|
204
|
+
true,
|
|
205
|
+
true,
|
|
206
|
+
]
|
|
207
|
+
`)
|
|
208
|
+
})
|
|
209
|
+
|
|
174
210
|
test('rejects legacy signatures without a config', () => {
|
|
175
211
|
const legacyRpc = {
|
|
176
212
|
account: '0x1111111111111111111111111111111111111111',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vp/test'
|
|
1
|
+
import { describe, expect, onTestFinished, test, vi } from 'vp/test'
|
|
2
|
+
import * as core_Hex from '../../../core/Hex.js'
|
|
2
3
|
import * as core_SignatureEnvelope from '../../../tempo/SignatureEnvelope.js'
|
|
3
4
|
import * as z_SignatureEnvelope from '../SignatureEnvelope.js'
|
|
4
5
|
import * as z from 'zod/mini'
|
|
@@ -49,6 +50,78 @@ describe('SignatureEnvelope', () => {
|
|
|
49
50
|
)
|
|
50
51
|
})
|
|
51
52
|
|
|
53
|
+
test('rejects WebAuthn data above the maximum size', () => {
|
|
54
|
+
const webAuthn = {
|
|
55
|
+
pubKeyX: p256.pubKeyX,
|
|
56
|
+
pubKeyY: p256.pubKeyY,
|
|
57
|
+
r: p256.r,
|
|
58
|
+
s: p256.s,
|
|
59
|
+
type: 'webAuthn',
|
|
60
|
+
} as const
|
|
61
|
+
// 37 (authenticatorData) + 16 + length (clientDataJSON) bytes
|
|
62
|
+
const webauthnData = (length: number) =>
|
|
63
|
+
core_Hex.concat(
|
|
64
|
+
`0x${'00'.repeat(37)}`,
|
|
65
|
+
core_Hex.fromString(JSON.stringify({ challenge: 'a'.repeat(length) })),
|
|
66
|
+
)
|
|
67
|
+
const max = { ...webAuthn, webauthnData: webauthnData(1867) }
|
|
68
|
+
expect(z.decode(z_SignatureEnvelope.SignatureEnvelope, max)).toEqual(
|
|
69
|
+
core_SignatureEnvelope.fromRpc(max),
|
|
70
|
+
)
|
|
71
|
+
expect(
|
|
72
|
+
z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
|
|
73
|
+
...webAuthn,
|
|
74
|
+
webauthnData: webauthnData(1868),
|
|
75
|
+
}).error?.issues,
|
|
76
|
+
).toMatchInlineSnapshot(`
|
|
77
|
+
[
|
|
78
|
+
{
|
|
79
|
+
"code": "custom",
|
|
80
|
+
"message": "expected at most 1920 bytes",
|
|
81
|
+
"path": [
|
|
82
|
+
"webauthnData",
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
`)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('decodes and parses WebAuthn data at most once', () => {
|
|
90
|
+
// Each opening brace starts an object that only fails to parse past its
|
|
91
|
+
// end, so a search that tries every split offset reads all of it each time.
|
|
92
|
+
const clientDataJSON = `${'{"a":'.repeat(313)}${'}'.repeat(313)}`
|
|
93
|
+
const webAuthn = {
|
|
94
|
+
pubKeyX: p256.pubKeyX,
|
|
95
|
+
pubKeyY: p256.pubKeyY,
|
|
96
|
+
r: p256.r,
|
|
97
|
+
s: p256.s,
|
|
98
|
+
type: 'webAuthn',
|
|
99
|
+
webauthnData: core_Hex.concat(
|
|
100
|
+
`0x${'00'.repeat(37)}`,
|
|
101
|
+
core_Hex.fromString(clientDataJSON),
|
|
102
|
+
),
|
|
103
|
+
} as const
|
|
104
|
+
|
|
105
|
+
const decode = vi.spyOn(TextDecoder.prototype, 'decode')
|
|
106
|
+
const parse = vi.spyOn(JSON, 'parse')
|
|
107
|
+
onTestFinished(() => {
|
|
108
|
+
vi.restoreAllMocks()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
expect(() =>
|
|
112
|
+
z.decode(z_SignatureEnvelope.SignatureEnvelope, webAuthn),
|
|
113
|
+
).toThrow('Unable to parse WebAuthn metadata')
|
|
114
|
+
expect(
|
|
115
|
+
decode.mock.calls.reduce(
|
|
116
|
+
(size, [input]) => size + (input?.byteLength ?? 0),
|
|
117
|
+
0,
|
|
118
|
+
),
|
|
119
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
120
|
+
expect(
|
|
121
|
+
parse.mock.calls.reduce((size, [text]) => size + text.length, 0),
|
|
122
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
123
|
+
})
|
|
124
|
+
|
|
52
125
|
test('decodes a recursive keychain envelope', () => {
|
|
53
126
|
const keychain = {
|
|
54
127
|
signature: secp256k1,
|
|
@@ -140,10 +213,71 @@ describe('SignatureEnvelope', () => {
|
|
|
140
213
|
),
|
|
141
214
|
).toEqual(rpc)
|
|
142
215
|
})
|
|
216
|
+
|
|
217
|
+
test('derives yParity from v when yParity is omitted', () => {
|
|
218
|
+
const { yParity: _, ...rest } = secp256k1
|
|
219
|
+
expect(
|
|
220
|
+
(
|
|
221
|
+
[
|
|
222
|
+
'0x0',
|
|
223
|
+
'0x1',
|
|
224
|
+
'0x1b',
|
|
225
|
+
'0x1c',
|
|
226
|
+
'0x25',
|
|
227
|
+
'0x26',
|
|
228
|
+
'0x1fffffffffffff',
|
|
229
|
+
'0x20000000000001',
|
|
230
|
+
'0x20000000000002',
|
|
231
|
+
'0xffffffffffffffff',
|
|
232
|
+
] as const
|
|
233
|
+
).map(
|
|
234
|
+
(v) =>
|
|
235
|
+
(
|
|
236
|
+
z.decode(z_SignatureEnvelope.SignatureEnvelope, {
|
|
237
|
+
...rest,
|
|
238
|
+
v,
|
|
239
|
+
}) as core_SignatureEnvelope.Secp256k1
|
|
240
|
+
).signature.yParity,
|
|
241
|
+
),
|
|
242
|
+
).toMatchInlineSnapshot(`
|
|
243
|
+
[
|
|
244
|
+
0,
|
|
245
|
+
1,
|
|
246
|
+
0,
|
|
247
|
+
1,
|
|
248
|
+
0,
|
|
249
|
+
1,
|
|
250
|
+
0,
|
|
251
|
+
0,
|
|
252
|
+
1,
|
|
253
|
+
0,
|
|
254
|
+
]
|
|
255
|
+
`)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
test('prefers yParity over v', () => {
|
|
259
|
+
expect(
|
|
260
|
+
z.decode(z_SignatureEnvelope.SignatureEnvelope, {
|
|
261
|
+
...secp256k1,
|
|
262
|
+
v: '0x1c',
|
|
263
|
+
}),
|
|
264
|
+
).toEqual(core_SignatureEnvelope.fromRpc(secp256k1))
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
test('rejects secp256k1 envelopes without yParity or a supported v', () => {
|
|
268
|
+
const { yParity: _, ...rest } = secp256k1
|
|
269
|
+
for (const v of ['0x2', '0x1a', '0x1d', '0x22', '0x', undefined])
|
|
270
|
+
expect(
|
|
271
|
+
z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
|
|
272
|
+
...rest,
|
|
273
|
+
...(v ? { v } : {}),
|
|
274
|
+
} as never).success,
|
|
275
|
+
).toMatchInlineSnapshot(`false`)
|
|
276
|
+
})
|
|
143
277
|
})
|
|
144
278
|
|
|
145
279
|
describe('Keychain', () => {
|
|
146
|
-
test('rejects
|
|
280
|
+
test('rejects keychain wrappers around keychain-wrapped configurable delegates', () => {
|
|
147
281
|
const inner = {
|
|
148
282
|
inner: envelope,
|
|
149
283
|
type: 'keychain',
|
|
@@ -179,12 +313,12 @@ describe('Keychain', () => {
|
|
|
179
313
|
...value,
|
|
180
314
|
version: 'v2',
|
|
181
315
|
}).success,
|
|
182
|
-
).toMatchInlineSnapshot(`
|
|
316
|
+
).toMatchInlineSnapshot(`false`)
|
|
183
317
|
expect(
|
|
184
318
|
z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
|
|
185
319
|
...rpc,
|
|
186
320
|
version: 'v2',
|
|
187
321
|
}).success,
|
|
188
|
-
).toMatchInlineSnapshot(`
|
|
322
|
+
).toMatchInlineSnapshot(`false`)
|
|
189
323
|
})
|
|
190
324
|
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vp/test'
|
|
2
|
-
import { LruMap } from '../../internal/lru.js'
|
|
3
|
-
|
|
4
|
-
test('default', () => {
|
|
5
|
-
const cache = new LruMap(5)
|
|
6
|
-
cache.set('a', 1)
|
|
7
|
-
cache.set('b', 2)
|
|
8
|
-
cache.set('c', 3)
|
|
9
|
-
cache.set('d', 4)
|
|
10
|
-
cache.set('e', 5)
|
|
11
|
-
cache.set('f', 6)
|
|
12
|
-
cache.set('g', 7)
|
|
13
|
-
expect(cache.size).toBe(5)
|
|
14
|
-
expect(cache.has('a')).toBe(false)
|
|
15
|
-
expect(cache.has('b')).toBe(false)
|
|
16
|
-
expect(cache.get('c')).toBe(3)
|
|
17
|
-
expect(cache.get('d')).toBe(4)
|
|
18
|
-
expect(cache.get('e')).toBe(5)
|
|
19
|
-
expect(cache.get('f')).toBe(6)
|
|
20
|
-
expect(cache.get('g')).toBe(7)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('update touched keys', () => {
|
|
24
|
-
const cache = new LruMap(5)
|
|
25
|
-
cache.set('a', 1)
|
|
26
|
-
cache.set('b', 2)
|
|
27
|
-
cache.set('c', 3)
|
|
28
|
-
cache.set('d', 4)
|
|
29
|
-
cache.set('e', 5)
|
|
30
|
-
expect(cache.size).toBe(5)
|
|
31
|
-
cache.get('a')
|
|
32
|
-
cache.set('f', 6)
|
|
33
|
-
cache.set('g', 7)
|
|
34
|
-
expect(cache.has('a')).toBe(true)
|
|
35
|
-
expect(cache.has('b')).toBe(false)
|
|
36
|
-
expect(cache.has('c')).toBe(false)
|
|
37
|
-
expect(cache.has('d')).toBe(true)
|
|
38
|
-
})
|
package/src/core/internal/uid.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const size = 256
|
|
2
|
-
let index = size
|
|
3
|
-
let buffer: string
|
|
4
|
-
|
|
5
|
-
/** @internal */
|
|
6
|
-
export function uid(length = 11) {
|
|
7
|
-
if (!buffer || index + length > size * 2) {
|
|
8
|
-
buffer = ''
|
|
9
|
-
index = 0
|
|
10
|
-
for (let i = 0; i < size; i++) {
|
|
11
|
-
buffer += ((256 + Math.random() * 256) | 0).toString(16).substring(1)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return buffer.substring(index, index++ + length)
|
|
15
|
-
}
|