passkey-kit 0.12.1 → 0.14.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 (172) hide show
  1. package/README.md +408 -227
  2. package/{types → dist}/base.d.ts +1 -0
  3. package/dist/base.d.ts.map +1 -0
  4. package/{src/base.ts → dist/base.js} +8 -10
  5. package/dist/base.js.map +1 -0
  6. package/dist/base64url.d.ts +18 -0
  7. package/dist/base64url.d.ts.map +1 -0
  8. package/dist/base64url.js +18 -0
  9. package/dist/base64url.js.map +1 -0
  10. package/dist/constants.d.ts +91 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +115 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/contract-errors.d.ts +69 -0
  15. package/dist/contract-errors.d.ts.map +1 -0
  16. package/dist/contract-errors.js +132 -0
  17. package/dist/contract-errors.js.map +1 -0
  18. package/dist/errors.d.ts +163 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +244 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/events.d.ts +94 -0
  23. package/dist/events.d.ts.map +1 -0
  24. package/dist/events.js +92 -0
  25. package/dist/events.js.map +1 -0
  26. package/dist/index.d.ts +22 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +36 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/indexer/codec.d.ts +18 -0
  31. package/dist/indexer/codec.d.ts.map +1 -0
  32. package/dist/indexer/codec.js +32 -0
  33. package/dist/indexer/codec.js.map +1 -0
  34. package/dist/indexer/index.d.ts +25 -0
  35. package/dist/indexer/index.d.ts.map +1 -0
  36. package/dist/indexer/index.js +34 -0
  37. package/dist/indexer/index.js.map +1 -0
  38. package/dist/indexer/mercury.d.ts +94 -0
  39. package/dist/indexer/mercury.d.ts.map +1 -0
  40. package/dist/indexer/mercury.js +245 -0
  41. package/dist/indexer/mercury.js.map +1 -0
  42. package/dist/indexer/stellar-indexer.d.ts +115 -0
  43. package/dist/indexer/stellar-indexer.d.ts.map +1 -0
  44. package/dist/indexer/stellar-indexer.js +279 -0
  45. package/dist/indexer/stellar-indexer.js.map +1 -0
  46. package/dist/indexer/types.d.ts +73 -0
  47. package/dist/indexer/types.d.ts.map +1 -0
  48. package/dist/indexer/types.js +9 -0
  49. package/dist/indexer/types.js.map +1 -0
  50. package/dist/kit/auth-payload.d.ts +106 -0
  51. package/dist/kit/auth-payload.d.ts.map +1 -0
  52. package/dist/kit/auth-payload.js +227 -0
  53. package/dist/kit/auth-payload.js.map +1 -0
  54. package/dist/kit/deploy-ops.d.ts +45 -0
  55. package/dist/kit/deploy-ops.d.ts.map +1 -0
  56. package/dist/kit/deploy-ops.js +69 -0
  57. package/dist/kit/deploy-ops.js.map +1 -0
  58. package/dist/kit/tx-ops.d.ts +95 -0
  59. package/dist/kit/tx-ops.d.ts.map +1 -0
  60. package/dist/kit/tx-ops.js +125 -0
  61. package/dist/kit/tx-ops.js.map +1 -0
  62. package/dist/kit/wallet-ops.d.ts +59 -0
  63. package/dist/kit/wallet-ops.d.ts.map +1 -0
  64. package/dist/kit/wallet-ops.js +122 -0
  65. package/dist/kit/wallet-ops.js.map +1 -0
  66. package/dist/kit/webauthn-ops.d.ts +55 -0
  67. package/dist/kit/webauthn-ops.d.ts.map +1 -0
  68. package/dist/kit/webauthn-ops.js +79 -0
  69. package/dist/kit/webauthn-ops.js.map +1 -0
  70. package/dist/kit.d.ts +132 -0
  71. package/dist/kit.d.ts.map +1 -0
  72. package/dist/kit.js +290 -0
  73. package/dist/kit.js.map +1 -0
  74. package/dist/managers/credential-manager.d.ts +39 -0
  75. package/dist/managers/credential-manager.d.ts.map +1 -0
  76. package/dist/managers/credential-manager.js +47 -0
  77. package/dist/managers/credential-manager.js.map +1 -0
  78. package/dist/managers/index.d.ts +7 -0
  79. package/dist/managers/index.d.ts.map +1 -0
  80. package/dist/managers/index.js +7 -0
  81. package/dist/managers/index.js.map +1 -0
  82. package/dist/managers/signer-manager.d.ts +62 -0
  83. package/dist/managers/signer-manager.d.ts.map +1 -0
  84. package/dist/managers/signer-manager.js +111 -0
  85. package/dist/managers/signer-manager.js.map +1 -0
  86. package/dist/managers/submission-manager.d.ts +52 -0
  87. package/dist/managers/submission-manager.d.ts.map +1 -0
  88. package/dist/managers/submission-manager.js +77 -0
  89. package/dist/managers/submission-manager.js.map +1 -0
  90. package/dist/relayer.d.ts +61 -0
  91. package/dist/relayer.d.ts.map +1 -0
  92. package/dist/relayer.js +122 -0
  93. package/dist/relayer.js.map +1 -0
  94. package/dist/rpc-data.d.ts +45 -0
  95. package/dist/rpc-data.d.ts.map +1 -0
  96. package/dist/rpc-data.js +61 -0
  97. package/dist/rpc-data.js.map +1 -0
  98. package/dist/sac.d.ts +31 -0
  99. package/dist/sac.d.ts.map +1 -0
  100. package/dist/sac.js +47 -0
  101. package/dist/sac.js.map +1 -0
  102. package/dist/server.d.ts +79 -0
  103. package/dist/server.d.ts.map +1 -0
  104. package/dist/server.js +152 -0
  105. package/dist/server.js.map +1 -0
  106. package/dist/signers.d.ts +83 -0
  107. package/dist/signers.d.ts.map +1 -0
  108. package/dist/signers.js +124 -0
  109. package/dist/signers.js.map +1 -0
  110. package/dist/storage/index.d.ts +13 -0
  111. package/dist/storage/index.d.ts.map +1 -0
  112. package/dist/storage/index.js +12 -0
  113. package/dist/storage/index.js.map +1 -0
  114. package/dist/storage/indexeddb.d.ts +26 -0
  115. package/dist/storage/indexeddb.d.ts.map +1 -0
  116. package/dist/storage/indexeddb.js +100 -0
  117. package/dist/storage/indexeddb.js.map +1 -0
  118. package/dist/storage/localStorage.d.ts +22 -0
  119. package/dist/storage/localStorage.d.ts.map +1 -0
  120. package/dist/storage/localStorage.js +86 -0
  121. package/dist/storage/localStorage.js.map +1 -0
  122. package/dist/storage/memory.d.ts +18 -0
  123. package/dist/storage/memory.d.ts.map +1 -0
  124. package/dist/storage/memory.js +41 -0
  125. package/dist/storage/memory.js.map +1 -0
  126. package/dist/types.d.ts +136 -0
  127. package/dist/types.d.ts.map +1 -0
  128. package/dist/types.js +39 -0
  129. package/dist/types.js.map +1 -0
  130. package/dist/utils.d.ts +72 -0
  131. package/dist/utils.d.ts.map +1 -0
  132. package/dist/utils.js +253 -0
  133. package/dist/utils.js.map +1 -0
  134. package/dist/validation.d.ts +42 -0
  135. package/dist/validation.d.ts.map +1 -0
  136. package/dist/validation.js +75 -0
  137. package/dist/validation.js.map +1 -0
  138. package/dist/version.d.ts +7 -0
  139. package/dist/version.d.ts.map +1 -0
  140. package/dist/version.js +9 -0
  141. package/dist/version.js.map +1 -0
  142. package/package.json +47 -20
  143. package/.claude/settings.local.json +0 -20
  144. package/.cursorrules +0 -170
  145. package/.gitattributes +0 -2
  146. package/.github/workflows/release.yml +0 -21
  147. package/.vscode/settings.json +0 -6
  148. package/PROPOSAL.md +0 -397
  149. package/cheatsheet.txt +0 -18
  150. package/clone-js-sdk.sh +0 -21
  151. package/packages/passkey-kit-sdk/README.md +0 -54
  152. package/packages/passkey-kit-sdk/package.json +0 -21
  153. package/packages/passkey-kit-sdk/src/index.ts +0 -171
  154. package/packages/passkey-kit-sdk/tsconfig.json +0 -98
  155. package/packages/passkey-kit-sdk/types/index.d.ts +0 -190
  156. package/packages/sac-sdk/README.md +0 -54
  157. package/packages/sac-sdk/package.json +0 -21
  158. package/packages/sac-sdk/src/index.ts +0 -586
  159. package/packages/sac-sdk/tsconfig.json +0 -98
  160. package/packages/sac-sdk/types/index.d.ts +0 -532
  161. package/pnpm-workspace.yaml +0 -2
  162. package/src/index.ts +0 -5
  163. package/src/kit.ts +0 -823
  164. package/src/sac.ts +0 -29
  165. package/src/server.ts +0 -179
  166. package/src/types.ts +0 -32
  167. package/tsconfig.json +0 -28
  168. package/types/index.d.ts +0 -5
  169. package/types/kit.d.ts +0 -95
  170. package/types/sac.d.ts +0 -13
  171. package/types/server.d.ts +0 -29
  172. package/types/types.d.ts +0 -22
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Soroban authorization-entry payload helpers + the flat `Signatures` map codec.
3
+ *
4
+ * These are thin wrappers over the stellar-sdk's native Protocol-27 auth
5
+ * primitives (`buildAuthorizationEntryPreimage`). The old kit hand-rolled a
6
+ * stack of "does this SDK support P27?" probe shims; on stellar-sdk >= 16 those
7
+ * are all dead, so this module simply uses the SDK.
8
+ *
9
+ * The smart wallet's `__check_auth` reads a `Signatures` value — a single
10
+ * `Map<SignerKey, Signature>` — from the address credentials. Each signer
11
+ * contributes one entry keyed by its on-chain `SignerKey`. The host rejects an
12
+ * `ScMap` whose keys are not in the host's canonical sort order, so the map is
13
+ * sorted with {@link compareScVal} (NOT a byte/`localeCompare` sort — see below).
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { buildAuthorizationEntryPreimage, hash, xdr, } from "@stellar/stellar-sdk";
18
+ import { SigningError, PasskeyKitErrorCode } from "../errors.js";
19
+ // ============================================================================
20
+ // Address credentials + signature payload
21
+ // ============================================================================
22
+ /**
23
+ * Extract the {@link xdr.SorobanAddressCredentials} from a credentials union,
24
+ * for the address / addressV2 / addressWithDelegates variants.
25
+ *
26
+ * @throws {SigningError} If the credentials are not address-based.
27
+ */
28
+ export function getAddressCredentials(credentials) {
29
+ switch (credentials.switch().name) {
30
+ case "sorobanCredentialsAddress":
31
+ return credentials.address();
32
+ case "sorobanCredentialsAddressV2":
33
+ return credentials.addressV2();
34
+ case "sorobanCredentialsAddressWithDelegates":
35
+ return credentials.addressWithDelegates().addressCredentials();
36
+ default:
37
+ throw new SigningError(`Soroban credentials do not contain address credentials: ${credentials.switch().name}`, PasskeyKitErrorCode.UNSUPPORTED_CREDENTIALS);
38
+ }
39
+ }
40
+ /**
41
+ * Whether a credentials union uses an address-bound signature payload (the P27
42
+ * V2 / with-delegates variants), whose preimage binds the invoker address.
43
+ */
44
+ export function usesAddressBoundPayload(credentials) {
45
+ const name = credentials.switch().name;
46
+ return (name === "sorobanCredentialsAddressV2" ||
47
+ name === "sorobanCredentialsAddressWithDelegates");
48
+ }
49
+ /**
50
+ * Coerce a credentials union to an address-bound variant (CAP-0071-02).
51
+ *
52
+ * Legacy V1 `sorobanCredentialsAddress` credentials are upgraded to
53
+ * `sorobanCredentialsAddressV2` IN PLACE of the signed payload's semantics: the
54
+ * V2 preimage (`HashIdPreimageSorobanAuthorizationWithAddress`) binds the
55
+ * authorizing address into the hash the signer signs, so the same signer key on
56
+ * two different wallets can never produce interchangeable signatures. V1's
57
+ * preimage has no address field — signing it verbatim would produce a payload
58
+ * that is identical across wallets for a signer key installed on more than
59
+ * one wallet.
60
+ *
61
+ * Already-address-bound variants (V2, with-delegates) pass through unchanged.
62
+ *
63
+ * @throws {SigningError} If the credentials are not address-based.
64
+ */
65
+ export function toAddressBoundCredentials(credentials) {
66
+ if (credentials.switch().name === "sorobanCredentialsAddress") {
67
+ return xdr.SorobanCredentials.sorobanCredentialsAddressV2(credentials.address());
68
+ }
69
+ // Anything else must already be address-bound (or is rejected here).
70
+ getAddressCredentials(credentials);
71
+ return credentials;
72
+ }
73
+ /**
74
+ * Assert that a signature-expiration ledger is a valid `u32`.
75
+ *
76
+ * @throws {SigningError} If not a `u32` integer.
77
+ */
78
+ export function assertSignatureExpirationLedger(expiration) {
79
+ if (!Number.isInteger(expiration) ||
80
+ expiration < 0 ||
81
+ expiration > 0xffffffff) {
82
+ throw new SigningError("Soroban signature expiration ledger must be a uint32 integer", PasskeyKitErrorCode.INVALID_SIGNATURE_EXPIRATION, { expiration });
83
+ }
84
+ }
85
+ /**
86
+ * Build the signature payload (the 32-byte hash a signer signs) for an
87
+ * authorization entry at a given expiration ledger.
88
+ *
89
+ * Sets the expiration on the entry's address credentials, then hashes the SDK's
90
+ * canonical authorization-entry preimage. Works for the address, addressV2, and
91
+ * addressWithDelegates credential variants.
92
+ *
93
+ * @throws {SigningError} If `expiration` is not a valid `u32`.
94
+ */
95
+ export function buildSignaturePayload(networkPassphrase, entry, expiration) {
96
+ assertSignatureExpirationLedger(expiration);
97
+ const credentials = getAddressCredentials(entry.credentials());
98
+ credentials.signatureExpirationLedger(expiration);
99
+ return hash(buildAuthorizationEntryPreimage(entry, expiration, networkPassphrase).toXDR());
100
+ }
101
+ // ============================================================================
102
+ // Host-order ScVal comparison
103
+ // ============================================================================
104
+ /**
105
+ * Compare two ScVals in the order the Soroban host uses when it validates that
106
+ * an ScMap is sorted by key (host `metered_map::from_map`, which rejects an
107
+ * unsorted map with `InvalidInput`).
108
+ *
109
+ * This is deliberately NOT a comparison of the XDR byte encodings. XDR prefixes
110
+ * every variable-length payload (Bytes, Symbol, String, Vec) with a 4-byte
111
+ * length, so `toXDR("hex")` sorting is length-major; the host instead compares
112
+ * those payloads element-wise by content (Rust slice `Ord`), where a shorter
113
+ * value that is a prefix of a longer one sorts first. The old kit's
114
+ * `localeCompare` on a symbol+hex string approximated this and could diverge
115
+ * from the host, producing a map the wallet rejects at `__check_auth`.
116
+ *
117
+ * Only the shapes that appear as `SignerKey` map keys are handled precisely
118
+ * (Vec, Symbol, String, Bytes, Address). All other shapes are same-type here
119
+ * (the discriminant is compared first), so their fixed-width XDR encodings sort
120
+ * order-equivalently to the host.
121
+ */
122
+ export function compareScVal(a, b) {
123
+ const aType = a.switch().value;
124
+ const bType = b.switch().value;
125
+ if (aType !== bType) {
126
+ return aType < bType ? -1 : 1;
127
+ }
128
+ switch (a.switch().name) {
129
+ case "scvVec": {
130
+ const av = a.vec() ?? [];
131
+ const bv = b.vec() ?? [];
132
+ const len = Math.min(av.length, bv.length);
133
+ for (let i = 0; i < len; i += 1) {
134
+ const cmp = compareScVal(av[i], bv[i]);
135
+ if (cmp !== 0)
136
+ return cmp;
137
+ }
138
+ return av.length - bv.length;
139
+ }
140
+ case "scvMap": {
141
+ const am = a.map() ?? [];
142
+ const bm = b.map() ?? [];
143
+ const len = Math.min(am.length, bm.length);
144
+ for (let i = 0; i < len; i += 1) {
145
+ const keyCmp = compareScVal(am[i].key(), bm[i].key());
146
+ if (keyCmp !== 0)
147
+ return keyCmp;
148
+ const valCmp = compareScVal(am[i].val(), bm[i].val());
149
+ if (valCmp !== 0)
150
+ return valCmp;
151
+ }
152
+ return am.length - bm.length;
153
+ }
154
+ case "scvSymbol":
155
+ return Buffer.compare(Buffer.from(a.sym().toString(), "utf8"), Buffer.from(b.sym().toString(), "utf8"));
156
+ case "scvString":
157
+ return Buffer.compare(Buffer.from(a.str().toString(), "utf8"), Buffer.from(b.str().toString(), "utf8"));
158
+ case "scvBytes":
159
+ return Buffer.compare(Buffer.from(a.bytes()), Buffer.from(b.bytes()));
160
+ case "scvAddress":
161
+ // ScAddress is a type discriminant plus a fixed-width key, so a byte
162
+ // comparison of the encoding matches the host's (type, key) ordering.
163
+ return Buffer.compare(a.address().toXDR(), b.address().toXDR());
164
+ default:
165
+ // Same-type scalar (or any unhandled shape): its XDR encoding is
166
+ // fixed-width for a given type, so a byte comparison is order-equivalent.
167
+ return Buffer.compare(a.toXDR(), b.toXDR());
168
+ }
169
+ }
170
+ // ============================================================================
171
+ // SignerKey / Signature encoding + the flat Signatures map
172
+ // ============================================================================
173
+ const SIGNER_KEY_UDT = xdr.ScSpecTypeDef.scSpecTypeUdt(new xdr.ScSpecTypeUdt({ name: "SignerKey" }));
174
+ const SIGNATURE_UDT = xdr.ScSpecTypeDef.scSpecTypeUdt(new xdr.ScSpecTypeUdt({ name: "Signature" }));
175
+ /** The `SignerVal` UDT type def, for decoding a stored signer entry's value. */
176
+ export const SIGNER_VAL_UDT = xdr.ScSpecTypeDef.scSpecTypeUdt(new xdr.ScSpecTypeUdt({ name: "SignerVal" }));
177
+ /** Encode a native `SignerKey` union into its contract ScVal via the spec. */
178
+ export function signerKeyToScVal(spec, key) {
179
+ return spec.nativeToScVal(key, SIGNER_KEY_UDT);
180
+ }
181
+ /**
182
+ * Encode a native `Signature` union into its contract ScVal via the spec, or
183
+ * `scvVoid` when there is no signature value (policy signers).
184
+ */
185
+ export function signatureToScVal(spec, val) {
186
+ return val ? spec.nativeToScVal(val, SIGNATURE_UDT) : xdr.ScVal.scvVoid();
187
+ }
188
+ /**
189
+ * Upsert a `(SignerKey, Signature)` pair into the entry's `Signatures` value,
190
+ * which is encoded as `scvVec([ scvMap([...]) ])`.
191
+ *
192
+ * A signer key already present in the map is replaced (co-signing is idempotent
193
+ * per signer). The map is re-sorted by key in host order after every insert, so
194
+ * the wallet's `__check_auth` accepts it.
195
+ *
196
+ * @throws {SigningError} If the existing signature is neither void nor a
197
+ * Signatures vec.
198
+ */
199
+ export function upsertSignatureEntry(credentials, scKey, scVal) {
200
+ const newEntry = new xdr.ScMapEntry({ key: scKey, val: scVal });
201
+ switch (credentials.signature().switch().name) {
202
+ case "scvVoid": {
203
+ credentials.signature(xdr.ScVal.scvVec([xdr.ScVal.scvMap([newEntry])]));
204
+ break;
205
+ }
206
+ case "scvVec": {
207
+ const map = credentials.signature().vec()?.[0]?.map();
208
+ if (!map) {
209
+ throw new SigningError("Malformed Signatures value: expected a map inside the signatures vector", PasskeyKitErrorCode.SIGNING_FAILED);
210
+ }
211
+ const existingIndex = map.findIndex((entry) => compareScVal(entry.key(), scKey) === 0);
212
+ if (existingIndex >= 0) {
213
+ map[existingIndex] = newEntry;
214
+ }
215
+ else {
216
+ map.push(newEntry);
217
+ }
218
+ // Host order: the wallet converts this map to a host object and rejects
219
+ // it if the keys are not in host-sort order.
220
+ map.sort((x, y) => compareScVal(x.key(), y.key()));
221
+ break;
222
+ }
223
+ default:
224
+ throw new SigningError(`Unsupported existing signature value: ${credentials.signature().switch().name}`, PasskeyKitErrorCode.SIGNING_FAILED);
225
+ }
226
+ }
227
+ //# sourceMappingURL=auth-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-payload.js","sourceRoot":"","sources":["../../src/kit/auth-payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,+BAA+B,EAC/B,IAAI,EACJ,GAAG,GACJ,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE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AAC,CAAC,EAAE,GAAG,EAAE,CAAC;YACtD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,YAAY,CACpB,yEAAyE,EACzE,mBAAmB,CAAC,cAAc,CACnC,CAAC;YACJ,CAAC;YACD,MAAM,aAAa,GAAG,GAAG,CAAC,SAAS,CACjC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAClD,CAAC;YACF,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;gBACvB,GAAG,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrB,CAAC;YACD,wEAAwE;YACxE,6CAA6C;YAC7C,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YACnD,MAAM;QACR,CAAC;QACD;YACE,MAAM,IAAI,YAAY,CACpB,yCAAyC,WAAW,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAChF,mBAAmB,CAAC,cAAc,CACnC,CAAC;IACN,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Smart-wallet deployment operations.
3
+ *
4
+ * The deployer keypair is now configurable (`config.deploySource`) instead of a
5
+ * hard-coded `Keypair.fromRawEd25519Seed(hash("kalepail"))`. The default still
6
+ * derives from {@link DEFAULT_DEPLOYER_SEED} = `"kalepail"` so contract-id
7
+ * determinism (and indexer reverse-lookup) is preserved out of the box.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { Keypair } from "@stellar/stellar-sdk";
12
+ import type { AssembledTransaction } from "@stellar/stellar-sdk/contract";
13
+ import { Client as PasskeyClient } from "passkey-kit-sdk";
14
+ /**
15
+ * Resolve the fee-paying deployer keypair from an optional secret.
16
+ *
17
+ * With no secret, derives the canonical deterministic deployer from
18
+ * {@link DEFAULT_DEPLOYER_SEED}. The deployer only pays fees and salts the
19
+ * deploy; it never controls the wallet. Supplying a different `deploySource`
20
+ * changes the derived contract addresses (and breaks keyId → contract
21
+ * discovery), so this is documented as an advanced option.
22
+ *
23
+ * @throws {ConfigurationError} If `deploySource` is not a valid secret key.
24
+ */
25
+ export declare function resolveDeployer(deploySource?: string): Keypair;
26
+ /** Deterministically derive a smart-wallet address for a passkey credential. */
27
+ export declare function deriveWalletAddress(deps: {
28
+ networkPassphrase: string;
29
+ deployerPublicKey: string;
30
+ }, keyId: Buffer): string;
31
+ /**
32
+ * Build the smart-wallet deploy transaction, initializing it with the passkey as
33
+ * the first (unlimited, persistent) Secp256r1 signer via `__constructor`.
34
+ *
35
+ * The returned {@link AssembledTransaction} still needs to be signed by the
36
+ * deployer keypair (the fee source) before submission.
37
+ */
38
+ export declare function buildDeployTransaction(deps: {
39
+ rpcUrl: string;
40
+ networkPassphrase: string;
41
+ walletWasmHash: string;
42
+ deployerPublicKey: string;
43
+ timeoutInSeconds: number;
44
+ }, keyId: Buffer, publicKey: Uint8Array): Promise<AssembledTransaction<PasskeyClient>>;
45
+ //# sourceMappingURL=deploy-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-ops.d.ts","sourceRoot":"","sources":["../../src/kit/deploy-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAQ,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,MAAM,IAAI,aAAa,EAExB,MAAM,iBAAiB,CAAC;AAKzB;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAY9D;AAED,gFAAgF;AAChF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAC9D,KAAK,EAAE,MAAM,GACZ,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B,EACD,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CAuB9C"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Smart-wallet deployment operations.
3
+ *
4
+ * The deployer keypair is now configurable (`config.deploySource`) instead of a
5
+ * hard-coded `Keypair.fromRawEd25519Seed(hash("kalepail"))`. The default still
6
+ * derives from {@link DEFAULT_DEPLOYER_SEED} = `"kalepail"` so contract-id
7
+ * determinism (and indexer reverse-lookup) is preserved out of the box.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { Keypair, hash } from "@stellar/stellar-sdk";
12
+ import { Client as PasskeyClient, } from "passkey-kit-sdk";
13
+ import { DEFAULT_DEPLOYER_SEED } from "../constants.js";
14
+ import { deriveContractAddress } from "../utils.js";
15
+ import { ConfigurationError, PasskeyKitErrorCode } from "../errors.js";
16
+ /**
17
+ * Resolve the fee-paying deployer keypair from an optional secret.
18
+ *
19
+ * With no secret, derives the canonical deterministic deployer from
20
+ * {@link DEFAULT_DEPLOYER_SEED}. The deployer only pays fees and salts the
21
+ * deploy; it never controls the wallet. Supplying a different `deploySource`
22
+ * changes the derived contract addresses (and breaks keyId → contract
23
+ * discovery), so this is documented as an advanced option.
24
+ *
25
+ * @throws {ConfigurationError} If `deploySource` is not a valid secret key.
26
+ */
27
+ export function resolveDeployer(deploySource) {
28
+ if (deploySource) {
29
+ try {
30
+ return Keypair.fromSecret(deploySource);
31
+ }
32
+ catch {
33
+ throw new ConfigurationError("deploySource must be a valid Stellar secret key (S…)", PasskeyKitErrorCode.INVALID_CONFIG);
34
+ }
35
+ }
36
+ return Keypair.fromRawEd25519Seed(hash(Buffer.from(DEFAULT_DEPLOYER_SEED)));
37
+ }
38
+ /** Deterministically derive a smart-wallet address for a passkey credential. */
39
+ export function deriveWalletAddress(deps, keyId) {
40
+ return deriveContractAddress(keyId, deps.deployerPublicKey, deps.networkPassphrase);
41
+ }
42
+ /**
43
+ * Build the smart-wallet deploy transaction, initializing it with the passkey as
44
+ * the first (unlimited, persistent) Secp256r1 signer via `__constructor`.
45
+ *
46
+ * The returned {@link AssembledTransaction} still needs to be signed by the
47
+ * deployer keypair (the fee source) before submission.
48
+ */
49
+ export async function buildDeployTransaction(deps, keyId, publicKey) {
50
+ const signer = {
51
+ tag: "Secp256r1",
52
+ values: [
53
+ Buffer.from(keyId),
54
+ Buffer.from(publicKey),
55
+ [undefined], // SignerExpiration: none
56
+ [undefined], // SignerLimits: unlimited
57
+ { tag: "Persistent", values: undefined },
58
+ ],
59
+ };
60
+ return PasskeyClient.deploy({ signer }, {
61
+ rpcUrl: deps.rpcUrl,
62
+ wasmHash: deps.walletWasmHash,
63
+ networkPassphrase: deps.networkPassphrase,
64
+ publicKey: deps.deployerPublicKey,
65
+ salt: hash(keyId),
66
+ timeoutInSeconds: deps.timeoutInSeconds,
67
+ });
68
+ }
69
+ //# sourceMappingURL=deploy-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-ops.js","sourceRoot":"","sources":["../../src/kit/deploy-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EACL,MAAM,IAAI,aAAa,GAExB,MAAM,iBAAiB,CAAC;AACz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AC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,cAAc;QAC7B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;QACzC,SAAS,EAAE,IAAI,CAAC,iBAAiB;QACjC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;QACjB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;KACxC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Transaction-signing operations: the auth-entry signing pipeline and the
3
+ * `AssembledTransaction` signing entrypoint.
4
+ *
5
+ * Two deliberate changes from the old kit:
6
+ * - `sign` takes a single explicit `AssembledTransaction<T>` instead of the
7
+ * lossy `AssembledTransaction | Tx | string` tri-input that silently dropped
8
+ * memo/fee/operations on its fallback path (#599 §6). Callers holding XDR use
9
+ * `AssembledTransaction.fromXDR` first.
10
+ * - The `Signatures` map is sorted with the host-order `compareScVal`, not the
11
+ * old `localeCompare` string approximation.
12
+ * - Signing is address-bound only: V1 address credentials are upgraded to
13
+ * CAP-0071-02 V2 before the payload is hashed (`toAddressBoundCredentials`),
14
+ * and there is no V1 signing path.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { xdr } from "@stellar/stellar-sdk";
19
+ import type { Keypair } from "@stellar/stellar-sdk";
20
+ import type { Server } from "@stellar/stellar-sdk/rpc";
21
+ import type { AssembledTransaction, Spec as ContractSpec } from "@stellar/stellar-sdk/contract";
22
+ import type { Signer, SignerContext } from "../signers.js";
23
+ /** Deps for computing a default signature-expiration ledger. */
24
+ export interface ExpirationDeps {
25
+ rpc: Server;
26
+ timeoutInSeconds: number;
27
+ }
28
+ /**
29
+ * Compute a default signature-expiration ledger: the latest ledger plus the
30
+ * timeout window (assuming ~5s ledgers), rounded up.
31
+ */
32
+ export declare function calculateExpiration(deps: ExpirationDeps): Promise<number>;
33
+ /** Deps for signing a single auth entry. */
34
+ export interface SignAuthEntryDeps {
35
+ networkPassphrase: string;
36
+ spec: ContractSpec;
37
+ signerContext: SignerContext;
38
+ calculateExpiration: () => Promise<number>;
39
+ }
40
+ /** Per-call signing options. */
41
+ export interface SignOptions {
42
+ /** Signature expiration ledger (defaults to the configured window). */
43
+ expiration?: number;
44
+ }
45
+ /**
46
+ * Sign a single Soroban authorization entry with a {@link Signer}, merging the
47
+ * resulting `(SignerKey, Signature)` pair into the entry's flat `Signatures`
48
+ * map (host-ordered).
49
+ *
50
+ * Mutates and returns the passed entry.
51
+ */
52
+ export declare function signAuthEntry(deps: SignAuthEntryDeps, entry: xdr.SorobanAuthorizationEntry, signer: Signer, options?: SignOptions): Promise<xdr.SorobanAuthorizationEntry>;
53
+ /** Deps for signing an assembled transaction's auth entries. */
54
+ export interface SignTxDeps extends SignAuthEntryDeps {
55
+ getContractId: () => string | undefined;
56
+ }
57
+ /**
58
+ * Sign every auth entry of an {@link AssembledTransaction} that is authorized by
59
+ * the connected wallet, using `signer`. Returns the same transaction with its
60
+ * auth entries signed.
61
+ *
62
+ * @throws {SigningError} If no wallet is connected.
63
+ */
64
+ export declare function sign<T>(deps: SignTxDeps, txn: AssembledTransaction<T>, signer: Signer, options?: SignOptions): Promise<AssembledTransaction<T>>;
65
+ /**
66
+ * The `restorePreamble` shape Soroban simulation returns when a transaction
67
+ * touches archived entries (a subset of the SDK's `SimulateTransactionResponse`).
68
+ */
69
+ export interface RestorePreamble {
70
+ minResourceFee: string;
71
+ transactionData: {
72
+ build(): xdr.SorobanTransactionData;
73
+ };
74
+ }
75
+ /**
76
+ * Restore an archived contract-data footprint reported by simulation, paying
77
+ * with the deployer keypair.
78
+ *
79
+ * Soroban simulation returns a `restorePreamble` when the transaction touches
80
+ * archived entries; the footprint must be restored (a separate, fee-bearing
81
+ * transaction) before the real transaction can succeed. The deployer keypair
82
+ * pays because it is the on-chain fee source the kit already controls.
83
+ *
84
+ * Returns the restore transaction hash. This path is exercised live in F2 (it
85
+ * requires archived on-chain state to trigger).
86
+ *
87
+ * @throws {SigningError} On submission/confirmation failure.
88
+ */
89
+ export declare function restoreFootprint(deps: {
90
+ rpc: Server;
91
+ networkPassphrase: string;
92
+ deployerKeypair: Keypair;
93
+ timeoutInSeconds: number;
94
+ }, restorePreamble: RestorePreamble): Promise<string>;
95
+ //# sourceMappingURL=tx-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx-ops.d.ts","sourceRoot":"","sources":["../../src/kit/tx-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAiC,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,oBAAoB,EACpB,IAAI,IAAI,YAAY,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAY3D,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAG/E;AAED,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,GAAG,CAAC,yBAAyB,EACpC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CA6CxC;AAED,gEAAgE;AAChE,MAAM,WAAW,UAAW,SAAQ,iBAAiB;IACnD,aAAa,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAC1B,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAkBlC;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE;QAAE,KAAK,IAAI,GAAG,CAAC,sBAAsB,CAAA;KAAE,CAAC;CAC1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE;IACJ,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,EACD,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,MAAM,CAAC,CAkCjB"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Transaction-signing operations: the auth-entry signing pipeline and the
3
+ * `AssembledTransaction` signing entrypoint.
4
+ *
5
+ * Two deliberate changes from the old kit:
6
+ * - `sign` takes a single explicit `AssembledTransaction<T>` instead of the
7
+ * lossy `AssembledTransaction | Tx | string` tri-input that silently dropped
8
+ * memo/fee/operations on its fallback path (#599 §6). Callers holding XDR use
9
+ * `AssembledTransaction.fromXDR` first.
10
+ * - The `Signatures` map is sorted with the host-order `compareScVal`, not the
11
+ * old `localeCompare` string approximation.
12
+ * - Signing is address-bound only: V1 address credentials are upgraded to
13
+ * CAP-0071-02 V2 before the payload is hashed (`toAddressBoundCredentials`),
14
+ * and there is no V1 signing path.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { Operation, TransactionBuilder, xdr } from "@stellar/stellar-sdk";
19
+ import { buildSignaturePayload, getAddressCredentials, signatureToScVal, signerKeyToScVal, toAddressBoundCredentials, upsertSignatureEntry, usesAddressBoundPayload, } from "./auth-payload.js";
20
+ import { SigningError, PasskeyKitError, PasskeyKitErrorCode } from "../errors.js";
21
+ /**
22
+ * Compute a default signature-expiration ledger: the latest ledger plus the
23
+ * timeout window (assuming ~5s ledgers), rounded up.
24
+ */
25
+ export async function calculateExpiration(deps) {
26
+ const { sequence } = await deps.rpc.getLatestLedger();
27
+ return Math.ceil(sequence + deps.timeoutInSeconds / 5);
28
+ }
29
+ /**
30
+ * Sign a single Soroban authorization entry with a {@link Signer}, merging the
31
+ * resulting `(SignerKey, Signature)` pair into the entry's flat `Signatures`
32
+ * map (host-ordered).
33
+ *
34
+ * Mutates and returns the passed entry.
35
+ */
36
+ export async function signAuthEntry(deps, entry, signer, options) {
37
+ if (entry.credentials().switch().name === "sorobanCredentialsAddressWithDelegates") {
38
+ throw new SigningError("ADDRESS_WITH_DELEGATES auth entries are not supported by passkey signing", PasskeyKitErrorCode.UNSUPPORTED_CREDENTIALS);
39
+ }
40
+ // Address-bound credentials only (CAP-0071-02): a legacy V1 address entry is
41
+ // upgraded to V2 before anything is hashed, so the wallet address is bound
42
+ // into the signed preimage. There is deliberately NO V1 signing path — a V1
43
+ // payload hash is identical across wallets for an address-free invocation,
44
+ // so it does not bind the signature to this wallet.
45
+ entry.credentials(toAddressBoundCredentials(entry.credentials()));
46
+ if (!usesAddressBoundPayload(entry.credentials())) {
47
+ throw new SigningError(`Refusing to sign a non-address-bound auth entry: ${entry.credentials().switch().name}`, PasskeyKitErrorCode.UNSUPPORTED_CREDENTIALS);
48
+ }
49
+ const credentials = getAddressCredentials(entry.credentials());
50
+ // `== null`, not `!expiration`: an explicit `expiration: 0` is a caller-chosen
51
+ // value, not "unset" — only undefined/null falls through to the entry's
52
+ // existing ledger or a freshly computed default.
53
+ let expiration = options?.expiration;
54
+ if (expiration == null) {
55
+ expiration = credentials.signatureExpirationLedger();
56
+ if (!expiration) {
57
+ expiration = await deps.calculateExpiration();
58
+ }
59
+ }
60
+ // Sets credentials.signatureExpirationLedger(expiration) as a side effect.
61
+ const payload = buildSignaturePayload(deps.networkPassphrase, entry, expiration);
62
+ const prepared = await signer.sign(payload, deps.signerContext);
63
+ const scKey = signerKeyToScVal(deps.spec, prepared.key);
64
+ const scVal = signatureToScVal(deps.spec, prepared.value);
65
+ upsertSignatureEntry(credentials, scKey, scVal);
66
+ return entry;
67
+ }
68
+ /**
69
+ * Sign every auth entry of an {@link AssembledTransaction} that is authorized by
70
+ * the connected wallet, using `signer`. Returns the same transaction with its
71
+ * auth entries signed.
72
+ *
73
+ * @throws {SigningError} If no wallet is connected.
74
+ */
75
+ export async function sign(deps, txn, signer, options) {
76
+ const contractId = deps.getContractId();
77
+ if (!contractId) {
78
+ throw new SigningError("A wallet must be connected to sign a transaction", PasskeyKitErrorCode.SIGNING_FAILED);
79
+ }
80
+ await txn.signAuthEntries({
81
+ address: contractId,
82
+ authorizeEntry: async (entry) => {
83
+ const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR());
84
+ return signAuthEntry(deps, clone, signer, options);
85
+ },
86
+ });
87
+ return txn;
88
+ }
89
+ /**
90
+ * Restore an archived contract-data footprint reported by simulation, paying
91
+ * with the deployer keypair.
92
+ *
93
+ * Soroban simulation returns a `restorePreamble` when the transaction touches
94
+ * archived entries; the footprint must be restored (a separate, fee-bearing
95
+ * transaction) before the real transaction can succeed. The deployer keypair
96
+ * pays because it is the on-chain fee source the kit already controls.
97
+ *
98
+ * Returns the restore transaction hash. This path is exercised live in F2 (it
99
+ * requires archived on-chain state to trigger).
100
+ *
101
+ * @throws {SigningError} On submission/confirmation failure.
102
+ */
103
+ export async function restoreFootprint(deps, restorePreamble) {
104
+ const account = await deps.rpc.getAccount(deps.deployerKeypair.publicKey());
105
+ const fee = (Number(restorePreamble.minResourceFee) + 100_000).toString();
106
+ const restoreTx = new TransactionBuilder(account, {
107
+ fee,
108
+ networkPassphrase: deps.networkPassphrase,
109
+ })
110
+ .addOperation(Operation.restoreFootprint({}))
111
+ .setSorobanData(restorePreamble.transactionData.build())
112
+ .setTimeout(deps.timeoutInSeconds)
113
+ .build();
114
+ restoreTx.sign(deps.deployerKeypair);
115
+ const sendResult = await deps.rpc.sendTransaction(restoreTx);
116
+ if (sendResult.status === "ERROR") {
117
+ throw new PasskeyKitError(`Footprint restore submission failed: ${sendResult.errorResult?.toXDR("base64") ?? "unknown"}`, PasskeyKitErrorCode.RESTORE_REQUIRED, { context: { hash: sendResult.hash } });
118
+ }
119
+ const result = await deps.rpc.pollTransaction(sendResult.hash, { attempts: 10 });
120
+ if (result.status !== "SUCCESS") {
121
+ throw new PasskeyKitError(`Footprint restore did not confirm (status ${result.status})`, PasskeyKitErrorCode.RESTORE_REQUIRED, { context: { hash: sendResult.hash } });
122
+ }
123
+ return sendResult.hash;
124
+ }
125
+ //# sourceMappingURL=tx-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx-ops.js","sourceRoot":"","sources":["../../src/kit/tx-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAQ1E,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQlF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAoB;IAC5D,MAAM,EAAE,QAAQ,EA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