ox 0.14.5 → 0.14.7

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 (58) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/tempo/AuthorizationTempo.js.map +1 -1
  3. package/_cjs/tempo/KeyAuthorization.js.map +1 -1
  4. package/_cjs/tempo/PoolId.js.map +1 -1
  5. package/_cjs/tempo/TempoAddress.js.map +1 -1
  6. package/_cjs/tempo/TokenId.js.map +1 -1
  7. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
  8. package/_cjs/version.js +1 -1
  9. package/_cjs/webauthn/Authentication.js +8 -1
  10. package/_cjs/webauthn/Authentication.js.map +1 -1
  11. package/_cjs/webauthn/Credential.js +8 -1
  12. package/_cjs/webauthn/Credential.js.map +1 -1
  13. package/_cjs/webauthn/Registration.js +8 -1
  14. package/_cjs/webauthn/Registration.js.map +1 -1
  15. package/_esm/tempo/AuthorizationTempo.js.map +1 -1
  16. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  17. package/_esm/tempo/PoolId.js.map +1 -1
  18. package/_esm/tempo/TempoAddress.js.map +1 -1
  19. package/_esm/tempo/TokenId.js.map +1 -1
  20. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
  21. package/_esm/version.js +1 -1
  22. package/_esm/webauthn/Authentication.js +8 -1
  23. package/_esm/webauthn/Authentication.js.map +1 -1
  24. package/_esm/webauthn/Credential.js +11 -1
  25. package/_esm/webauthn/Credential.js.map +1 -1
  26. package/_esm/webauthn/Registration.js +8 -1
  27. package/_esm/webauthn/Registration.js.map +1 -1
  28. package/_types/tempo/AuthorizationTempo.d.ts +4 -4
  29. package/_types/tempo/AuthorizationTempo.d.ts.map +1 -1
  30. package/_types/tempo/KeyAuthorization.d.ts +11 -9
  31. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  32. package/_types/tempo/PoolId.d.ts +3 -2
  33. package/_types/tempo/PoolId.d.ts.map +1 -1
  34. package/_types/tempo/TempoAddress.d.ts +4 -0
  35. package/_types/tempo/TempoAddress.d.ts.map +1 -1
  36. package/_types/tempo/TokenId.d.ts +2 -2
  37. package/_types/tempo/TokenId.d.ts.map +1 -1
  38. package/_types/tempo/TransactionRequest.d.ts +1 -1
  39. package/_types/tempo/TransactionRequest.d.ts.map +1 -1
  40. package/_types/tempo/TxEnvelopeTempo.d.ts +9 -7
  41. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  42. package/_types/version.d.ts +1 -1
  43. package/_types/webauthn/Authentication.d.ts.map +1 -1
  44. package/_types/webauthn/Credential.d.ts.map +1 -1
  45. package/_types/webauthn/Registration.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/tempo/AuthorizationTempo.test.ts +6 -6
  48. package/tempo/AuthorizationTempo.ts +8 -5
  49. package/tempo/KeyAuthorization.ts +26 -15
  50. package/tempo/PoolId.ts +3 -2
  51. package/tempo/TempoAddress.ts +9 -0
  52. package/tempo/TokenId.ts +6 -2
  53. package/tempo/TransactionRequest.ts +1 -1
  54. package/tempo/TxEnvelopeTempo.ts +25 -13
  55. package/version.ts +1 -1
  56. package/webauthn/Authentication.ts +8 -1
  57. package/webauthn/Credential.ts +11 -1
  58. package/webauthn/Registration.ts +8 -3
@@ -32,15 +32,16 @@ export type KeyAuthorization<
32
32
  signed extends boolean = boolean,
33
33
  bigintType = bigint,
34
34
  numberType = number,
35
+ addressType = Address.Address,
35
36
  > = {
36
37
  /** Address derived from the public key of the key type. */
37
- address: TempoAddress.Address
38
+ address: addressType
38
39
  /** Chain ID for replay protection. */
39
40
  chainId: bigintType
40
41
  /** Unix timestamp when key expires (0 = never expires). */
41
42
  expiry?: numberType | null | undefined
42
43
  /** TIP20 spending limits for this key. */
43
- limits?: readonly TokenLimit<bigintType>[] | undefined
44
+ limits?: readonly TokenLimit<bigintType, addressType>[] | undefined
44
45
  /** Key type. (secp256k1, P256, WebAuthn). */
45
46
  type: SignatureEnvelope.Type
46
47
  } & (signed extends true
@@ -51,6 +52,14 @@ export type KeyAuthorization<
51
52
  | undefined
52
53
  })
