@outpost-protocol/core 0.2.0 → 0.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.
@@ -5,6 +5,7 @@
5
5
  * and 100% asset-agnostic across all Stellar SAC and SEP-41 token contracts.
6
6
  */
7
7
  import * as StellarSdk from "@stellar/stellar-sdk";
8
+ import { type HwKind, type HwProof } from "./hw.js";
8
9
  import { type IndexedWitnessSignature, type Smeshc1Packet } from "./wire.js";
9
10
  import { type WireAddress } from "./xdr.js";
10
11
  /**
@@ -176,3 +177,80 @@ export interface OnChainPocketState {
176
177
  * Returns `null` when `ScVal` is `scvVoid` (`None`).
177
178
  */
178
179
  export declare function decodePocketStateScVal(scVal: StellarSdk.xdr.ScVal): OnChainPocketState | null;
180
+ /** Encodes a v2 [`HwProof`] into its exact Soroban `ScVal` enum representation (`scvVec`). */
181
+ export declare function encodeHwProofScVal(proof: HwProof): StellarSdk.xdr.ScVal;
182
+ /** Build `UserVault.deposit_hw(...)` Soroban operation (v2 Hardware Roaming Pocket). */
183
+ export declare function buildDepositHwOp(params: {
184
+ readonly vaultId: string | WireAddress | Uint8Array;
185
+ readonly pocketId: number;
186
+ readonly token: string | WireAddress | Uint8Array;
187
+ readonly amount: bigint;
188
+ readonly hwKind: HwKind;
189
+ readonly maxSeq: number;
190
+ readonly hwAnchor: Uint8Array | string;
191
+ readonly appIdHash: Uint8Array | string;
192
+ readonly attestationDigest: Uint8Array | string;
193
+ readonly exitDelaySecs: bigint | number;
194
+ }): StellarSdk.xdr.Operation;
195
+ /** Build permissionless `UserVault.settle_hw(...)` Soroban operation. */
196
+ export declare function buildSettleHwOp(params: {
197
+ readonly vaultId: string | WireAddress | Uint8Array;
198
+ readonly pocketId: number;
199
+ readonly epoch: number;
200
+ readonly seq: number;
201
+ readonly to: WireAddress | string;
202
+ readonly amount: bigint;
203
+ readonly maxTip: bigint;
204
+ readonly actualTip: bigint;
205
+ readonly gateway: WireAddress | string;
206
+ readonly expiryTs: bigint | number;
207
+ readonly expiryLedger: number;
208
+ readonly orderId: bigint | number;
209
+ readonly cumulativeSpent: bigint;
210
+ readonly hwProof: HwProof;
211
+ }): StellarSdk.xdr.Operation;
212
+ /** Build `UserVault.void_hw_seqs(pocket_id, void_proofs)` Soroban operation. */
213
+ export declare function buildVoidHwSeqsOp(params: {
214
+ readonly vaultId: string | WireAddress | Uint8Array;
215
+ readonly pocketId: number;
216
+ readonly voidProofs: readonly {
217
+ readonly seq: number;
218
+ readonly proof: HwProof;
219
+ }[];
220
+ }): StellarSdk.xdr.Operation;
221
+ /** Build `UserVault.close_hw_instant(pocket_id, to_alt, void_proofs)` Soroban operation. */
222
+ export declare function buildCloseHwInstantOp(params: {
223
+ readonly vaultId: string | WireAddress | Uint8Array;
224
+ readonly pocketId: number;
225
+ readonly toAlt: WireAddress | string;
226
+ readonly voidProofs: readonly {
227
+ readonly seq: number;
228
+ readonly proof: HwProof;
229
+ }[];
230
+ }): StellarSdk.xdr.Operation;
231
+ /** Build `UserVault.request_hw_exit(pocket_id)` Soroban operation. */
232
+ export declare function buildRequestHwExitOp(params: {
233
+ readonly vaultId: string | WireAddress | Uint8Array;
234
+ readonly pocketId: number;
235
+ }): StellarSdk.xdr.Operation;
236
+ /** Build `UserVault.finalize_hw_exit(pocket_id, to_alt)` Soroban operation. */
237
+ export declare function buildFinalizeHwExitOp(params: {
238
+ readonly vaultId: string | WireAddress | Uint8Array;
239
+ readonly pocketId: number;
240
+ readonly toAlt: WireAddress | string;
241
+ }): StellarSdk.xdr.Operation;
242
+ export interface OnChainHwPocketState {
243
+ readonly token: string;
244
+ readonly balance: bigint;
245
+ readonly epochTotalDeposited: bigint;
246
+ readonly hwKind: HwKind;
247
+ readonly maxSeq: number;
248
+ readonly hwAnchor: Uint8Array;
249
+ readonly appIdHash: Uint8Array;
250
+ readonly attestationDigest: Uint8Array;
251
+ readonly exitDelaySecs: bigint;
252
+ readonly pendingExitTs: bigint;
253
+ readonly epoch: number;
254
+ }
255
+ /** Decode `Option<HwPocketState>` returned by `UserVault.hw_pocket_of(pocket_id)` or `getLedgerEntries`. */
256
+ export declare function decodeHwPocketStateScVal(scVal: StellarSdk.xdr.ScVal): OnChainHwPocketState | null;
package/dist/contracts.js CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import * as StellarSdk from "@stellar/stellar-sdk";
8
8
  import { assertBigInt, assertBytesLength, assertSortedUniqueWitnesses, assertU16, assertU32, MAX_U64, MAX_WITNESSES, } from "./digest.js";
