@outpost-protocol/core 0.1.1 → 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.
- package/README.md +3 -1
- package/dist/cert0.d.ts +12 -0
- package/dist/cert0.js +125 -0
- package/dist/contracts.d.ts +256 -0
- package/dist/contracts.js +665 -0
- package/dist/coordinators.d.ts +131 -0
- package/dist/coordinators.js +457 -0
- package/dist/hw.d.ts +243 -0
- package/dist/hw.js +858 -0
- package/dist/hwClient.d.ts +270 -0
- package/dist/hwClient.js +794 -0
- package/dist/hwTransport.d.ts +173 -0
- package/dist/hwTransport.js +431 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/wallet.d.ts +43 -4
- package/dist/wallet.js +136 -5
- package/dist/walletStorage.d.ts +128 -0
- package/dist/walletStorage.js +399 -0
- package/dist/wire.d.ts +10 -0
- package/dist/wire.js +31 -0
- package/dist/witnessClient.d.ts +20 -0
- package/package.json +1 -1
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;
|