ox 0.12.4 → 0.13.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/_cjs/core/P256.js +1 -1
  3. package/_cjs/core/P256.js.map +1 -1
  4. package/_cjs/core/WebAuthnP256.js +15 -256
  5. package/_cjs/core/WebAuthnP256.js.map +1 -1
  6. package/_cjs/core/WebCryptoP256.js +3 -1
  7. package/_cjs/core/WebCryptoP256.js.map +1 -1
  8. package/_cjs/core/internal/webauthn.js +5 -13
  9. package/_cjs/core/internal/webauthn.js.map +1 -1
  10. package/_cjs/index.docs.js +1 -0
  11. package/_cjs/index.docs.js.map +1 -1
  12. package/_cjs/version.js +1 -1
  13. package/_cjs/webauthn/Authentication.js +246 -0
  14. package/_cjs/webauthn/Authentication.js.map +1 -0
  15. package/_cjs/webauthn/Authenticator.js +55 -0
  16. package/_cjs/webauthn/Authenticator.js.map +1 -0
  17. package/_cjs/webauthn/Credential.js +53 -0
  18. package/_cjs/webauthn/Credential.js.map +1 -0
  19. package/_cjs/webauthn/Registration.js +349 -0
  20. package/_cjs/webauthn/Registration.js.map +1 -0
  21. package/_cjs/webauthn/Types.js +3 -0
  22. package/_cjs/webauthn/Types.js.map +1 -0
  23. package/_cjs/webauthn/index.js +9 -0
  24. package/_cjs/webauthn/index.js.map +1 -0
  25. package/_cjs/webauthn/internal/utils.js +53 -0
  26. package/_cjs/webauthn/internal/utils.js.map +1 -0
  27. package/_esm/core/P256.js +1 -1
  28. package/_esm/core/P256.js.map +1 -1
  29. package/_esm/core/WebAuthnP256.js +13 -261
  30. package/_esm/core/WebAuthnP256.js.map +1 -1
  31. package/_esm/core/WebCryptoP256.js +4 -1
  32. package/_esm/core/WebCryptoP256.js.map +1 -1
  33. package/_esm/core/internal/webauthn.js +5 -13
  34. package/_esm/core/internal/webauthn.js.map +1 -1
  35. package/_esm/erc8021/index.js +2 -2
  36. package/_esm/index.docs.js +1 -0
  37. package/_esm/index.docs.js.map +1 -1
  38. package/_esm/tempo/TransactionReceipt.js +1 -1
  39. package/_esm/tempo/TransactionRequest.js +1 -1
  40. package/_esm/version.js +1 -1
  41. package/_esm/webauthn/Authentication.js +453 -0
  42. package/_esm/webauthn/Authentication.js.map +1 -0
  43. package/_esm/webauthn/Authenticator.js +176 -0
  44. package/_esm/webauthn/Authenticator.js.map +1 -0
  45. package/_esm/webauthn/Credential.js +95 -0
  46. package/_esm/webauthn/Credential.js.map +1 -0
  47. package/_esm/webauthn/Registration.js +512 -0
  48. package/_esm/webauthn/Registration.js.map +1 -0
  49. package/_esm/webauthn/Types.js +2 -0
  50. package/_esm/webauthn/Types.js.map +1 -0
  51. package/_esm/webauthn/index.js +31 -0
  52. package/_esm/webauthn/index.js.map +1 -0
  53. package/_esm/webauthn/internal/utils.js +52 -0
  54. package/_esm/webauthn/internal/utils.js.map +1 -0
  55. package/_types/core/WebAuthnP256.d.ts +33 -208
  56. package/_types/core/WebAuthnP256.d.ts.map +1 -1
  57. package/_types/core/WebCryptoP256.d.ts +2 -0
  58. package/_types/core/WebCryptoP256.d.ts.map +1 -1
  59. package/_types/core/internal/webauthn.d.ts +2 -110
  60. package/_types/core/internal/webauthn.d.ts.map +1 -1
  61. package/_types/erc8021/index.d.ts +2 -2
  62. package/_types/index.docs.d.ts +1 -0
  63. package/_types/index.docs.d.ts.map +1 -1
  64. package/_types/tempo/Transaction.d.ts +2 -2
  65. package/_types/tempo/TransactionReceipt.d.ts +2 -2
  66. package/_types/tempo/TransactionRequest.d.ts +2 -2
  67. package/_types/version.d.ts +1 -1
  68. package/_types/webauthn/Authentication.d.ts +324 -0
  69. package/_types/webauthn/Authentication.d.ts.map +1 -0
  70. package/_types/webauthn/Authenticator.d.ts +182 -0
  71. package/_types/webauthn/Authenticator.d.ts.map +1 -0
  72. package/_types/webauthn/Credential.d.ts +77 -0
  73. package/_types/webauthn/Credential.d.ts.map +1 -0
  74. package/_types/webauthn/Registration.d.ts +308 -0
  75. package/_types/webauthn/Registration.d.ts.map +1 -0
  76. package/_types/webauthn/Types.d.ts +106 -0
  77. package/_types/webauthn/Types.d.ts.map +1 -0
  78. package/_types/webauthn/index.d.ts +33 -0
  79. package/_types/webauthn/index.d.ts.map +1 -0
  80. package/_types/webauthn/internal/utils.d.ts +17 -0
  81. package/_types/webauthn/internal/utils.d.ts.map +1 -0
  82. package/core/P256.ts +1 -1
  83. package/core/WebAuthnP256.ts +37 -582
  84. package/core/WebCryptoP256.ts +6 -1
  85. package/core/internal/webauthn.ts +6 -165
  86. package/erc8021/index.ts +2 -2
  87. package/index.docs.ts +1 -0
  88. package/package.json +31 -1
  89. package/tempo/Transaction.ts +2 -2
  90. package/tempo/TransactionReceipt.ts +2 -2
  91. package/tempo/TransactionRequest.ts +2 -2
  92. package/version.ts +1 -1
  93. package/webauthn/Authentication/package.json +6 -0
  94. package/webauthn/Authentication.ts +673 -0
  95. package/webauthn/Authenticator/package.json +6 -0
  96. package/webauthn/Authenticator.ts +259 -0
  97. package/webauthn/Credential/package.json +6 -0
  98. package/webauthn/Credential.ts +146 -0
  99. package/webauthn/Registration/package.json +6 -0
  100. package/webauthn/Registration.ts +805 -0
  101. package/webauthn/Types/package.json +6 -0
  102. package/webauthn/Types.ts +158 -0
  103. package/webauthn/index.ts +38 -0
  104. package/webauthn/internal/utils.ts +63 -0
  105. package/webauthn/package.json +6 -0