9
+ import { HW_KIND_ANDROID_KEYMINT_MERKLE, HW_KIND_IOS_APP_ATTEST, MAX_HW_MERKLE_DEPTH, MAX_HW_SEQ, MAX_IOS_AUTH_DATA_LEN, MIN_IOS_AUTH_DATA_LEN, } from "./hw.js";
9
10
  import { MIN_EXIT_DELAY_SECS, MAX_EXIT_DELAY_SECS } from "./wallet.js";
10
11
  import { decodeSmeshc1 } from "./wire.js";
11
12
  import { hexToBytes } from "./witnessClient.js";
@@ -433,3 +434,232 @@ export function decodePocketStateScVal(scVal) {
433
434
  epoch,
434
435
  };
435
436
  }
437
+ // ---------------------------------------------------------------------------
438
+ // UserVault v2 Hardware Roaming Pocket ABI Builders & Decoders
439
+ // ---------------------------------------------------------------------------
440
+ /** Encodes a v2 [`HwProof`] into its exact Soroban `ScVal` enum representation (`scvVec`). */
441
+ export function encodeHwProofScVal(proof) {
442
+ if (proof.kind === "ios_app_attest") {
443
+ if (proof.authData.length < MIN_IOS_AUTH_DATA_LEN ||
444
+ proof.authData.length > MAX_IOS_AUTH_DATA_LEN) {
445
+ throw new Error(`Invalid iOS authData length: ${proof.authData.length}`);
446
+ }
447
+ assertBytesLength(proof.sig64, 64, "sig64");
448
+ return StellarSdk.xdr.ScVal.scvVec([
449
+ StellarSdk.xdr.ScVal.scvSymbol("IosAppAttest"),
450
+ StellarSdk.xdr.ScVal.scvBytes(new Uint8Array(proof.authData)),
451
+ StellarSdk.xdr.ScVal.scvBytes(new Uint8Array(proof.sig64)),
452
+ ]);
453
+ }
454
+ assertBytesLength(proof.leafPubkey65, 65, "leafPubkey65");
455
+ if (proof.leafPubkey65[0] !== 0x04) {
456
+ throw new Error("leafPubkey65 must start with 0x04");
457
+ }
458
+ if (proof.merkleProof.length > MAX_HW_MERKLE_DEPTH) {
459
+ throw new Error(`merkleProof length exceeds ${MAX_HW_MERKLE_DEPTH}`);
460
+ }
461
+ assertBytesLength(proof.sig64, 64, "sig64");
462
+ return StellarSdk.xdr.ScVal.scvVec([
463
+ StellarSdk.xdr.ScVal.scvSymbol("AndroidKeyMintMerkle"),
464
+ StellarSdk.xdr.ScVal.scvBytes(new Uint8Array(proof.leafPubkey65)),
465
+ StellarSdk.xdr.ScVal.scvVec(proof.merkleProof.map((h, i) => {
466
+ assertBytesLength(h, 32, `merkleProof[${i}]`);
467
+ return StellarSdk.xdr.ScVal.scvBytes(new Uint8Array(h));
468
+ })),
469
+ StellarSdk.xdr.ScVal.scvBytes(new Uint8Array(proof.sig64)),
470
+ ]);
471
+ }
472
+ /** Build `UserVault.deposit_hw(...)` Soroban operation (v2 Hardware Roaming Pocket). */
473
+ export function buildDepositHwOp(params) {
474
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
475
+ const tokenStrKey = normalizeContractStrKey(params.token, "token");
476
+ assertU16(params.pocketId, "pocketId");
477
+ assertBigInt(params.amount, "amount");
478
+ if (params.amount < 1n || params.amount > MAX_U64) {
479
+ throw new RangeError(`amount out of range [1, ${MAX_U64}]: ${params.amount}`);
480
+ }
481
+ if (!Number.isInteger(params.maxSeq) || params.maxSeq < 1 || params.maxSeq > MAX_HW_SEQ) {
482
+ throw new RangeError(`maxSeq must be in 1..=${MAX_HW_SEQ}, got ${params.maxSeq}`);
483
+ }
484
+ const exitDelay = normalizeU64BigInt(params.exitDelaySecs, "exitDelaySecs");
485
+ if (exitDelay < MIN_EXIT_DELAY_SECS || exitDelay > MAX_EXIT_DELAY_SECS) {
486
+ throw new RangeError(`exitDelaySecs out of [${MIN_EXIT_DELAY_SECS}, ${MAX_EXIT_DELAY_SECS}]`);
487
+ }
488
+ const anchorBytes = typeof params.hwAnchor === "string"
489
+ ? hexToBytes(params.hwAnchor)
490
+ : new Uint8Array(params.hwAnchor);
491
+ if (params.hwKind === HW_KIND_IOS_APP_ATTEST) {
492
+ assertBytesLength(anchorBytes, 65, "hwAnchor");
493
+ if (anchorBytes[0] !== 0x04)
494
+ throw new Error("iOS hwAnchor must start with 0x04");
495
+ }
496
+ else if (params.hwKind === HW_KIND_ANDROID_KEYMINT_MERKLE) {
497
+ assertBytesLength(anchorBytes, 32, "hwAnchor");
498
+ }
499
+ else {
500
+ throw new Error(`Invalid hwKind: ${String(params.hwKind)}`);
501
+ }
502
+ const appIdBytes = normalizeFixedBytes(params.appIdHash, 32, "appIdHash");
503
+ const attBytes = normalizeFixedBytes(params.attestationDigest, 32, "attestationDigest");
504
+ return buildContractCallOp(vaultStrKey, "deposit_hw", [
505
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
506
+ StellarSdk.Address.fromString(tokenStrKey).toScVal(),
507
+ StellarSdk.nativeToScVal(params.amount, { type: "i128" }),
508
+ StellarSdk.xdr.ScVal.scvU32(params.hwKind),
509
+ StellarSdk.xdr.ScVal.scvU32(params.maxSeq),
510
+ StellarSdk.xdr.ScVal.scvBytes(anchorBytes),
511
+ StellarSdk.xdr.ScVal.scvBytes(appIdBytes),
512
+ StellarSdk.xdr.ScVal.scvBytes(attBytes),
513
+ StellarSdk.nativeToScVal(exitDelay, { type: "u64" }),
514
+ ]);
515
+ }
516
+ /** Build permissionless `UserVault.settle_hw(...)` Soroban operation. */
517
+ export function buildSettleHwOp(params) {
518
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
519
+ assertU16(params.pocketId, "pocketId");
520
+ assertU32(params.epoch, "epoch");
521
+ assertU32(params.seq, "seq");
522
+ const toStrKey = normalizeNonMuxedAddressStrKey(params.to, "to");
523
+ const gatewayStrKey = normalizeNonMuxedAddressStrKey(params.gateway, "gateway");
524
+ assertBigInt(params.amount, "amount");
525
+ if (params.amount < 1n || params.amount > MAX_U64) {
526
+ throw new RangeError(`amount out of range [1, ${MAX_U64}]: ${params.amount}`);
527
+ }
528
+ assertBigInt(params.maxTip, "maxTip");
529
+ if (params.maxTip < 0n || params.maxTip > MAX_U64) {
530
+ throw new RangeError(`maxTip out of range [0, ${MAX_U64}]: ${params.maxTip}`);
531
+ }
532
+ assertBigInt(params.actualTip, "actualTip");
533
+ if (params.actualTip < 0n || params.actualTip > params.maxTip) {
534
+ throw new RangeError(`actualTip out of range [0, ${params.maxTip}]: ${params.actualTip}`);
535
+ }
536
+ assertBigInt(params.cumulativeSpent, "cumulativeSpent");
537
+ if (params.cumulativeSpent < params.amount + params.maxTip || params.cumulativeSpent > MAX_U64) {
538
+ throw new RangeError(`cumulativeSpent out of range: ${params.cumulativeSpent}`);
539
+ }
540
+ const expiryTs = normalizeU64BigInt(params.expiryTs, "expiryTs");
541
+ assertU32(params.expiryLedger, "expiryLedger");
542
+ const orderId = normalizeU64BigInt(params.orderId, "orderId");
543
+ return buildContractCallOp(vaultStrKey, "settle_hw", [
544
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
545
+ StellarSdk.xdr.ScVal.scvU32(params.epoch),
546
+ StellarSdk.xdr.ScVal.scvU32(params.seq),
547
+ StellarSdk.Address.fromString(toStrKey).toScVal(),
548
+ StellarSdk.nativeToScVal(params.amount, { type: "i128" }),
549
+ StellarSdk.nativeToScVal(params.maxTip, { type: "i128" }),
550
+ StellarSdk.nativeToScVal(params.actualTip, { type: "i128" }),
551
+ StellarSdk.Address.fromString(gatewayStrKey).toScVal(),
552
+ StellarSdk.nativeToScVal(expiryTs, { type: "u64" }),
553
+ StellarSdk.xdr.ScVal.scvU32(params.expiryLedger),
554
+ StellarSdk.nativeToScVal(orderId, { type: "u64" }),
555
+ StellarSdk.nativeToScVal(params.cumulativeSpent, { type: "i128" }),
556
+ encodeHwProofScVal(params.hwProof),
557
+ ]);
558
+ }
559
+ /** Build `UserVault.void_hw_seqs(pocket_id, void_proofs)` Soroban operation. */
560
+ export function buildVoidHwSeqsOp(params) {
561
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
562
+ assertU16(params.pocketId, "pocketId");
563
+ const vec = StellarSdk.xdr.ScVal.scvVec(params.voidProofs.map((entry) => {
564
+ assertU32(entry.seq, "seq");
565
+ return StellarSdk.xdr.ScVal.scvVec([
566
+ StellarSdk.xdr.ScVal.scvU32(entry.seq),
567
+ encodeHwProofScVal(entry.proof),
568
+ ]);
569
+ }));
570
+ return buildContractCallOp(vaultStrKey, "void_hw_seqs", [
571
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
572
+ vec,
573
+ ]);
574
+ }
575
+ /** Build `UserVault.close_hw_instant(pocket_id, to_alt, void_proofs)` Soroban operation. */
576
+ export function buildCloseHwInstantOp(params) {
577
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
578
+ assertU16(params.pocketId, "pocketId");
579
+ const toAltStrKey = normalizeNonMuxedAddressStrKey(params.toAlt, "toAlt");
580
+ const vec = StellarSdk.xdr.ScVal.scvVec(params.voidProofs.map((entry) => {
581
+ assertU32(entry.seq, "seq");
582
+ return StellarSdk.xdr.ScVal.scvVec([
583
+ StellarSdk.xdr.ScVal.scvU32(entry.seq),
584
+ encodeHwProofScVal(entry.proof),
585
+ ]);
586
+ }));
587
+ return buildContractCallOp(vaultStrKey, "close_hw_instant", [
588
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
589
+ StellarSdk.Address.fromString(toAltStrKey).toScVal(),
590
+ vec,
591
+ ]);
592
+ }
593
+ /** Build `UserVault.request_hw_exit(pocket_id)` Soroban operation. */
594
+ export function buildRequestHwExitOp(params) {
595
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
596
+ assertU16(params.pocketId, "pocketId");
597
+ return buildContractCallOp(vaultStrKey, "request_hw_exit", [
598
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
599
+ ]);
600
+ }
601
+ /** Build `UserVault.finalize_hw_exit(pocket_id, to_alt)` Soroban operation. */
602
+ export function buildFinalizeHwExitOp(params) {
603
+ const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
604
+ assertU16(params.pocketId, "pocketId");
605
+ const toAltStrKey = normalizeNonMuxedAddressStrKey(params.toAlt, "toAlt");
606
+ return buildContractCallOp(vaultStrKey, "finalize_hw_exit", [
607
+ StellarSdk.xdr.ScVal.scvU32(params.pocketId),
608
+ StellarSdk.Address.fromString(toAltStrKey).toScVal(),
609
+ ]);
610
+ }
611
+ /** Decode `Option<HwPocketState>` returned by `UserVault.hw_pocket_of(pocket_id)` or `getLedgerEntries`. */
612
+ export function decodeHwPocketStateScVal(scVal) {
613
+ if (scVal.type === "scvVoid")
614
+ return null;
615
+ if (scVal.type !== "scvMap" || !scVal.map) {
616
+ throw new Error(`Expected scvMap or scvVoid for HwPocketState, got ${scVal.type}`);
617
+ }
618
+ const fields = new Map();
619
+ for (const entry of scVal.map) {
620
+ if (entry.key.type === "scvSymbol") {
621
+ fields.set(String(StellarSdk.scValToNative(entry.key)), entry.val);
622
+ }
623
+ }
624
+ const getField = (name) => {
625
+ const v = fields.get(name);
626
+ if (!v)
627
+ throw new Error(`HwPocketState ScVal missing required field "${name}"`);
628
+ return v;
629
+ };
630
+ const tokenVal = getField("token");
631
+ if (tokenVal.type !== "scvAddress") {
632
+ throw new Error(`HwPocketState.token expected scvAddress, got ${tokenVal.type}`);
633
+ }
634
+ const token = StellarSdk.Address.fromScVal(tokenVal).toString();
635
+ normalizeContractHash(token);
636
+ const hwKindRaw = Number(StellarSdk.scValToBigInt(getField("hw_kind")));
637
+ if (hwKindRaw !== HW_KIND_IOS_APP_ATTEST && hwKindRaw !== HW_KIND_ANDROID_KEYMINT_MERKLE) {
638
+ throw new Error(`HwPocketState.hw_kind invalid: ${hwKindRaw}`);
639
+ }
640
+ const readBytesField = (name) => {
641
+ const v = getField(name);
642
+ if (v.type !== "scvBytes") {
643
+ throw new Error(`HwPocketState.${name} expected scvBytes, got ${v.type}`);
644
+ }
645
+ return new Uint8Array(StellarSdk.scValToNative(v));
646
+ };
647
+ const hwAnchor = readBytesField("hw_anchor");
648
+ const appIdHash = readBytesField("app_id_hash");
649
+ assertBytesLength(appIdHash, 32, "HwPocketState.app_id_hash");
650
+ const attestationDigest = readBytesField("attestation_digest");
651
+ assertBytesLength(attestationDigest, 32, "HwPocketState.attestation_digest");
652
+ return {
653
+ token,
654
+ balance: StellarSdk.scValToBigInt(getField("balance")),
655
+ epochTotalDeposited: StellarSdk.scValToBigInt(getField("epoch_total_deposited")),
656
+ hwKind: hwKindRaw,
657
+ maxSeq: Number(StellarSdk.scValToBigInt(getField("max_seq"))),
658
+ hwAnchor,
659
+ appIdHash,
660
+ attestationDigest,
661
+ exitDelaySecs: StellarSdk.scValToBigInt(getField("exit_delay_secs")),
662
+ pendingExitTs: StellarSdk.scValToBigInt(getField("pending_exit_ts")),
663
+ epoch: Number(StellarSdk.scValToBigInt(getField("epoch"))),
664
+ };
665
+ }
package/dist/hw.d.ts ADDED
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Outpost v2 Hardware-Backed Roaming Pockets (`iOS AppAttest` + `Android KeyMint/StrongBox`).
3
+ *
4
+ * Pure browser / React Native / Cloudflare Worker / Node compatible (`Uint8Array`, zero Node
5
+ * `Buffer` dependencies), byte-for-byte identical to `contracts/user-vault/src/lib.rs` and
6
+ * `crates/outpost-wire/src/hw.rs`.
7
+ */
8
+ import { NetworkHint, type WireAddress } from "./xdr.js";
9
+ export declare const HRP_SMESHH = "SMESHH";
10
+ export declare const SMESHH1_WIRE_VERSION = 2;
11
+ export declare const MAX_SMESHH1_BYTES = 28000;
12
+ export declare const HW_KIND_IOS_APP_ATTEST: 1;
13
+ export declare const HW_KIND_ANDROID_KEYMINT_MERKLE: 2;
14
+ export type HwKind = typeof HW_KIND_IOS_APP_ATTEST | typeof HW_KIND_ANDROID_KEYMINT_MERKLE;
15
+ export declare const MAX_HW_SEQ = 64;
16
+ export declare const MAX_HW_MERKLE_DEPTH = 6;
17
+ export declare const MIN_IOS_AUTH_DATA_LEN = 37;
18
+ export declare const MAX_IOS_AUTH_DATA_LEN = 256;
19
+ export declare const HW_MIN_EXIT_DELAY_SECS = 259200n;
20
+ export declare const HW_MAX_EXIT_DELAY_SECS = 2592000n;
21
+ export declare const DOMAIN_TAG_HW_INTENT: Uint8Array<ArrayBuffer>;
22
+ export declare const DOMAIN_TAG_HW_VOID: Uint8Array<ArrayBuffer>;
23
+ export declare const DOMAIN_TAG_HW_LEAF: Uint8Array<ArrayBuffer>;
24
+ export declare const DOMAIN_TAG_HW_NODE: Uint8Array<ArrayBuffer>;
25
+ export declare const DOMAIN_TAG_HW_EMPTY: Uint8Array<ArrayBuffer>;
26
+ export declare const DOMAIN_TAG_HW_GENESIS: Uint8Array<ArrayBuffer>;
27
+ export declare const DOMAIN_TAG_HW_CHAL: Uint8Array<ArrayBuffer>;
28
+ /** Exact binary tree depth for `maxSeq` (`1..=64`), matching `UserVault::merkle_depth_for`. */
29
+ export declare function hwMerkleDepthFor(maxSeq: number): number;
30
+ /** Canonical Android KeyMint single-use key leaf digest for `seq` (`1..=maxSeq`). */
31
+ export declare function hwMerkleLeaf(seq: number, pubkey65: Uint8Array): Uint8Array;
32
+ /** Domain-separated internal Merkle node digest. */
33
+ export declare function hwMerkleNode(left: Uint8Array, right: Uint8Array): Uint8Array;
34
+ /** Canonical padding leaf for non-power-of-two Android KeyMint key batches. */
35
+ export declare function hwMerkleEmptyLeaf(): Uint8Array;
36
+ export interface HwMerkleTree {
37
+ readonly root: Uint8Array;
38
+ readonly depth: number;
39
+ /** Per-leaf sibling proof arrays indexed by `seq - 1` (`0..pubkeys.length - 1`). */
40
+ readonly proofs: readonly (readonly Uint8Array[])[];
41
+ }
42
+ /** Builds the canonical Android KeyMint Merkle root and per-leaf inclusion proofs. */
43
+ export declare function hwMerkleBuildTree(pubkeys65: readonly Uint8Array[]): HwMerkleTree;
44
+ /** Verifies an Android KeyMint Merkle inclusion proof for `(seq, leafPubkey65)` against `expectedRoot`. */
45
+ export declare function hwMerkleVerifyProof(expectedRoot: Uint8Array, maxSeq: number, seq: number, leafPubkey65: Uint8Array, merkleProof: readonly Uint8Array[]): boolean;
46
+ /**
47
+ * Converts an ASN.1 DER ECDSA P-256 signature (as emitted by Apple `DCAppAttestService` and
48
+ * Android `Signature("SHA256withECDSA")`) into canonical 64-byte low-S `(r || s)` required by
49
+ * Stellar Soroban `CAP-0051` (`secp256r1_verify`).
50
+ */
51
+ export declare function normalizeP256DerToLowS64(der: Uint8Array): Uint8Array;
52
+ /** Checks that `pubkey65` is a valid 65-byte uncompressed SEC1 point on `secp256r1` (`0x04 || x || y`). */
53
+ export declare function isValidP256UncompressedPubkey(pubkey65: Uint8Array): boolean;
54
+ /**
55
+ * Strictly verifies a 64-byte **low-S** ECDSA P-256 signature over a 32-byte prehashed digest,
56
+ * mirroring Stellar Soroban `CAP-0051` (`secp256r1_verify`, rejecting high-S malleability).
57
+ */
58
+ export declare function verifyP256PrehashLowS(pubkey65: Uint8Array, digest32: Uint8Array, sig64: Uint8Array): boolean;
59
+ export interface HwIntentDigestParams {
60
+ readonly networkId: Uint8Array;
61
+ readonly vaultId: Uint8Array | string;
62
+ readonly pocketId: number;
63
+ readonly epoch: number;
64
+ readonly seq: number;
65
+ readonly tokenId: Uint8Array | string;
66
+ readonly to: WireAddress | string;
67
+ readonly amount: bigint;
68
+ readonly maxTip: bigint;
69
+ readonly cumulativeSpent: bigint;
70
+ readonly expiryTs: bigint;
71
+ readonly expiryLedger: number;
72
+ readonly orderId: bigint;
73
+ }
74
+ /** Computes `"SMW2_HWINTENT"` 32-byte digest matching `UserVault::compute_hw_intent_digest`. */
75
+ export declare function computeHwIntentDigest(params: HwIntentDigestParams): Uint8Array;
76
+ /** Computes `"SMW2_HWVOID"` 32-byte digest matching `UserVault::compute_hw_void_digest`. */
77
+ export declare function computeHwVoidDigest(params: {
78
+ readonly networkId: Uint8Array;
79
+ readonly vaultId: Uint8Array | string;
80
+ readonly pocketId: number;
81
+ readonly epoch: number;
82
+ readonly seq: number;
83
+ }): Uint8Array;
84
+ /**
85
+ * Computes canonical `"SMW2_HWCHAL"` 32-byte attestation challenge bound to
86
+ * `(networkId, vaultId, pocketId, epoch, seq)`.
87
+ * - iOS `DCAppAttestService.attestKey(keyId, clientDataHash)`: pass `seq = 0`.
88
+ * - Android `KeyGenParameterSpec.setAttestationChallenge(challenge)`: pass `seq = 1..=maxSeq`.
89
+ */
90
+ export declare function computeHwAttestationChallenge(params: {
91
+ readonly networkId: Uint8Array;
92
+ readonly vaultId: Uint8Array | string;
93
+ readonly pocketId: number;
94
+ readonly epoch: number;
95
+ readonly seq: number;
96
+ }): Uint8Array;
97
+ export type HwProof = {
98
+ readonly kind: "ios_app_attest";
99
+ /** Raw WebAuthn / Apple AppAttest `authenticatorData` (`37..=256` bytes). */
100
+ readonly authData: Uint8Array;
101
+ /** Canonical 64-byte low-S `(r || s)` ECDSA P-256 signature. */
102
+ readonly sig64: Uint8Array;
103
+ } | {
104
+ readonly kind: "android_keymint_merkle";
105
+ /** 65-byte uncompressed SEC1 P-256 leaf pubkey (`0x04 || x || y`). */
106
+ readonly leafPubkey65: Uint8Array;
107
+ /** Sibling hashes from leaf (`level 0`) to root. */
108
+ readonly merkleProof: readonly Uint8Array[];
109
+ /** Canonical 64-byte low-S `(r || s)` ECDSA P-256 signature. */
110
+ readonly sig64: Uint8Array;
111
+ };
112
+ export type HwProofDto = {
113
+ readonly kind: "ios_app_attest";
114
+ readonly auth_data: string;
115
+ readonly sig_64: string;
116
+ } | {
117
+ readonly kind: "android_keymint_merkle";
118
+ readonly leaf_pubkey_65: string;
119
+ readonly merkle_proof: readonly string[];
120
+ readonly sig_64: string;
121
+ };
122
+ export declare function hwProofToDto(proof: HwProof): HwProofDto;
123
+ export declare function hwProofFromDto(dto: HwProofDto): HwProof;
124
+ /** Verifies an Apple Secure Enclave `DCAppAttestService` assertion proof. */
125
+ export declare function verifyIosAppAttestProof(params: {
126
+ readonly pubkey65: Uint8Array;
127
+ readonly expectedAppIdHash: Uint8Array;
128
+ readonly expectedSeq: number;
129
+ readonly clientDataHash: Uint8Array;
130
+ readonly authData: Uint8Array;
131
+ readonly sig64: Uint8Array;
132
+ }): boolean;
133
+ /** Verifies an Android KeyMint / StrongBox single-use key proof against `expectedMerkleRoot`. */
134
+ export declare function verifyAndroidKeyMintProof(params: {
135
+ readonly expectedMerkleRoot: Uint8Array;
136
+ readonly maxSeq: number;
137
+ readonly expectedSeq: number;
138
+ readonly clientDataHash: Uint8Array;
139
+ readonly leafPubkey65: Uint8Array;
140
+ readonly merkleProof: readonly Uint8Array[];
141
+ readonly sig64: Uint8Array;
142
+ }): boolean;
143
+ export interface HwGenesisCert {
144
+ readonly factoryVer: number;
145
+ readonly owner: WireAddress;
146
+ readonly vaultId: Uint8Array;
147
+ readonly pocketId: number;
148
+ readonly epoch: number;
149
+ readonly tokenId: Uint8Array;
150
+ readonly epochTotalDeposited: bigint;
151
+ readonly hwKind: HwKind;
152
+ readonly maxSeq: number;
153
+ readonly hwAnchor: Uint8Array;
154
+ readonly appIdHash: Uint8Array;
155
+ readonly attestationDigest: Uint8Array;
156
+ readonly exitDelaySecs: bigint;
157
+ readonly syncedAtTs: bigint;
158
+ readonly syncedLedgerSeq: number;
159
+ readonly verifierSig: Uint8Array;
160
+ }
161
+ export interface HwGenesisCertDto {
162
+ readonly factory_ver: number;
163
+ readonly owner: string;
164
+ readonly vault_id: string;
165
+ readonly pocket_id: number;
166
+ readonly epoch: number;
167
+ readonly token_id: string;
168
+ readonly epoch_total_deposited: string;
169
+ readonly hw_kind: HwKind;
170
+ readonly max_seq: number;
171
+ readonly hw_anchor: string;
172
+ readonly app_id_hash: string;
173
+ readonly attestation_digest: string;
174
+ readonly exit_delay_secs: string;
175
+ readonly synced_at_ts: string;
176
+ readonly synced_ledger_seq: number;
177
+ readonly verifier_sig: string;
178
+ }
179
+ export declare function hwGenesisCertToDto(cert: HwGenesisCert): HwGenesisCertDto;
180
+ export declare function hwGenesisCertFromDto(dto: HwGenesisCertDto): HwGenesisCert;
181
+ /** Computes canonical `"SMW2_HWGENESIS"` 32-byte digest matching `crates/outpost-wire/src/hw.rs`. */
182
+ export declare function computeHwGenesisDigest(networkId: Uint8Array, cert: Omit<HwGenesisCert, "verifierSig">): Uint8Array;
183
+ export interface HwPaymentEntry {
184
+ readonly seq: number;
185
+ readonly to: WireAddress;
186
+ readonly amount: bigint;
187
+ readonly maxTip: bigint;
188
+ readonly cumulativeSpent: bigint;
189
+ readonly expiryTs: bigint;
190
+ readonly expiryLedger: number;
191
+ readonly orderId: bigint;
192
+ readonly hwProof: HwProof;
193
+ }
194
+ export interface HwPaymentEntryDto {
195
+ readonly seq: number;
196
+ readonly to: string;
197
+ readonly amount: string;
198
+ readonly max_tip: string;
199
+ readonly cumulative_spent: string;
200
+ readonly expiry_ts: string;
201
+ readonly expiry_ledger: number;
202
+ readonly order_id: string;
203
+ readonly hw_proof: HwProofDto;
204
+ }
205
+ export declare function hwPaymentEntryToDto(entry: HwPaymentEntry): HwPaymentEntryDto;
206
+ export declare function hwPaymentEntryFromDto(dto: HwPaymentEntryDto): HwPaymentEntry;
207
+ /**
208
+ * Verifies an unbroken contiguous offline Hardware Roaming Pocket spend chain `[1..=k]` with
209
+ * **zero internet** and **zero fixed nearby Stations**. Mirrors `crates/outpost-wire::verify_hw_spend_chain`.
210
+ *
211
+ * Returns the verified `cumulativeSpent` (`bigint`) on success, or throws on any violation.
212
+ */
213
+ export declare function verifyHwSpendChain(params: {
214
+ readonly networkId: Uint8Array;
215
+ readonly trustedVerifierPubkey: Uint8Array;
216
+ readonly cert: HwGenesisCert;
217
+ readonly entries: readonly HwPaymentEntry[];
218
+ readonly localNowTs: bigint;
219
+ readonly exitMarginSecs: bigint;
220
+ }): bigint;
221
+ /**
222
+ * Complete offline Hardware Roaming Pocket payment handover packet (`SMESHH1`), carrying
223
+ * the verified `HwGenesisCert` AND the unbroken contiguous spend chain `[seq 1 -> 2 -> ... -> k]`.
224
+ *
225
+ * Used identically across:
226
+ * - Static QR (`SMESHH1<BASE32(raw || crc32c)>`)
227
+ * - Animated QR (`UR:SMESH/<idx>-<total>/...` over `encodeSmeshh1Bytes`)
228
+ * - Bluetooth LE GATT (`POST /v2/hw-pay` over `OUTPOST_BLE_V1` with raw `encodeSmeshh1Bytes`)
229
+ * - Direct Gateway Settlement (`POST /v2/settle/hw` `{ "payload": "SMESHH1..." }`)
230
+ */
231
+ export interface Smeshh1Packet {
232
+ readonly networkHint: NetworkHint;
233
+ readonly cert: HwGenesisCert;
234
+ readonly entries: readonly HwPaymentEntry[];
235
+ }
236
+ /** Encodes a `Smeshh1Packet` into canonical raw binary bytes (<= `MAX_SMESHH1_BYTES`). */
237
+ export declare function encodeSmeshh1Bytes(packet: Smeshh1Packet): Uint8Array;
238
+ /** Decodes and structurally validates a `Smeshh1Packet` from canonical raw binary bytes. */
239
+ export declare function decodeSmeshh1Bytes(raw: Uint8Array): Smeshh1Packet;
240
+ /** Encodes `SMESHH1<UPPERCASE_UNPADDED_RFC4648_BASE32(raw_bytes || crc32c_be_4B)>`. */
241
+ export declare function encodeSmeshh1(packet: Smeshh1Packet): string;
242
+ /** Decodes `SMESHH1<BASE32(raw_bytes || crc32c_be_4B)>` (case-insensitive). */
243
+ export declare function decodeSmeshh1(encoded: string): Smeshh1Packet;