53
54
 
55
+ /** Input type for a Key Authorization. */
56
+ export type Input = KeyAuthorization<
57
+ false,
58
+ bigint,
59
+ number,
60
+ TempoAddress.Address
61
+ >
62
+
54
63
  /** RPC representation of an {@link ox#KeyAuthorization.KeyAuthorization}. */
55
64
  export type Rpc = Omit<
56
65
  KeyAuthorization<false, Hex.Hex, Hex.Hex>,
@@ -62,11 +71,11 @@ export type Rpc = Omit<
62
71
  }
63
72
 
64
73
  /** Signed representation of a Key Authorization. */
65
- export type Signed<bigintType = bigint, numberType = number> = KeyAuthorization<
66
- true,
67
- bigintType,
68
- numberType
69
- >
74
+ export type Signed<
75
+ bigintType = bigint,
76
+ numberType = number,
77
+ addressType = Address.Address,
78
+ > = KeyAuthorization<true, bigintType, numberType, addressType>
70
79
 
71
80
  type BaseTuple = readonly [
72
81
  chainId: Hex.Hex,
@@ -106,9 +115,9 @@ export type Tuple<signed extends boolean = boolean> = signed extends true
106
115
  *
107
116
  * [Access Keys Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#access-keys)
108
117
  */
109
- export type TokenLimit<bigintType = bigint> = {
118
+ export type TokenLimit<bigintType = bigint, addressType = Address.Address> = {
110
119
  /** Address of the TIP-20 token. */
111
- token: TempoAddress.Address
120
+ token: addressType
112
121
  /** Maximum spending amount for this token (enforced over the key's lifetime). */
113
122
  limit: bigintType
114
123
  }
@@ -250,7 +259,7 @@ export type TokenLimit<bigintType = bigint> = {
250
259
  * @returns The {@link ox#KeyAuthorization.KeyAuthorization}.
251
260
  */
252
261
  export function from<
253
- const authorization extends KeyAuthorization | Rpc,
262
+ const authorization extends Input | Rpc,
254
263
  const signature extends SignatureEnvelope.from.Value | undefined = undefined,
255
264
  >(
256
265
  authorization: authorization | KeyAuthorization,
@@ -291,17 +300,19 @@ export declare namespace from {
291
300
  }
292
301
 
293
302
  type ReturnType<
294
- authorization extends KeyAuthorization | Rpc = KeyAuthorization,
303
+ authorization extends KeyAuthorization | Input | Rpc = KeyAuthorization,
295
304
  signature extends SignatureEnvelope.from.Value | undefined =
296
305
  | SignatureEnvelope.from.Value
297
306
  | undefined,
298
307
  > = Compute<
299
308
  authorization extends Rpc
300
309
  ? Signed
301
- : authorization &
302
- (signature extends SignatureEnvelope.from.Value
303
- ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
304
- : {})
310
+ : TempoAddress.ResolveAddresses<
311
+ authorization &
312
+ (signature extends SignatureEnvelope.from.Value
313
+ ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
314
+ : {})
315
+ >
305
316
  >
306
317
 
307
318
  type ErrorType = Errors.GlobalErrorType
package/tempo/PoolId.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as Hash from '../core/Hash.js'
2
2
  import * as Hex from '../core/Hex.js'
3
+ import type * as TempoAddress from './TempoAddress.js'
3
4
  import * as TokenId from './TokenId.js'
4
5
 
5
6
  /**
@@ -35,8 +36,8 @@ export function from(value: from.Value): Hex.Hex {
35
36
  export declare namespace from {
36
37
  export type Value = {
37
38
  /** User token. */
38
- userToken: TokenId.TokenIdOrAddress
39
+ userToken: TokenId.TokenIdOrAddress<TempoAddress.Address>
39
40
  /** Validator token. */
40
- validatorToken: TokenId.TokenIdOrAddress
41
+ validatorToken: TokenId.TokenIdOrAddress<TempoAddress.Address>
41
42
  }
42
43
  }
@@ -9,6 +9,15 @@ export type Address = core_Address.Address | Tempo
9
9
  /** Root type for a Tempo Address. */
10
10
  export type Tempo = Compute<`tempox${string}`>
11
11
 
12
+ /** Deeply converts all {@link ox#TempoAddress.Tempo} types to {@link ox#Address.Address}. */
13
+ export type ResolveAddresses<type> = type extends Tempo
14
+ ? core_Address.Address
15
+ : type extends readonly (infer item)[]
16
+ ? readonly ResolveAddresses<item>[]
17
+ : type extends object
18
+ ? { [key in keyof type]: ResolveAddresses<type[key]> }
19
+ : type
20
+
12
21
  /**
13
22
  * Resolves an address input (either an Ethereum hex address or a Tempo address)
14
23
  * to an Ethereum hex address.
package/tempo/TokenId.ts CHANGED
@@ -7,7 +7,9 @@ import * as TempoAddress from './TempoAddress.js'
7
7
  const tip20Prefix = '0x20c0'
8
8
 
9
9
  export type TokenId = bigint
10
- export type TokenIdOrAddress = TokenId | TempoAddress.Address
10
+ export type TokenIdOrAddress<addressType = Address.Address> =
11
+ | TokenId
12
+ | addressType
11
13
 
12
14
  /**
13
15
  * Converts a token ID or address to a token ID.
@@ -73,7 +75,9 @@ export function fromAddress(address: TempoAddress.Address): TokenId {
73
75
  * @param tokenId - The token ID.
74
76
  * @returns The address.
75
77
  */
76
- export function toAddress(tokenId: TokenIdOrAddress): Address.Address {
78
+ export function toAddress(
79
+ tokenId: TokenIdOrAddress<TempoAddress.Address>,
80
+ ): Address.Address {
77
81
  if (typeof tokenId === 'string') {
78
82
  const resolved = TempoAddress.resolve(tokenId as TempoAddress.Address)
79
83
  Address.assert(resolved)
@@ -35,7 +35,7 @@ export type TransactionRequest<
35
35
  keyAuthorization?: KeyAuthorization.KeyAuthorization<true> | undefined
36
36
  keyData?: Hex.Hex | undefined
37
37
  keyType?: KeyType | undefined
38
- feeToken?: TokenId.TokenIdOrAddress | undefined
38
+ feeToken?: TokenId.TokenIdOrAddress<TempoAddress.Address> | undefined
39
39
  nonceKey?: 'random' | bigintType | undefined
40
40
  validBefore?: numberType | undefined
41
41
  validAfter?: numberType | undefined
@@ -69,6 +69,7 @@ export type TxEnvelopeTempo<
69
69
  bigintType = bigint,
70
70
  numberType = number,
71
71
  type extends string = Type,
72
+ addressType = Address.Address,
72
73
  > = Compute<
73
74
  {
74
75
  /** EIP-2930 Access List. */
@@ -78,11 +79,11 @@ export type TxEnvelopeTempo<
78
79
  | AuthorizationTempo.ListSigned<bigintType, numberType>
79
80
  | undefined
80
81
  /** Array of calls to execute. */
81
- calls: readonly Call<bigintType, TempoAddress.Address>[]
82
+ calls: readonly Call<bigintType, addressType>[]
82
83
  /** EIP-155 Chain ID. */
83
84
  chainId: numberType
84
85
  /** Sender of the transaction. */
85
- from?: TempoAddress.Address | undefined
86
+ from?: addressType | undefined
86
87
  /** Gas provided for transaction execution */
87
88
  gas?: bigintType | undefined
88
89
  /** Fee payer signature. */
@@ -100,7 +101,7 @@ export type TxEnvelopeTempo<
100
101
  * The authorization must be signed with the root key, the tx can be signed by the Keychain signature.
101
102
  */
102
103
  keyAuthorization?:
103
- | KeyAuthorization.Signed<bigintType, numberType>
104
+ | KeyAuthorization.Signed<bigintType, numberType, addressType>
104
105
  | undefined
105
106
  /** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). */
106
107
  maxFeePerGas?: bigintType | undefined
@@ -127,6 +128,15 @@ export type TxEnvelopeTempo<
127
128
  })
128
129
  >
129
130
 
131
+ /** Input type that accepts TempoAddress for `calls.to`, `from`, etc. */
132
+ export type Input = TxEnvelopeTempo<
133
+ boolean,
134
+ bigint,
135
+ number,
136
+ Type,
137
+ TempoAddress.Address
138
+ >
139
+
130
140
  export type Rpc<signed extends boolean = boolean> = TxEnvelopeTempo<
131
141
  signed,
132
142
  Hex.Hex,
@@ -486,10 +496,10 @@ export declare namespace deserialize {
486
496
  * @returns A Tempo Transaction Envelope.
487
497
  */
488
498
  export function from<
489
- const envelope extends UnionPartialBy<TxEnvelopeTempo, 'type'> | Serialized,
499
+ const envelope extends UnionPartialBy<Input, 'type'> | Serialized,
490
500
  const signature extends SignatureEnvelope.from.Value | undefined = undefined,
491
501
  >(
492
- envelope: envelope | UnionPartialBy<TxEnvelopeTempo, 'type'> | Serialized,
502
+ envelope: envelope | UnionPartialBy<Input, 'type'> | Serialized,
493
503
  options: from.Options<signature> = {},
494
504
  ): from.ReturnValue<envelope, signature> {
495
505
  const { feePayerSignature, signature } = options
@@ -532,20 +542,22 @@ export declare namespace from {
532
542
  }
533
543
 
534
544
  type ReturnValue<
535
- envelope extends UnionPartialBy<TxEnvelopeTempo, 'type'> | Hex.Hex =
545
+ envelope extends UnionPartialBy<Input, 'type'> | Hex.Hex =
536
546
  | TxEnvelopeTempo
537
547
  | Hex.Hex,
538
548
  signature extends SignatureEnvelope.from.Value | undefined = undefined,
539
549
  > = Compute<
540
550
  envelope extends Hex.Hex
541
551
  ? TxEnvelopeTempo
542
- : Assign<
543
- envelope,
544
- (signature extends SignatureEnvelope.from.Value
545
- ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
546
- : {}) & {
547
- readonly type: 'tempo'
548
- }
552
+ : TempoAddress.ResolveAddresses<
553
+ Assign<
554
+ envelope,
555
+ (signature extends SignatureEnvelope.from.Value
556
+ ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
557
+ : {}) & {
558
+ readonly type: 'tempo'
559
+ }
560
+ >
549
561
  >
550
562
  >
551
563
 
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.5'
2
+ export const version = '0.14.7'
@@ -408,7 +408,14 @@ export function serializeResponse(response: Response): Response<true> {
408
408
 
409
409
  const rawResponse = {} as Record<string, string>
410
410
  for (const key of responseKeys) {
411
- const value = (raw.response as unknown as Record<string, unknown>)[key]
411
+ const r = raw.response as unknown as Record<string, unknown>
412
+ let value = r[key]
413
+ if (!(value instanceof ArrayBuffer)) {
414
+ const getter =
415
+ `get${key[0]!.toUpperCase()}${key.slice(1)}` as keyof typeof r
416
+ const fn = r[getter]
417
+ if (typeof fn === 'function') value = fn.call(r)
418
+ }
412
419
  if (value instanceof ArrayBuffer)
413
420
  rawResponse[key] = Base64.fromBytes(
414
421
  new Uint8Array(value),
@@ -53,7 +53,17 @@ export function serialize(credential: Credential): Credential<true> {
53
53
 
54
54
  const response = {} as Record<string, string>
55
55
  for (const key of responseKeys) {
56
- const value = (raw.response as unknown as Record<string, unknown>)[key]
56
+ const r = raw.response as unknown as Record<string, unknown>
57
+ let value = r[key]
58
+ // Some properties (e.g. `authenticatorData`) are only accessible via
59
+ // getter methods (e.g. `getAuthenticatorData()`) in certain browsers
60
+ // and passkey providers.
61
+ if (!(value instanceof ArrayBuffer)) {
62
+ const getter =
63
+ `get${key[0]!.toUpperCase()}${key.slice(1)}` as keyof typeof r
64
+ const fn = r[getter]
65
+ if (typeof fn === 'function') value = fn.call(r)
66
+ }
57
67
  if (value instanceof ArrayBuffer)
58
68
  response[key] = Base64.fromBytes(new Uint8Array(value), base64UrlOptions)
59
69
  }
@@ -302,9 +302,14 @@ export function serializeResponse(response: Response): Response<true> {
302
302
 
303
303
  const rawResponse = {} as Record<string, string>
304
304
  for (const key of responseKeys) {
305
- const value = (
306
- credential.raw.response as unknown as Record<string, unknown>
307
- )[key]
305
+ const r = credential.raw.response as unknown as Record<string, unknown>
306
+ let value = r[key]
307
+ if (!(value instanceof ArrayBuffer)) {
308
+ const getter =
309
+ `get${key[0]!.toUpperCase()}${key.slice(1)}` as keyof typeof r
310
+ const fn = r[getter]
311
+ if (typeof fn === 'function') value = fn.call(r)
312
+ }
308
313
  if (value instanceof ArrayBuffer)
309
314
  rawResponse[key] = Base64.fromBytes(
310
315
  new Uint8Array(value),