@@ -283,7 +283,10 @@ export declare namespace sign {
283
283
  * @returns Whether the payload was signed by the provided public key.
284
284
  */
285
285
  export async function verify(options: verify.Options): Promise<boolean> {
286
- const { payload, signature } = options
286
+ const { lowS = true, payload, signature } = options
287
+
288
+ // Reject high-S signatures if lowS is enabled.
289
+ if (lowS && signature.s > p256.CURVE.n / 2n) return false
287
290
 
288
291
  const publicKey = await globalThis.crypto.subtle.importKey(
289
292
  'raw',
@@ -306,6 +309,8 @@ export async function verify(options: verify.Options): Promise<boolean> {
306
309
 
307
310
  export declare namespace verify {
308
311
  type Options = {
312
+ /** If set to `true`, only low-S signatures will be accepted. @default true */
313
+ lowS?: boolean | undefined
309
314
  /** Public key that signed the payload. */
310
315
  publicKey: PublicKey.PublicKey<boolean>
311
316
  /** Signature of the payload. */
@@ -1,157 +1,7 @@
1
1
  import { p256 } from '@noble/curves/p256'
2
+ import * as Registration from '../../webauthn/Registration.js'
2
3
  import type * as Errors from '../Errors.js'
3
- import * as Hex from '../Hex.js'
4
4
  import * as PublicKey from '../PublicKey.js'
5
- import { CredentialCreationFailedError } from '../WebAuthnP256.js'
6
-
7
- /** @internal */
8
- export type AttestationConveyancePreference =
9
- | 'direct'
10
- | 'enterprise'
11
- | 'indirect'
12
- | 'none'
13
-
14
- /** @internal */
15
- export type AuthenticatorAttachment = 'cross-platform' | 'platform'
16
-
17
- /** @internal */
18
- export type AuthenticatorTransport =
19
- | 'ble'
20
- | 'hybrid'
21
- | 'internal'
22
- | 'nfc'
23
- | 'usb'
24
-
25
- /** @internal */
26
- export type COSEAlgorithmIdentifier = number
27
-
28
- /** @internal */
29
- export type CredentialMediationRequirement =
30
- | 'conditional'
31
- | 'optional'
32
- | 'required'
33
- | 'silent'
34
-
35
- /** @internal */
36
- export type PublicKeyCredentialType = 'public-key'
37
-
38
- /** @internal */
39
- export type ResidentKeyRequirement = 'discouraged' | 'preferred' | 'required'
40
-
41
- /** @internal */
42
- export type UserVerificationRequirement =
43
- | 'discouraged'
44
- | 'preferred'
45
- | 'required'
46
-
47
- /** @internal */
48
- export type LargeBlobSupport = {
49
- support: 'required' | 'preferred'
50
- }
51
-
52
- /** @internal */
53
- export type BufferSource = ArrayBufferView | ArrayBuffer
54
-
55
- /** @internal */
56
- export type PrfExtension = Record<'eval', Record<'first', Uint8Array>>
57
-
58
- /** @internal */
59
- export interface AuthenticationExtensionsClientInputs {
60
- appid?: string
61
- credProps?: boolean
62
- hmacCreateSecret?: boolean
63
- minPinLength?: boolean
64
- prf?: PrfExtension
65
- largeBlob?: LargeBlobSupport
66
- }
67
-
68
- /** @internal */
69
- export interface AuthenticatorSelectionCriteria {
70
- authenticatorAttachment?: AuthenticatorAttachment
71
- requireResidentKey?: boolean
72
- residentKey?: ResidentKeyRequirement
73
- userVerification?: UserVerificationRequirement
74
- }
75
-
76
- /** @internal */
77
- export interface Credential {
78
- readonly id: string
79
- readonly type: string
80
- }
81
-
82
- /** @internal */
83
- export interface CredentialCreationOptions {
84
- publicKey?: PublicKeyCredentialCreationOptions
85
- signal?: AbortSignal
86
- }
87
-
88
- /** @internal */
89
- export interface CredentialRequestOptions {
90
- mediation?: CredentialMediationRequirement
91
- publicKey?: PublicKeyCredentialRequestOptions
92
- signal?: AbortSignal
93
- }
94
-
95
- /** @internal */
96
- export interface PublicKeyCredential extends Credential {
97
- readonly authenticatorAttachment: string | null
98
- readonly rawId: ArrayBuffer
99
- readonly response: AuthenticatorResponse
100
- getClientExtensionResults(): AuthenticationExtensionsClientOutputs
101
- }
102
-
103
- /** @internal */
104
- export interface PublicKeyCredentialCreationOptions {
105
- attestation?: AttestationConveyancePreference
106
- authenticatorSelection?: AuthenticatorSelectionCriteria
107
- challenge: BufferSource
108
- excludeCredentials?: PublicKeyCredentialDescriptor[]
109
- extensions?: AuthenticationExtensionsClientInputs
110
- pubKeyCredParams: PublicKeyCredentialParameters[]
111
- rp: PublicKeyCredentialRpEntity
112
- timeout?: number
113
- user: PublicKeyCredentialUserEntity
114
- }
115
-
116
- /** @internal */
117
- export interface PublicKeyCredentialDescriptor {
118
- id: BufferSource
119
- transports?: AuthenticatorTransport[]
120
- type: PublicKeyCredentialType
121
- }
122
-
123
- /** @internal */
124
- export interface PublicKeyCredentialEntity {
125
- name: string
126
- }
127
-
128
- /** @internal */
129
- export interface PublicKeyCredentialParameters {
130
- alg: COSEAlgorithmIdentifier
131
- type: PublicKeyCredentialType
132
- }
133
-
134
- /** @internal */
135
- export interface PublicKeyCredentialRequestOptions {
136
- allowCredentials?: PublicKeyCredentialDescriptor[]
137
- challenge: BufferSource
138
- extensions?: AuthenticationExtensionsClientInputs
139
- rpId?: string
140
- timeout?: number
141
- userVerification?: UserVerificationRequirement
142
- }
143
-
144
- /** @internal */
145
- export interface PublicKeyCredentialRpEntity extends PublicKeyCredentialEntity {
146
- id?: string
147
- }
148
-
149
- /** @internal */
150
- export interface PublicKeyCredentialUserEntity
151
- extends PublicKeyCredentialEntity {
152
- displayName: string
153
- id: BufferSource
154
- }
155
5
 
156
6
  /**
157
7
  * Parses an ASN.1 signature into a r and s value.
@@ -159,17 +9,8 @@ export interface PublicKeyCredentialUserEntity
159
9
  * @internal
160
10
  */
161
11
  export function parseAsn1Signature(bytes: Uint8Array) {
162
- const r_start = bytes[4] === 0 ? 5 : 4
163
- const r_end = r_start + 32
164
- const s_start = bytes[r_end + 2] === 0 ? r_end + 3 : r_end + 2
165
-
166
- const r = BigInt(Hex.fromBytes(bytes.slice(r_start, r_end)))
167
- const s = BigInt(Hex.fromBytes(bytes.slice(s_start)))
168
-
169
- return {
170
- r,
171
- s: s > p256.CURVE.n / 2n ? p256.CURVE.n - s : s,
172
- }
12
+ const sig = p256.Signature.fromDER(bytes).normalizeS()
13
+ return { r: sig.r, s: sig.s }
173
14
  }
174
15
 
175
16
  /**
@@ -183,7 +24,7 @@ export async function parseCredentialPublicKey(
183
24
  ): Promise<PublicKey.PublicKey> {
184
25
  try {
185
26
  const publicKeyBuffer = response.getPublicKey()
186
- if (!publicKeyBuffer) throw new CredentialCreationFailedError()
27
+ if (!publicKeyBuffer) throw new Registration.CreateFailedError()
187
28
 
188
29
  // Converting `publicKeyBuffer` throws when credential is created by 1Password Firefox Add-on
189
30
  const publicKeyBytes = new Uint8Array(publicKeyBuffer)
@@ -218,7 +59,7 @@ export async function parseCredentialPublicKey(
218
59
  for (let i = 0; i < data.length - coordinate.length; i++)
219
60
  if (coordinate.every((byte, j) => data[i + j] === byte))
220
61
  return i + coordinate.length
221
- throw new CredentialCreationFailedError()
62
+ throw new Registration.CreateFailedError()
222
63
  }
223
64
 
224
65
  const xStart = findStart(0x21)
@@ -235,5 +76,5 @@ export async function parseCredentialPublicKey(
235
76
  }
236
77
 
237
78
  export declare namespace parseCredentialPublicKey {
238
- type ErrorType = CredentialCreationFailedError | Errors.GlobalErrorType
79
+ type ErrorType = Registration.CreateFailedError | Errors.GlobalErrorType
239
80
  }
package/erc8021/index.ts CHANGED
@@ -17,7 +17,7 @@ export type {}
17
17
  *
18
18
  * const dataSuffix2 = Attribution.toDataSuffix({
19
19
  * codes: ['baseapp', 'morpho'],
20
- * codeRegistryAddress: '0x...'
20
+ * codeRegistry: { address: '0x0000000000000000000000000000000000000000', chainId: 1 },
21
21
  * })
22
22
  * ```
23
23
  *
@@ -30,7 +30,7 @@ export type {}
30
30
  * const attribution = Attribution.fromData('0x...')
31
31
  *
32
32
  * console.log(attribution)
33
- * // @log: { codes: ['baseapp', 'morpho'], codeRegistryAddress: '0x...' }
33
+ * // @log: { codes: ['baseapp', 'morpho'], codeRegistry: { address: '0x...', chainId: 1 } }
34
34
  * ```
35
35
  *
36
36
  * @category ERC-8021
package/index.docs.ts CHANGED
@@ -7,4 +7,5 @@ export * from './erc6492/index.js'
7
7
  export * from './erc7821/index.js'
8
8
  export * from './erc8010/index.js'
9
9
  export * from './erc8021/index.js'
10
+ export * from './webauthn/index.js'
10
11
  export * from './tempo/index.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.12.4",
4
+ "version": "0.13.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -554,6 +554,36 @@
554
554
  "import": "./_esm/trusted-setups/index.js",
555
555
  "default": "./_cjs/trusted-setups/index.js"
556
556
  },
557
+ "./webauthn/Authentication": {
558
+ "types": "./_types/webauthn/Authentication.d.ts",
559
+ "import": "./_esm/webauthn/Authentication.js",
560
+ "default": "./_cjs/webauthn/Authentication.js"
561
+ },
562
+ "./webauthn/Authenticator": {
563
+ "types": "./_types/webauthn/Authenticator.d.ts",
564
+ "import": "./_esm/webauthn/Authenticator.js",
565
+ "default": "./_cjs/webauthn/Authenticator.js"
566
+ },
567
+ "./webauthn/Credential": {
568
+ "types": "./_types/webauthn/Credential.d.ts",
569
+ "import": "./_esm/webauthn/Credential.js",
570
+ "default": "./_cjs/webauthn/Credential.js"
571
+ },
572
+ "./webauthn/Registration": {
573
+ "types": "./_types/webauthn/Registration.d.ts",
574
+ "import": "./_esm/webauthn/Registration.js",
575
+ "default": "./_cjs/webauthn/Registration.js"
576
+ },
577
+ "./webauthn/Types": {
578
+ "types": "./_types/webauthn/Types.d.ts",
579
+ "import": "./_esm/webauthn/Types.js",
580
+ "default": "./_cjs/webauthn/Types.js"
581
+ },
582
+ "./webauthn": {
583
+ "types": "./_types/webauthn/index.d.ts",
584
+ "import": "./_esm/webauthn/index.js",
585
+ "default": "./_cjs/webauthn/index.js"
586
+ },
557
587
  "./window": {
558
588
  "types": "./_types/window/index.d.ts",
559
589
  "import": "./_esm/window/index.js",
@@ -13,7 +13,7 @@ import type { Call } from './TxEnvelopeTempo.js'
13
13
  /**
14
14
  * A Transaction as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/transaction.yaml).
15
15
  *
16
- * @see {@link https://docs.tempo.xyz/protocol/transactions Tempo Transactions}
16
+ * @see {@link https://docs.tempo.xyz/protocol/transactions}
17
17
  */
18
18
  export type Transaction<
19
19
  pending extends boolean = false,
@@ -39,7 +39,7 @@ export type Rpc<pending extends boolean = false> = UnionCompute<
39
39
  * Features configurable fee tokens, call batching, fee sponsorship, access keys,
40
40
  * parallelizable nonces, and scheduled execution via `validAfter`/`validBefore`.
41
41
  *
42
- * @see {@link https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction Tempo Transaction Specification}
42
+ * @see {@link https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction}
43
43
  */
44
44
  export type Tempo<
45
45
  pending extends boolean = false,
@@ -9,7 +9,7 @@ import * as ox_TransactionReceipt from '../core/TransactionReceipt.js'
9
9
  * Extends standard receipts with `feePayer` (the address that paid fees) and
10
10
  * `feeToken` (the TIP-20 token used for fee payment).
11
11
  *
12
- * @see {@link https://docs.tempo.xyz/protocol/transactions Tempo Transactions}
12
+ * @see {@link https://docs.tempo.xyz/protocol/transactions}
13
13
  */
14
14
  export type TransactionReceipt<
15
15
  status = ox_TransactionReceipt.Status,
@@ -60,7 +60,7 @@ export const toRpcType = {
60
60
  /**
61
61
  * Converts an RPC receipt to a TransactionReceipt.
62
62
  *
63
- * @see {@link https://docs.tempo.xyz/protocol/transactions Tempo Transactions}
63
+ * @see {@link https://docs.tempo.xyz/protocol/transactions}
64
64
  *
65
65
  * @example
66
66
  * ```ts twoslash
@@ -16,7 +16,7 @@ type KeyType = 'secp256k1' | 'p256' | 'webAuthn'
16
16
  * Extends the [Execution API specification](https://github.com/ethereum/execution-apis/blob/4aca1d7a3e5aab24c8f6437131289ad386944eaa/src/schemas/transaction.yaml#L358-L423)
17
17
  * with Tempo-specific fields for batched calls, fee tokens, access keys, and scheduled execution.
18
18
  *
19
- * @see {@link https://docs.tempo.xyz/protocol/transactions Tempo Transactions}
19
+ * @see {@link https://docs.tempo.xyz/protocol/transactions}
20
20
  */
21
21
  export type TransactionRequest<
22
22
  bigintType = bigint,
@@ -54,7 +54,7 @@ export type Rpc = Omit<
54
54
  /**
55
55
  * Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#TransactionRequest.Rpc}.
56
56
  *
57
- * @see {@link https://docs.tempo.xyz/protocol/transactions Tempo Transactions}
57
+ * @see {@link https://docs.tempo.xyz/protocol/transactions}
58
58
  *
59
59
  * @example
60
60
  * ```ts twoslash
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.12.4'
2
+ export const version = '0.13.0'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/webauthn/Authentication.d.ts",
4
+ "main": "../../_cjs/webauthn/Authentication.js",
5
+ "module": "../../_esm/webauthn/Authentication.js"
6
+ }