@0xsequence/wallet-primitives 3.0.0-beta.9 → 3.0.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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +28 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +85 -0
- package/dist/attestation.d.ts +15 -3
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +1 -1
- package/dist/attestation.js.map +1 -1
- package/dist/config.d.ts +40 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -7
- package/dist/config.js.map +1 -1
- package/dist/extensions/recovery.d.ts +4 -4
- package/dist/extensions/recovery.d.ts.map +1 -1
- package/dist/extensions/recovery.js +2 -2
- package/dist/extensions/recovery.js.map +1 -1
- package/dist/network.d.ts +9 -1
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +212 -8
- package/dist/network.js.map +1 -1
- package/dist/payload.d.ts.map +1 -1
- package/dist/payload.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +8 -6
- package/dist/signature.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +12 -0
- package/package.json +7 -5
- package/src/attestation.ts +16 -4
- package/src/config.ts +62 -20
- package/src/extensions/recovery.ts +7 -8
- package/src/network.ts +226 -9
- package/src/payload.ts +1 -1
- package/src/signature.ts +10 -8
- package/src/utils.ts +2 -2
- package/test/address.test.ts +9 -9
- package/test/attestation.test.ts +1 -1
- package/test/config.test.ts +1 -1
- package/test/passkeys.test.ts +3 -10
- package/test/payload.test.ts +2 -7
- package/test/precondition.test.ts +6 -8
- package/test/signature.test.ts +11 -17
- package/test/utils.test.ts +4 -4
- package/eslint.config.mjs +0 -4
package/src/config.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Address, Bytes, Hash, Hex } from 'ox'
|
|
|
2
2
|
import {
|
|
3
3
|
isRawConfig,
|
|
4
4
|
isRawNestedLeaf,
|
|
5
|
-
isRawNode,
|
|
6
5
|
isRawSignerLeaf,
|
|
7
6
|
isSignedSapientSignerLeaf,
|
|
8
7
|
isSignedSignerLeaf,
|
|
@@ -55,6 +54,49 @@ export type Leaf = SignerLeaf | SapientSignerLeaf | SubdigestLeaf | AnyAddressSu
|
|
|
55
54
|
|
|
56
55
|
export type Topology = Node | Leaf
|
|
57
56
|
|
|
57
|
+
/** Encoded topology types for JSON serialization */
|
|
58
|
+
type EncodedSignerLeaf = {
|
|
59
|
+
type: 'signer'
|
|
60
|
+
address: Address.Address
|
|
61
|
+
weight: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type EncodedSapientSignerLeaf = {
|
|
65
|
+
type: 'sapient-signer'
|
|
66
|
+
address: Address.Address
|
|
67
|
+
weight: string
|
|
68
|
+
imageHash: Hex.Hex
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type EncodedSubdigestLeaf = {
|
|
72
|
+
type: 'subdigest'
|
|
73
|
+
digest: Hex.Hex
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type EncodedAnyAddressSubdigestLeaf = {
|
|
77
|
+
type: 'any-address-subdigest'
|
|
78
|
+
digest: Hex.Hex
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type EncodedNestedLeaf = {
|
|
82
|
+
type: 'nested'
|
|
83
|
+
tree: EncodedTopology
|
|
84
|
+
weight: string
|
|
85
|
+
threshold: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type EncodedNodeLeaf = Hex.Hex
|
|
89
|
+
|
|
90
|
+
export type EncodedLeaf =
|
|
91
|
+
| EncodedSignerLeaf
|
|
92
|
+
| EncodedSapientSignerLeaf
|
|
93
|
+
| EncodedSubdigestLeaf
|
|
94
|
+
| EncodedAnyAddressSubdigestLeaf
|
|
95
|
+
| EncodedNestedLeaf
|
|
96
|
+
| EncodedNodeLeaf
|
|
97
|
+
export type EncodedNode = [EncodedTopology, EncodedTopology]
|
|
98
|
+
export type EncodedTopology = EncodedNode | EncodedLeaf
|
|
99
|
+
|
|
58
100
|
export type Config = {
|
|
59
101
|
threshold: bigint
|
|
60
102
|
checkpoint: bigint
|
|
@@ -62,39 +104,39 @@ export type Config = {
|
|
|
62
104
|
checkpointer?: Address.Address
|
|
63
105
|
}
|
|
64
106
|
|
|
65
|
-
export function isSignerLeaf(cand:
|
|
66
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'signer'
|
|
107
|
+
export function isSignerLeaf(cand: unknown): cand is SignerLeaf {
|
|
108
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'signer'
|
|
67
109
|
}
|
|
68
110
|
|
|
69
|
-
export function isSapientSignerLeaf(cand:
|
|
70
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'sapient-signer'
|
|
111
|
+
export function isSapientSignerLeaf(cand: unknown): cand is SapientSignerLeaf {
|
|
112
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'sapient-signer'
|
|
71
113
|
}
|
|
72
114
|
|
|
73
|
-
export function isSubdigestLeaf(cand:
|
|
74
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'subdigest'
|
|
115
|
+
export function isSubdigestLeaf(cand: unknown): cand is SubdigestLeaf {
|
|
116
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'subdigest'
|
|
75
117
|
}
|
|
76
118
|
|
|
77
|
-
export function isAnyAddressSubdigestLeaf(cand:
|
|
78
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'any-address-subdigest'
|
|
119
|
+
export function isAnyAddressSubdigestLeaf(cand: unknown): cand is AnyAddressSubdigestLeaf {
|
|
120
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'any-address-subdigest'
|
|
79
121
|
}
|
|
80
122
|
|
|
81
|
-
export function isNodeLeaf(cand:
|
|
82
|
-
return Hex.validate(cand) && cand.length === 66
|
|
123
|
+
export function isNodeLeaf(cand: unknown): cand is NodeLeaf {
|
|
124
|
+
return typeof cand === 'string' && Hex.validate(cand) && cand.length === 66
|
|
83
125
|
}
|
|
84
126
|
|
|
85
|
-
export function isNestedLeaf(cand:
|
|
86
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'nested'
|
|
127
|
+
export function isNestedLeaf(cand: unknown): cand is NestedLeaf {
|
|
128
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'nested'
|
|
87
129
|
}
|
|
88
130
|
|
|
89
|
-
export function isNode(cand:
|
|
131
|
+
export function isNode(cand: unknown): cand is Node {
|
|
90
132
|
return Array.isArray(cand) && cand.length === 2 && isTopology(cand[0]) && isTopology(cand[1])
|
|
91
133
|
}
|
|
92
134
|
|
|
93
|
-
export function isConfig(cand:
|
|
94
|
-
return typeof cand === 'object' && 'threshold' in cand && 'checkpoint' in cand && 'topology' in cand
|
|
135
|
+
export function isConfig(cand: unknown): cand is Config {
|
|
136
|
+
return typeof cand === 'object' && cand !== null && 'threshold' in cand && 'checkpoint' in cand && 'topology' in cand
|
|
95
137
|
}
|
|
96
138
|
|
|
97
|
-
export function isLeaf(cand:
|
|
139
|
+
export function isLeaf(cand: unknown): cand is Leaf {
|
|
98
140
|
return (
|
|
99
141
|
isSignerLeaf(cand) ||
|
|
100
142
|
isSapientSignerLeaf(cand) ||
|
|
@@ -105,7 +147,7 @@ export function isLeaf(cand: Topology): cand is Leaf {
|
|
|
105
147
|
)
|
|
106
148
|
}
|
|
107
149
|
|
|
108
|
-
export function isTopology(cand:
|
|
150
|
+
export function isTopology(cand: unknown): cand is Topology {
|
|
109
151
|
return isNode(cand) || isLeaf(cand)
|
|
110
152
|
}
|
|
111
153
|
|
|
@@ -310,7 +352,7 @@ export function configFromJson(json: string): Config {
|
|
|
310
352
|
}
|
|
311
353
|
}
|
|
312
354
|
|
|
313
|
-
function encodeTopology(top: Topology):
|
|
355
|
+
function encodeTopology(top: Topology): EncodedTopology {
|
|
314
356
|
if (isNode(top)) {
|
|
315
357
|
return [encodeTopology(top[0]), encodeTopology(top[1])]
|
|
316
358
|
} else if (isSignerLeaf(top)) {
|
|
@@ -350,7 +392,7 @@ function encodeTopology(top: Topology): any {
|
|
|
350
392
|
throw new Error('Invalid topology')
|
|
351
393
|
}
|
|
352
394
|
|
|
353
|
-
function decodeTopology(obj:
|
|
395
|
+
function decodeTopology(obj: EncodedTopology): Topology {
|
|
354
396
|
if (Array.isArray(obj)) {
|
|
355
397
|
if (obj.length !== 2) {
|
|
356
398
|
throw new Error('Invalid node structure in JSON')
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Abi, AbiFunction, Address, Bytes, Hex, Provider } from 'ox'
|
|
2
2
|
import * as GenericTree from '../generic-tree.js'
|
|
3
3
|
import { Signature } from '../index.js'
|
|
4
|
-
import * as Network from '../network.js'
|
|
5
4
|
import * as Payload from '../payload.js'
|
|
6
5
|
import { packRSY } from '../utils.js'
|
|
7
6
|
|
|
@@ -56,21 +55,21 @@ export type Tree = Branch | GenericTree.Node | RecoveryLeaf
|
|
|
56
55
|
/**
|
|
57
56
|
* Type guard to check if a value is a RecoveryLeaf
|
|
58
57
|
*/
|
|
59
|
-
export function isRecoveryLeaf(cand:
|
|
60
|
-
return typeof cand === 'object' && cand !== null && cand.type === 'leaf'
|
|
58
|
+
export function isRecoveryLeaf(cand: unknown): cand is RecoveryLeaf {
|
|
59
|
+
return typeof cand === 'object' && cand !== null && 'type' in cand && cand.type === 'leaf'
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
63
|
* Type guard to check if a value is a Node (pair of subtrees)
|
|
65
64
|
*/
|
|
66
|
-
export function isBranch(cand:
|
|
65
|
+
export function isBranch(cand: unknown): cand is Branch {
|
|
67
66
|
return Array.isArray(cand) && cand.length === 2 && isTree(cand[0]) && isTree(cand[1])
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
70
|
* Type guard to check if a value is a Topology
|
|
72
71
|
*/
|
|
73
|
-
export function isTree(cand:
|
|
72
|
+
export function isTree(cand: unknown): cand is Tree {
|
|
74
73
|
return isRecoveryLeaf(cand) || GenericTree.isNode(cand) || isBranch(cand)
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -203,7 +202,7 @@ export function parseBranch(encoded: Bytes.Bytes): { nodes: Tree[]; leftover: By
|
|
|
203
202
|
*/
|
|
204
203
|
export function trimTopology(topology: Tree, signer: Address.Address): Tree {
|
|
205
204
|
if (isRecoveryLeaf(topology)) {
|
|
206
|
-
if (topology.signer
|
|
205
|
+
if (Address.isEqual(topology.signer, signer)) {
|
|
207
206
|
return topology
|
|
208
207
|
} else {
|
|
209
208
|
return hashConfiguration(topology)
|
|
@@ -437,10 +436,10 @@ export function fromGenericTree(tree: GenericTree.Tree): Tree {
|
|
|
437
436
|
*/
|
|
438
437
|
export function encodeCalldata(
|
|
439
438
|
wallet: Address.Address,
|
|
440
|
-
payload: Payload.Recovery<
|
|
439
|
+
payload: Payload.Recovery<Payload.MayRecoveryPayload>,
|
|
441
440
|
signer: Address.Address,
|
|
442
441
|
signature: Signature.SignatureOfSignerLeaf,
|
|
443
|
-
) {
|
|
442
|
+
): Hex.Hex {
|
|
444
443
|
let signatureBytes: Hex.Hex
|
|
445
444
|
|
|
446
445
|
if (signature.type === 'erc1271') {
|