ox 1.1.2 → 1.3.0
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 +61 -0
- package/dist/core/AbiFunction.d.ts +1 -1
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +6 -2
- package/dist/core/AbiFunction.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 +1 -13
- package/dist/core/AbiParameters.js.map +1 -1
- package/dist/core/AesGcm.d.ts +36 -1
- package/dist/core/AesGcm.d.ts.map +1 -1
- package/dist/core/AesGcm.js +44 -0
- package/dist/core/AesGcm.js.map +1 -1
- package/dist/core/Ed25519.d.ts +46 -1
- package/dist/core/Ed25519.d.ts.map +1 -1
- package/dist/core/Ed25519.js +43 -0
- package/dist/core/Ed25519.js.map +1 -1
- package/dist/core/Engine.d.ts +1 -1
- package/dist/core/Engine.d.ts.map +1 -1
- package/dist/core/Engine.js.map +1 -1
- package/dist/core/Hash.d.ts +200 -1
- package/dist/core/Hash.d.ts.map +1 -1
- package/dist/core/Hash.js +207 -0
- package/dist/core/Hash.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +1 -4
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Rlp.d.ts +32 -0
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +146 -0
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/Secp256k1.d.ts +46 -1
- package/dist/core/Secp256k1.d.ts.map +1 -1
- package/dist/core/Secp256k1.js +48 -0
- package/dist/core/Secp256k1.js.map +1 -1
- package/dist/core/WebAuthn.d.ts +224 -0
- package/dist/core/WebAuthn.d.ts.map +1 -0
- package/dist/core/WebAuthn.js +343 -0
- package/dist/core/WebAuthn.js.map +1 -0
- package/dist/core/WebAuthnP256.d.ts +46 -50
- package/dist/core/WebAuthnP256.d.ts.map +1 -1
- package/dist/core/WebAuthnP256.js +44 -50
- package/dist/core/WebAuthnP256.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +7 -87
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +339 -194
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/engine.d.ts +35 -2
- package/dist/core/internal/engine.d.ts.map +1 -1
- package/dist/core/internal/engine.js +12 -1
- package/dist/core/internal/engine.js.map +1 -1
- package/dist/core/internal/hash.d.ts +10 -0
- package/dist/core/internal/hash.d.ts.map +1 -1
- package/dist/core/internal/hash.js +26 -1
- package/dist/core/internal/hash.js.map +1 -1
- package/dist/index.d.ts +23 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/node/Engine.d.ts +1 -1
- package/dist/node/Engine.d.ts.map +1 -1
- package/dist/node/Engine.js.map +1 -1
- package/dist/node/Hash.d.ts +6 -4
- package/dist/node/Hash.d.ts.map +1 -1
- package/dist/node/Hash.js +35 -3
- package/dist/node/Hash.js.map +1 -1
- package/dist/tempo/AuthorizationTempo.d.ts +6 -6
- package/dist/tempo/AuthorizationTempo.js +6 -6
- package/dist/tempo/KeyAuthorization.d.ts +3 -8
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +3 -8
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +8 -8
- package/dist/tempo/SignatureEnvelope.js +8 -8
- package/dist/trusted-setups/Paths.d.ts +1 -0
- package/dist/trusted-setups/Paths.d.ts.map +1 -1
- package/dist/trusted-setups/Paths.js +1 -0
- package/dist/trusted-setups/Paths.js.map +1 -1
- package/dist/trusted-setups/Setups.d.ts +35 -0
- package/dist/trusted-setups/Setups.d.ts.map +1 -0
- package/dist/trusted-setups/Setups.js +29 -0
- package/dist/trusted-setups/Setups.js.map +1 -0
- package/dist/trusted-setups/index.d.ts +20 -0
- package/dist/trusted-setups/index.d.ts.map +1 -1
- package/dist/trusted-setups/index.js +20 -0
- package/dist/trusted-setups/index.js.map +1 -1
- package/dist/trusted-setups/internal/paths.d.ts.map +1 -1
- package/dist/trusted-setups/internal/paths.js +1 -1
- package/dist/trusted-setups/internal/paths.js.map +1 -1
- package/dist/trusted-setups/internal/setups/mainnet.d.ts +7 -0
- package/dist/trusted-setups/internal/setups/mainnet.d.ts.map +1 -0
- package/dist/trusted-setups/internal/setups/mainnet.js +11 -0
- package/dist/trusted-setups/internal/setups/mainnet.js.map +1 -0
- package/dist/wasm/Engine.d.ts +4 -3
- package/dist/wasm/Engine.d.ts.map +1 -1
- package/dist/wasm/Engine.js +5 -5
- package/dist/wasm/Engine.js.map +1 -1
- package/dist/wasm/Hash.d.ts +1 -1
- package/dist/wasm/Hash.d.ts.map +1 -1
- package/dist/wasm/Hash.js +5 -0
- package/dist/wasm/Hash.js.map +1 -1
- package/dist/wasm/Keystore.d.ts +23 -9
- package/dist/wasm/Keystore.d.ts.map +1 -1
- package/dist/wasm/Keystore.js +30 -13
- package/dist/wasm/Keystore.js.map +1 -1
- package/dist/wasm/Kzg.d.ts +112 -0
- package/dist/wasm/Kzg.d.ts.map +1 -0
- package/dist/wasm/Kzg.js +333 -0
- package/dist/wasm/Kzg.js.map +1 -0
- package/dist/wasm/Secp256k1.d.ts +55 -0
- package/dist/wasm/Secp256k1.d.ts.map +1 -0
- package/dist/wasm/Secp256k1.js +181 -0
- package/dist/wasm/Secp256k1.js.map +1 -0
- package/dist/wasm/index.d.ts +44 -1
- package/dist/wasm/index.d.ts.map +1 -1
- package/dist/wasm/index.js +44 -1
- package/dist/wasm/index.js.map +1 -1
- package/dist/wasm/internal/blake3.d.ts +10 -1
- package/dist/wasm/internal/blake3.d.ts.map +1 -1
- package/dist/wasm/internal/blake3.js +12 -1
- package/dist/wasm/internal/blake3.js.map +1 -1
- package/dist/wasm/internal/blake3.wasm.d.ts +3 -1
- package/dist/wasm/internal/blake3.wasm.d.ts.map +1 -1
- package/dist/wasm/internal/blake3.wasm.js +3 -1
- package/dist/wasm/internal/blake3.wasm.js.map +1 -1
- package/dist/wasm/internal/hash.d.ts +9 -0
- package/dist/wasm/internal/hash.d.ts.map +1 -1
- package/dist/wasm/internal/hash.js +13 -1
- package/dist/wasm/internal/hash.js.map +1 -1
- package/dist/wasm/internal/hashState.d.ts +25 -0
- package/dist/wasm/internal/hashState.d.ts.map +1 -0
- package/dist/wasm/internal/hashState.js +105 -0
- package/dist/wasm/internal/hashState.js.map +1 -0
- package/dist/wasm/internal/hashes.d.ts +12 -1
- package/dist/wasm/internal/hashes.d.ts.map +1 -1
- package/dist/wasm/internal/hashes.js +18 -1
- package/dist/wasm/internal/hashes.js.map +1 -1
- package/dist/wasm/internal/hashes.wasm.d.ts +11 -3
- package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -1
- package/dist/wasm/internal/hashes.wasm.js +11 -3
- package/dist/wasm/internal/hashes.wasm.js.map +1 -1
- package/dist/wasm/internal/instantiate.d.ts +12 -0
- package/dist/wasm/internal/instantiate.d.ts.map +1 -1
- package/dist/wasm/internal/instantiate.js +23 -7
- package/dist/wasm/internal/instantiate.js.map +1 -1
- package/dist/wasm/internal/keystore.d.ts +10 -0
- package/dist/wasm/internal/keystore.d.ts.map +1 -0
- package/dist/wasm/internal/keystore.js +10 -0
- package/dist/wasm/internal/keystore.js.map +1 -0
- package/dist/wasm/internal/kzg.d.ts +17 -0
- package/dist/wasm/internal/kzg.d.ts.map +1 -0
- package/dist/wasm/internal/kzg.js +8 -0
- package/dist/wasm/internal/kzg.js.map +1 -0
- package/dist/wasm/internal/kzg.wasm.d.ts +3 -0
- package/dist/wasm/internal/kzg.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/kzg.wasm.js +10 -0
- package/dist/wasm/internal/kzg.wasm.js.map +1 -0
- package/dist/wasm/internal/scrypt.d.ts +16 -0
- package/dist/wasm/internal/scrypt.d.ts.map +1 -0
- package/dist/wasm/internal/scrypt.js +78 -0
- package/dist/wasm/internal/scrypt.js.map +1 -0
- package/dist/wasm/internal/scrypt.wasm.d.ts +7 -0
- package/dist/wasm/internal/scrypt.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/scrypt.wasm.js +14 -0
- package/dist/wasm/internal/scrypt.wasm.js.map +1 -0
- package/dist/wasm/internal/secp256k1.d.ts +16 -0
- package/dist/wasm/internal/secp256k1.d.ts.map +1 -0
- package/dist/wasm/internal/secp256k1.js +20 -0
- package/dist/wasm/internal/secp256k1.js.map +1 -0
- package/dist/wasm/internal/secp256k1.wasm.d.ts +3 -0
- package/dist/wasm/internal/secp256k1.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/secp256k1.wasm.js +10 -0
- package/dist/wasm/internal/secp256k1.wasm.js.map +1 -0
- package/dist/webauthn/Authentication.d.ts +2 -0
- package/dist/webauthn/Authentication.d.ts.map +1 -1
- package/dist/webauthn/Authentication.js +2 -1
- package/dist/webauthn/Authentication.js.map +1 -1
- package/dist/webauthn/Registration.d.ts.map +1 -1
- package/dist/webauthn/Registration.js +2 -1
- package/dist/webauthn/Registration.js.map +1 -1
- package/dist/webauthn/Types.d.ts +27 -6
- package/dist/webauthn/Types.d.ts.map +1 -1
- package/dist/webauthn/internal/utils.d.ts.map +1 -1
- package/dist/webauthn/internal/utils.js +35 -9
- package/dist/webauthn/internal/utils.js.map +1 -1
- package/dist/zod/TypedData.d.ts +2 -2
- package/package.json +27 -2
- package/src/benchmarks/Ox.bench.ts +6 -0
- package/src/benchmarks/OxNode.bench.ts +8 -0
- package/src/benchmarks/OxV0.bench.ts +4 -0
- package/src/benchmarks/OxWasm.bench.ts +22 -0
- package/src/core/AbiFunction.ts +5 -5
- package/src/core/AbiParameters.ts +8 -20
- package/src/core/AesGcm.ts +86 -1
- package/src/core/Ed25519.ts +87 -1
- package/src/core/Engine.ts +1 -0
- package/src/core/Hash.ts +321 -1
- package/src/core/Hex.ts +1 -4
- package/src/core/Rlp.ts +172 -5
- package/src/core/Secp256k1.ts +92 -1
- package/src/core/WebAuthn.ts +579 -0
- package/src/core/WebAuthnP256.ts +47 -50
- package/src/core/_test/AbiFunction.test.ts +9 -0
- package/src/core/_test/AbiParameters.differential.fuzz.ts +156 -0
- package/src/core/_test/AbiParameters.encode.test.ts +22 -0
- package/src/core/_test/AbiParameters.fuzz.ts +4 -0
- package/src/core/_test/AesGcm.test.ts +76 -0
- package/src/core/_test/Block.test.ts +9 -2
- package/src/core/_test/Ed25519.test-d.ts +13 -1
- package/src/core/_test/Ed25519.test.ts +120 -1
- package/src/core/_test/Engine.test-d.ts +9 -0
- package/src/core/_test/Engine.test.ts +1 -1
- package/src/core/_test/Hash.test-d.ts +41 -0
- package/src/core/_test/Hash.test.ts +278 -1
- package/src/core/_test/Hash.vectors.test.ts +1 -2
- package/src/core/_test/Hex.test.ts +2 -0
- package/src/core/_test/Rlp.test-d.ts +18 -0
- package/src/core/_test/Rlp.test.ts +109 -0
- package/src/core/_test/Secp256k1.test-d.ts +14 -0
- package/src/core/_test/Secp256k1.test.ts +91 -1
- package/src/core/_test/Transaction.test.ts +11 -2
- package/src/core/_test/WebAuthn.test-d.ts +142 -0
- package/src/core/_test/WebAuthn.test.ts +766 -0
- package/src/core/_test/index.test.ts +1 -0
- package/src/core/internal/abiParameters.ts +466 -326
- package/src/core/internal/engine.ts +47 -2
- package/src/core/internal/hash.ts +53 -1
- package/src/index.ts +24 -14
- package/src/node/Engine.ts +1 -0
- package/src/node/Hash.ts +43 -6
- package/src/node/_test/Engine.test-d.ts +1 -0
- package/src/node/_test/Engine.test.ts +2 -0
- package/src/node/_test/Hash.test-d.ts +11 -0
- package/src/node/_test/Hash.test.ts +46 -0
- package/src/tempo/AuthorizationTempo.ts +6 -6
- package/src/tempo/KeyAuthorization.ts +3 -8
- package/src/tempo/SignatureEnvelope.ts +8 -8
- package/src/trusted-setups/Paths.ts +1 -0
- package/src/trusted-setups/README.md +39 -0
- package/src/trusted-setups/Setups.ts +46 -0
- package/src/trusted-setups/_test/Paths.test.ts +16 -0
- package/src/trusted-setups/_test/Setups.test-d.ts +7 -0
- package/src/trusted-setups/_test/Setups.test.ts +43 -0
- package/src/trusted-setups/_test/index.test.ts +1 -0
- package/src/trusted-setups/index.ts +21 -0
- package/src/trusted-setups/internal/paths.ts +4 -1
- package/src/trusted-setups/internal/setups/mainnet.source.json +7 -0
- package/src/trusted-setups/internal/setups/mainnet.ts +16 -0
- package/src/version.ts +1 -1
- package/src/wasm/Engine.ts +9 -6
- package/src/wasm/Hash.ts +10 -0
- package/src/wasm/Keystore.bench.ts +26 -0
- package/src/wasm/Keystore.ts +32 -14
- package/src/wasm/Kzg.bench.ts +63 -0
- package/src/wasm/Kzg.ts +518 -0
- package/src/wasm/Secp256k1.bench.ts +79 -0
- package/src/wasm/Secp256k1.ts +248 -0
- package/src/wasm/_test/Engine.test-d.ts +2 -0
- package/src/wasm/_test/Engine.test.ts +5 -0
- package/src/wasm/_test/Hash.browser.test.ts +31 -0
- package/src/wasm/_test/Hash.test-d.ts +17 -0
- package/src/wasm/_test/Hash.test.ts +252 -3
- package/src/wasm/_test/Keystore.browser.test.ts +31 -0
- package/src/wasm/_test/Keystore.fuzz.ts +50 -0
- package/src/wasm/_test/Keystore.test-d.ts +10 -1
- package/src/wasm/_test/Keystore.test.ts +289 -4
- package/src/wasm/_test/Kzg.test-d.ts +19 -0
- package/src/wasm/_test/Kzg.test.ts +220 -0
- package/src/wasm/_test/Runtime.test.ts +9 -0
- package/src/wasm/_test/Secp256k1.test-d.ts +35 -0
- package/src/wasm/_test/Secp256k1.test.ts +354 -0
- package/src/wasm/index.ts +46 -1
- package/src/wasm/internal/blake3.ts +23 -2
- package/src/wasm/internal/blake3.wasm.ts +4 -1
- package/src/wasm/internal/hash.ts +27 -1
- package/src/wasm/internal/hashState.ts +154 -0
- package/src/wasm/internal/hashes.ts +56 -15
- package/src/wasm/internal/hashes.wasm.ts +15 -3
- package/src/wasm/internal/instantiate.ts +29 -9
- package/src/wasm/internal/keystore.ts +19 -0
- package/src/wasm/internal/kzg.ts +50 -0
- package/src/wasm/internal/kzg.wasm.ts +11 -0
- package/src/wasm/internal/scrypt.ts +131 -0
- package/src/wasm/internal/scrypt.wasm.ts +17 -0
- package/src/wasm/internal/secp256k1.ts +62 -0
- package/src/wasm/internal/secp256k1.wasm.ts +11 -0
- package/src/webauthn/Authentication.ts +4 -0
- package/src/webauthn/Registration.ts +2 -0
- package/src/webauthn/Types.ts +32 -2
- package/src/webauthn/_test/Authentication.test.ts +123 -1
- package/src/webauthn/_test/Registration.test.ts +26 -6
- package/src/webauthn/_test/WebAuthn.browser.test.ts +28 -0
- package/src/webauthn/internal/utils.ts +41 -8
- package/wasm/vendor/c-kzg-4844/LICENSE +201 -0
- package/wasm/vendor/c-kzg-4844/blst/LICENSE +201 -0
- package/src/trusted-setups/internal/setups/mainnet.txt +0 -4163
package/src/core/WebAuthnP256.ts
CHANGED
|
@@ -16,9 +16,9 @@ export const createChallenge = Registration.createChallenge
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts twoslash
|
|
19
|
-
* import {
|
|
19
|
+
* import { WebAuthn } from 'ox'
|
|
20
20
|
*
|
|
21
|
-
* const credential = await
|
|
21
|
+
* const credential = await WebAuthn.createCredential({
|
|
22
22
|
* name: 'Example'
|
|
23
23
|
* }) // [!code focus]
|
|
24
24
|
* // @log: {
|
|
@@ -27,7 +27,7 @@ export const createChallenge = Registration.createChallenge
|
|
|
27
27
|
* // @log: raw: PublicKeyCredential {},
|
|
28
28
|
* // @log: }
|
|
29
29
|
*
|
|
30
|
-
* const { metadata, signature } = await
|
|
30
|
+
* const { metadata, signature } = await WebAuthn.sign({
|
|
31
31
|
* credentialId: credential.id,
|
|
32
32
|
* challenge: '0xdeadbeef'
|
|
33
33
|
* })
|
|
@@ -49,27 +49,25 @@ export declare namespace createCredential {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Gets the authenticator data which contains information about the
|
|
52
|
-
* processing of an authenticator request (ie. from `
|
|
52
|
+
* processing of an authenticator request (ie. from `WebAuthn.sign`).
|
|
53
53
|
*
|
|
54
54
|
* :::warning
|
|
55
55
|
*
|
|
56
56
|
* This function is mainly for testing purposes or for manually constructing
|
|
57
57
|
* autenticator data. In most cases you will not need this function.
|
|
58
58
|
* `authenticatorData` is typically returned as part of the
|
|
59
|
-
* {@link ox#
|
|
59
|
+
* {@link ox#WebAuthn.(sign:function)} response (ie. an authenticator response).
|
|
60
60
|
*
|
|
61
61
|
* :::
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
64
|
* ```ts twoslash
|
|
65
|
-
* import {
|
|
65
|
+
* import { WebAuthn } from 'ox'
|
|
66
66
|
*
|
|
67
|
-
* const authenticatorData =
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* }
|
|
72
|
-
* )
|
|
67
|
+
* const authenticatorData = WebAuthn.getAuthenticatorData({
|
|
68
|
+
* rpId: 'example.com',
|
|
69
|
+
* signCount: 420
|
|
70
|
+
* })
|
|
73
71
|
* // @log: "0xa379a6f6eeafb9a55e378c118034e2751e682fab9f2d30ab13d2125586ce194705000001a4"
|
|
74
72
|
* ```
|
|
75
73
|
*
|
|
@@ -79,20 +77,18 @@ export declare namespace createCredential {
|
|
|
79
77
|
* Include a credential ID and public key in the authenticator data (for registration responses):
|
|
80
78
|
*
|
|
81
79
|
* ```ts twoslash
|
|
82
|
-
* import { P256,
|
|
80
|
+
* import { P256, WebAuthn } from 'ox'
|
|
83
81
|
*
|
|
84
82
|
* const { publicKey } = P256.createKeyPair()
|
|
85
83
|
*
|
|
86
|
-
* const authenticatorData =
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* publicKey
|
|
93
|
-
* }
|
|
84
|
+
* const authenticatorData = WebAuthn.getAuthenticatorData({
|
|
85
|
+
* rpId: 'example.com',
|
|
86
|
+
* flag: 0x41, // UP + AT
|
|
87
|
+
* credential: {
|
|
88
|
+
* id: new Uint8Array(32),
|
|
89
|
+
* publicKey
|
|
94
90
|
* }
|
|
95
|
-
* )
|
|
91
|
+
* })
|
|
96
92
|
* ```
|
|
97
93
|
*
|
|
98
94
|
* @param options - Options to construct the authenticator data.
|
|
@@ -108,22 +104,22 @@ export declare namespace getAuthenticatorData {
|
|
|
108
104
|
|
|
109
105
|
/**
|
|
110
106
|
* Constructs the Client Data in stringified JSON format which represents client data that
|
|
111
|
-
* was passed to `credentials.get()` in {@link ox#
|
|
107
|
+
* was passed to `credentials.get()` in {@link ox#WebAuthn.(sign:function)}.
|
|
112
108
|
*
|
|
113
109
|
* :::warning
|
|
114
110
|
*
|
|
115
111
|
* This function is mainly for testing purposes or for manually constructing
|
|
116
112
|
* client data. In most cases you will not need this function.
|
|
117
113
|
* `clientDataJSON` is typically returned as part of the
|
|
118
|
-
* {@link ox#
|
|
114
|
+
* {@link ox#WebAuthn.(sign:function)} response (ie. an authenticator response).
|
|
119
115
|
*
|
|
120
116
|
* :::
|
|
121
117
|
*
|
|
122
118
|
* @example
|
|
123
119
|
* ```ts twoslash
|
|
124
|
-
* import {
|
|
120
|
+
* import { WebAuthn } from 'ox'
|
|
125
121
|
*
|
|
126
|
-
* const clientDataJSON =
|
|
122
|
+
* const clientDataJSON = WebAuthn.getClientDataJSON({
|
|
127
123
|
* challenge: '0xdeadbeef',
|
|
128
124
|
* origin: 'https://example.com'
|
|
129
125
|
* })
|
|
@@ -154,19 +150,17 @@ export declare namespace getClientDataJSON {
|
|
|
154
150
|
*
|
|
155
151
|
* @example
|
|
156
152
|
* ```ts twoslash
|
|
157
|
-
* import { P256,
|
|
153
|
+
* import { P256, WebAuthn } from 'ox'
|
|
158
154
|
*
|
|
159
155
|
* const { publicKey } = P256.createKeyPair()
|
|
160
156
|
*
|
|
161
|
-
* const attestationObject =
|
|
162
|
-
* {
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* }
|
|
169
|
-
* )
|
|
157
|
+
* const attestationObject = WebAuthn.getAttestationObject({
|
|
158
|
+
* authData: WebAuthn.getAuthenticatorData({
|
|
159
|
+
* rpId: 'example.com',
|
|
160
|
+
* flag: 0x41,
|
|
161
|
+
* credential: { id: new Uint8Array(32), publicKey }
|
|
162
|
+
* })
|
|
163
|
+
* })
|
|
170
164
|
* ```
|
|
171
165
|
*
|
|
172
166
|
* @param options - Options to construct the attestation object.
|
|
@@ -186,9 +180,9 @@ export declare namespace getAttestationObject {
|
|
|
186
180
|
*
|
|
187
181
|
* @example
|
|
188
182
|
* ```ts twoslash
|
|
189
|
-
* import {
|
|
183
|
+
* import { WebAuthn } from 'ox'
|
|
190
184
|
*
|
|
191
|
-
* const options =
|
|
185
|
+
* const options = WebAuthn.getCredentialCreationOptions({
|
|
192
186
|
* name: 'Example'
|
|
193
187
|
* })
|
|
194
188
|
*
|
|
@@ -212,9 +206,9 @@ export declare namespace getCredentialCreationOptions {
|
|
|
212
206
|
*
|
|
213
207
|
* @example
|
|
214
208
|
* ```ts twoslash
|
|
215
|
-
* import {
|
|
209
|
+
* import { WebAuthn } from 'ox'
|
|
216
210
|
*
|
|
217
|
-
* const options =
|
|
211
|
+
* const options = WebAuthn.getCredentialRequestOptions({
|
|
218
212
|
* challenge: '0xdeadbeef'
|
|
219
213
|
* })
|
|
220
214
|
*
|
|
@@ -242,15 +236,15 @@ export declare namespace getCredentialRequestOptions {
|
|
|
242
236
|
*
|
|
243
237
|
* This function is mainly for testing purposes or for manually constructing
|
|
244
238
|
* signing payloads. In most cases you will not need this function and
|
|
245
|
-
* instead use {@link ox#
|
|
239
|
+
* instead use {@link ox#WebAuthn.(sign:function)}.
|
|
246
240
|
*
|
|
247
241
|
* :::
|
|
248
242
|
*
|
|
249
243
|
* @example
|
|
250
244
|
* ```ts twoslash
|
|
251
|
-
* import {
|
|
245
|
+
* import { WebAuthn, WebCryptoP256 } from 'ox'
|
|
252
246
|
*
|
|
253
|
-
* const { metadata, payload } =
|
|
247
|
+
* const { metadata, payload } = WebAuthn.getSignPayload({
|
|
254
248
|
* // [!code focus]
|
|
255
249
|
* challenge: '0xdeadbeef' // [!code focus]
|
|
256
250
|
* }) // [!code focus]
|
|
@@ -294,13 +288,13 @@ export declare namespace getSignPayload {
|
|
|
294
288
|
*
|
|
295
289
|
* @example
|
|
296
290
|
* ```ts twoslash
|
|
297
|
-
* import {
|
|
291
|
+
* import { WebAuthn } from 'ox'
|
|
298
292
|
*
|
|
299
|
-
* const credential = await
|
|
293
|
+
* const credential = await WebAuthn.createCredential({
|
|
300
294
|
* name: 'Example'
|
|
301
295
|
* })
|
|
302
296
|
*
|
|
303
|
-
* const { metadata, signature } = await
|
|
297
|
+
* const { metadata, signature } = await WebAuthn.sign({
|
|
304
298
|
* // [!code focus]
|
|
305
299
|
* credentialId: credential.id, // [!code focus]
|
|
306
300
|
* challenge: '0xdeadbeef' // [!code focus]
|
|
@@ -337,18 +331,18 @@ export declare namespace sign {
|
|
|
337
331
|
*
|
|
338
332
|
* @example
|
|
339
333
|
* ```ts twoslash
|
|
340
|
-
* import {
|
|
334
|
+
* import { WebAuthn } from 'ox'
|
|
341
335
|
*
|
|
342
|
-
* const credential = await
|
|
336
|
+
* const credential = await WebAuthn.createCredential({
|
|
343
337
|
* name: 'Example'
|
|
344
338
|
* })
|
|
345
339
|
*
|
|
346
|
-
* const { metadata, signature } = await
|
|
340
|
+
* const { metadata, signature } = await WebAuthn.sign({
|
|
347
341
|
* credentialId: credential.id,
|
|
348
342
|
* challenge: '0xdeadbeef'
|
|
349
343
|
* })
|
|
350
344
|
*
|
|
351
|
-
* const result = await
|
|
345
|
+
* const result = await WebAuthn.verify({
|
|
352
346
|
* // [!code focus]
|
|
353
347
|
* metadata, // [!code focus]
|
|
354
348
|
* challenge: '0xdeadbeef', // [!code focus]
|
|
@@ -398,3 +392,6 @@ export type {
|
|
|
398
392
|
ResidentKeyRequirement,
|
|
399
393
|
UserVerificationRequirement,
|
|
400
394
|
} from '../webauthn/Types.js'
|
|
395
|
+
|
|
396
|
+
/** @deprecated Use `WebAuthn` instead. */
|
|
397
|
+
declare module './WebAuthnP256.js' {}
|
|
@@ -218,6 +218,15 @@ describe('encodeData', () => {
|
|
|
218
218
|
)
|
|
219
219
|
})
|
|
220
220
|
|
|
221
|
+
test('behavior: malformed bytes compatibility', () => {
|
|
222
|
+
const abiFunction = AbiFunction.from('function foo(bytes)')
|
|
223
|
+
expect(
|
|
224
|
+
AbiFunction.encodeData(abiFunction, ['0xzz1']),
|
|
225
|
+
).toMatchInlineSnapshot(
|
|
226
|
+
`"0x30c8d1da00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002zz10000000000000000000000000000000000000000000000000000000000000"`,
|
|
227
|
+
)
|
|
228
|
+
})
|
|
229
|
+
|
|
221
230
|
test('behavior: with overloads', () => {
|
|
222
231
|
const abi = Abi.from([
|
|
223
232
|
{
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { test } from '@fast-check/vitest'
|
|
2
|
+
import { AbiCoder, Interface, ParamType } from 'ethers'
|
|
3
|
+
import { AbiFunction, AbiParameters } from 'ox'
|
|
4
|
+
import { describe, expect } from 'vp/test'
|
|
5
|
+
|
|
6
|
+
import { arbitraryAbiCase } from '../../../test/fuzz/arbitraries/abi.js'
|
|
7
|
+
import { numRuns } from '../../../test/fuzz/numRuns.js'
|
|
8
|
+
|
|
9
|
+
const coder = AbiCoder.defaultAbiCoder()
|
|
10
|
+
|
|
11
|
+
describe('AbiParameters differential', () => {
|
|
12
|
+
test.prop(
|
|
13
|
+
{
|
|
14
|
+
input: arbitraryAbiCase({
|
|
15
|
+
maxArrayLength: 4,
|
|
16
|
+
maxBytesLength: 128,
|
|
17
|
+
maxDepth: 4,
|
|
18
|
+
maxTupleArity: 4,
|
|
19
|
+
minFixedArrayLength: 0,
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
{ numRuns },
|
|
23
|
+
)('encode matches ethers AbiCoder', ({ input }) => {
|
|
24
|
+
expectParameters(input.parameters, input.values)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('integer boundaries match ethers AbiCoder', () => {
|
|
28
|
+
for (let bits = 8; bits <= 256; bits += 8) {
|
|
29
|
+
const bits_ = BigInt(bits)
|
|
30
|
+
const maxUnsigned = 2n ** bits_ - 1n
|
|
31
|
+
const maxSigned = 2n ** (bits_ - 1n) - 1n
|
|
32
|
+
const minSigned = -(2n ** (bits_ - 1n))
|
|
33
|
+
|
|
34
|
+
for (const value of [0n, 1n, maxUnsigned])
|
|
35
|
+
expectParameters([{ type: `uint${bits}` }], [value])
|
|
36
|
+
for (const value of [minSigned, -1n, 0n, 1n, maxSigned])
|
|
37
|
+
expectParameters([{ type: `int${bits}` }], [value])
|
|
38
|
+
|
|
39
|
+
if (bits > 64) {
|
|
40
|
+
expectParameters([{ type: `uint${bits}` }], [2n ** 64n - 1n])
|
|
41
|
+
expectParameters([{ type: `uint${bits}` }], [2n ** 64n])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('bytes and string boundaries match ethers AbiCoder', () => {
|
|
47
|
+
for (let size = 1; size <= 32; size++)
|
|
48
|
+
expectParameters([{ type: `bytes${size}` }], [`0x${'ab'.repeat(size)}`])
|
|
49
|
+
|
|
50
|
+
for (const size of [0, 1, 31, 32, 33, 63, 64, 65, 128]) {
|
|
51
|
+
expectParameters([{ type: 'bytes' }], [`0x${'ab'.repeat(size)}`])
|
|
52
|
+
expectParameters([{ type: 'string' }], ['a'.repeat(size)])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const value of ['\u0000', 'é', '€', '😀', 'a😀b'])
|
|
56
|
+
expectParameters([{ type: 'string' }], [value])
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('zero-width types match ethers AbiCoder', () => {
|
|
60
|
+
expectParameters([{ type: 'uint256[0]' }, { type: 'uint256' }], [[], 3n])
|
|
61
|
+
expectParameters([{ type: 'string[0]' }, { type: 'uint256' }], [[], 3n])
|
|
62
|
+
expectParameters([{ type: 'tuple', components: [] }], [[]])
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe('AbiFunction differential', () => {
|
|
67
|
+
test.prop(
|
|
68
|
+
{
|
|
69
|
+
input: arbitraryAbiCase({
|
|
70
|
+
maxArrayLength: 4,
|
|
71
|
+
maxBytesLength: 128,
|
|
72
|
+
maxDepth: 4,
|
|
73
|
+
maxTupleArity: 4,
|
|
74
|
+
minFixedArrayLength: 0,
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
{ numRuns },
|
|
78
|
+
)('encodeData matches ethers Interface', ({ input }) => {
|
|
79
|
+
expectFunction(input.parameters, input.values)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('nested named dynamic values match ethers Interface', () => {
|
|
83
|
+
expectFunction(
|
|
84
|
+
[
|
|
85
|
+
{
|
|
86
|
+
components: [
|
|
87
|
+
{ name: 'maker', type: 'address' },
|
|
88
|
+
{
|
|
89
|
+
components: [
|
|
90
|
+
{ name: 'id', type: 'uint256' },
|
|
91
|
+
{ name: 'memo', type: 'string' },
|
|
92
|
+
{ name: 'payloads', type: 'bytes[]' },
|
|
93
|
+
],
|
|
94
|
+
name: 'items',
|
|
95
|
+
type: 'tuple[2]',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
name: 'orders',
|
|
99
|
+
type: 'tuple[]',
|
|
100
|
+
},
|
|
101
|
+
{ name: 'suffix', type: 'string[2]' },
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
[
|
|
105
|
+
{
|
|
106
|
+
items: [
|
|
107
|
+
{
|
|
108
|
+
id: 2n ** 64n - 1n,
|
|
109
|
+
memo: '',
|
|
110
|
+
payloads: ['0x', `0x${'ab'.repeat(31)}`],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 2n ** 64n,
|
|
114
|
+
memo: '😀',
|
|
115
|
+
payloads: [`0x${'ab'.repeat(32)}`, `0x${'ab'.repeat(33)}`],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
maker: '0x0000000000000000000000000000000000000001',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
['', 'a'.repeat(33)],
|
|
122
|
+
],
|
|
123
|
+
)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
function expectParameters(
|
|
128
|
+
parameters: readonly AbiParameters.Parameter[],
|
|
129
|
+
values: readonly unknown[],
|
|
130
|
+
) {
|
|
131
|
+
const types = parameters.map((parameter) => ParamType.from(parameter))
|
|
132
|
+
const expected = coder.encode(types, values)
|
|
133
|
+
const encoded = AbiParameters.encode(parameters, values as never)
|
|
134
|
+
expect(encoded).toEqual(expected)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function expectFunction(
|
|
138
|
+
parameters: readonly AbiParameters.Parameter[],
|
|
139
|
+
values: readonly unknown[],
|
|
140
|
+
) {
|
|
141
|
+
const abiFunction: AbiFunction.AbiFunction = {
|
|
142
|
+
inputs: parameters,
|
|
143
|
+
name: 'test',
|
|
144
|
+
outputs: [],
|
|
145
|
+
stateMutability: 'pure',
|
|
146
|
+
type: 'function',
|
|
147
|
+
}
|
|
148
|
+
const inputs = parameters
|
|
149
|
+
.map((parameter) => ParamType.from(parameter).format('full'))
|
|
150
|
+
.join(',')
|
|
151
|
+
const expected = new Interface([
|
|
152
|
+
`function ${abiFunction.name}(${inputs}) pure`,
|
|
153
|
+
]).encodeFunctionData(abiFunction.name, values)
|
|
154
|
+
const encoded = AbiFunction.encodeData(abiFunction, values as never)
|
|
155
|
+
expect(encoded).toEqual(expected)
|
|
156
|
+
}
|
|
@@ -1825,6 +1825,28 @@ test('invalid bytes', () => {
|
|
|
1825
1825
|
)
|
|
1826
1826
|
})
|
|
1827
1827
|
|
|
1828
|
+
test('invalid bytes type', () => {
|
|
1829
|
+
expect(() =>
|
|
1830
|
+
AbiParameters.encode([{ name: 'x', type: 'bytes0' }], ['0x']),
|
|
1831
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1832
|
+
'[AbiParameters.InvalidTypeError: Type `bytes0` is not a valid ABI Type.]',
|
|
1833
|
+
)
|
|
1834
|
+
expect(() =>
|
|
1835
|
+
AbiParameters.encode(
|
|
1836
|
+
[
|
|
1837
|
+
{ name: 'x', type: 'bytes33' },
|
|
1838
|
+
{ name: 'following', type: 'uint256' },
|
|
1839
|
+
],
|
|
1840
|
+
[
|
|
1841
|
+
'0x000000000000000000000000000000000000000000000000000000000000000000',
|
|
1842
|
+
1n,
|
|
1843
|
+
],
|
|
1844
|
+
),
|
|
1845
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1846
|
+
'[AbiParameters.InvalidTypeError: Type `bytes33` is not a valid ABI Type.]',
|
|
1847
|
+
)
|
|
1848
|
+
})
|
|
1849
|
+
|
|
1828
1850
|
test('integer out of range', () => {
|
|
1829
1851
|
expect(() =>
|
|
1830
1852
|
AbiParameters.encode(
|
|
@@ -32,5 +32,9 @@ function normalize(value: unknown): unknown {
|
|
|
32
32
|
if (Array.isArray(value)) return value.map(normalize)
|
|
33
33
|
if (typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value))
|
|
34
34
|
return value.toLowerCase()
|
|
35
|
+
if (value && typeof value === 'object')
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(value).map(([key, value]) => [key, normalize(value)]),
|
|
38
|
+
)
|
|
35
39
|
return value
|
|
36
40
|
}
|
|
@@ -85,6 +85,80 @@ describe('encrypt', () => {
|
|
|
85
85
|
})
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
+
describe('fromPrf', () => {
|
|
89
|
+
test('vector', async () => {
|
|
90
|
+
const key = await AesGcm.fromPrf(
|
|
91
|
+
'0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
|
92
|
+
)
|
|
93
|
+
const expectedKey = await globalThis.crypto.subtle.importKey(
|
|
94
|
+
'raw',
|
|
95
|
+
Bytes.fromHex(
|
|
96
|
+
'0x95c3c66b64baf063678e43d8aa98e1a4b4447c431fa9434b79e4a8c01ee85e07',
|
|
97
|
+
),
|
|
98
|
+
{ name: 'AES-GCM' },
|
|
99
|
+
false,
|
|
100
|
+
['decrypt'],
|
|
101
|
+
)
|
|
102
|
+
const value = Bytes.fromString('i am a secret message')
|
|
103
|
+
const encrypted = await AesGcm.encrypt(value, key)
|
|
104
|
+
|
|
105
|
+
await expect(AesGcm.decrypt(encrypted, expectedKey)).resolves.toEqual(value)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('value: Bytes', async () => {
|
|
109
|
+
const key = await AesGcm.fromPrf(
|
|
110
|
+
Bytes.fromHex(
|
|
111
|
+
'0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
const value = Bytes.fromString('i am a secret message')
|
|
115
|
+
|
|
116
|
+
await expect(
|
|
117
|
+
AesGcm.decrypt(await AesGcm.encrypt(value, key), key),
|
|
118
|
+
).resolves.toEqual(value)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('behavior: CryptoKey properties', async () => {
|
|
122
|
+
const key = await AesGcm.fromPrf(new Uint8Array(32))
|
|
123
|
+
|
|
124
|
+
expect({
|
|
125
|
+
algorithm: key.algorithm,
|
|
126
|
+
extractable: key.extractable,
|
|
127
|
+
type: key.type,
|
|
128
|
+
usages: key.usages,
|
|
129
|
+
}).toMatchInlineSnapshot(`
|
|
130
|
+
{
|
|
131
|
+
"algorithm": {
|
|
132
|
+
"length": 256,
|
|
133
|
+
"name": "AES-GCM",
|
|
134
|
+
},
|
|
135
|
+
"extractable": false,
|
|
136
|
+
"type": "secret",
|
|
137
|
+
"usages": [
|
|
138
|
+
"encrypt",
|
|
139
|
+
"decrypt",
|
|
140
|
+
],
|
|
141
|
+
}
|
|
142
|
+
`)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test('error: PRF output is too short', async () => {
|
|
146
|
+
await expect(
|
|
147
|
+
AesGcm.fromPrf(new Uint8Array(31)),
|
|
148
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
149
|
+
`[AesGcm.InvalidPrfSizeError: PRF output must be exactly 32 bytes. Received 31 bytes.]`,
|
|
150
|
+
)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('error: PRF output is too long', async () => {
|
|
154
|
+
await expect(
|
|
155
|
+
AesGcm.fromPrf(new Uint8Array(33)),
|
|
156
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
157
|
+
`[AesGcm.InvalidPrfSizeError: PRF output must be exactly 32 bytes. Received 33 bytes.]`,
|
|
158
|
+
)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
88
162
|
describe('getKey', () => {
|
|
89
163
|
test('default', async () => {
|
|
90
164
|
const key = await AesGcm.getKey({ password: 'qwerty' })
|
|
@@ -105,8 +179,10 @@ test('exports', () => {
|
|
|
105
179
|
"ivLength",
|
|
106
180
|
"decrypt",
|
|
107
181
|
"encrypt",
|
|
182
|
+
"fromPrf",
|
|
108
183
|
"getKey",
|
|
109
184
|
"randomSalt",
|
|
185
|
+
"InvalidPrfSizeError",
|
|
110
186
|
]
|
|
111
187
|
`)
|
|
112
188
|
})
|
|
@@ -400,9 +400,16 @@ describe('fromRpc', () => {
|
|
|
400
400
|
method: 'eth_getBlockByNumber',
|
|
401
401
|
params: ['latest', true],
|
|
402
402
|
})
|
|
403
|
-
.then(Block.fromRpc)
|
|
403
|
+
.then((block) => Block.fromRpc(block, { includeTransactions: true }))
|
|
404
404
|
|
|
405
|
-
|
|
405
|
+
const transactions = block?.transactions.map((transaction) => {
|
|
406
|
+
const { blockTimestamp: _, ...transaction_ } = {
|
|
407
|
+
blockTimestamp: undefined,
|
|
408
|
+
...transaction,
|
|
409
|
+
}
|
|
410
|
+
return transaction_
|
|
411
|
+
})
|
|
412
|
+
expect({ ...block, transactions }).toMatchSnapshot()
|
|
406
413
|
})
|
|
407
414
|
})
|
|
408
415
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { attest } from '@ark/attest'
|
|
2
|
-
import { Ed25519 } from 'ox'
|
|
2
|
+
import { type Bytes, Ed25519, type Hex } from 'ox'
|
|
3
3
|
import { expectTypeOf, test } from 'vp/test'
|
|
4
4
|
|
|
5
5
|
test('createKeyPair', () => {
|
|
@@ -28,6 +28,18 @@ test('createKeyPair', () => {
|
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
+
test('fromPrf', () => {
|
|
32
|
+
const prf =
|
|
33
|
+
'0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
|
|
34
|
+
|
|
35
|
+
expectTypeOf(Ed25519.fromPrf(prf)).toEqualTypeOf<Hex.Hex>()
|
|
36
|
+
expectTypeOf(Ed25519.fromPrf(new Uint8Array(32))).toEqualTypeOf<Hex.Hex>()
|
|
37
|
+
expectTypeOf(Ed25519.fromPrf(prf, { as: 'Hex' })).toEqualTypeOf<Hex.Hex>()
|
|
38
|
+
expectTypeOf(
|
|
39
|
+
Ed25519.fromPrf(prf, { as: 'Bytes' }),
|
|
40
|
+
).toEqualTypeOf<Bytes.Bytes>()
|
|
41
|
+
})
|
|
42
|
+
|
|
31
43
|
test('getPublicKey', () => {
|
|
32
44
|
// Default behavior (Hex)
|
|
33
45
|
{
|