@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
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-Level Outpost v2 Hardware Roaming Wallet & Gateway SDK (`@outpost-protocol/core`).
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - `HwGatewayClient`: Bounded HTTP client for `GET /health`, `POST /v2/hw-attest` (`preview` & `cert`),
|
|
6
|
+
* and `POST /v2/settle/hw` (accepting `SMESHH1` strings or `{ cert, entry }`).
|
|
7
|
+
* - `HwPocketSession`: Stateful, serializable offline pocket manager for mobile apps (iOS Secure Enclave
|
|
8
|
+
* & Android KeyMint/StrongBox) with non-zero `(recipient, orderId)` retry deduplication, safe `SREQ1`
|
|
9
|
+
* tip capping, pre-mutation P-256 verification, and 1-call QR/UR:SMESH/BLE encoding.
|
|
10
|
+
*/
|
|
11
|
+
import * as StellarSdk from "@stellar/stellar-sdk";
|
|
12
|
+
import { type HwGenesisCert, type HwGenesisCertDto, type HwKind, type HwPaymentEntry, type Smeshh1Packet } from "./hw.js";
|
|
13
|
+
import { type Smeshh1QrPayload } from "./hwTransport.js";
|
|
14
|
+
import type { Sreq1Packet } from "./wire.js";
|
|
15
|
+
import { type FetchLike } from "./witnessClient.js";
|
|
16
|
+
import { NetworkHint, TokenResolver, type WireAddress } from "./xdr.js";
|
|
17
|
+
export declare class HwGatewayError extends Error {
|
|
18
|
+
readonly status: number;
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly details?: Record<string, unknown>;
|
|
21
|
+
constructor(status: number, code: string, message: string, details?: Record<string, unknown>);
|
|
22
|
+
}
|
|
23
|
+
export interface HwGatewayClientOptions {
|
|
24
|
+
/** Base gateway URL, e.g. `"https://gateway.outpost.cash"`. */
|
|
25
|
+
readonly baseUrl: string;
|
|
26
|
+
readonly fetch?: FetchLike;
|
|
27
|
+
readonly timeoutMs?: number;
|
|
28
|
+
readonly posApiKey?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface HwGatewayHealthInfo {
|
|
31
|
+
readonly status: string;
|
|
32
|
+
readonly version: string;
|
|
33
|
+
readonly network: string;
|
|
34
|
+
readonly networkHint: NetworkHint;
|
|
35
|
+
readonly gatewayAddress?: string;
|
|
36
|
+
readonly factoryIds?: Readonly<Record<string, string>>;
|
|
37
|
+
readonly hwRoaming?: {
|
|
38
|
+
readonly enabled: boolean;
|
|
39
|
+
readonly attestationCertSigningEnabled: boolean;
|
|
40
|
+
readonly factoryVer: number;
|
|
41
|
+
readonly factoryId?: string;
|
|
42
|
+
readonly userVaultWasmHash?: string;
|
|
43
|
+
readonly verifierPubkey?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface HwAttestPreviewResult {
|
|
47
|
+
readonly factoryVer: number;
|
|
48
|
+
readonly owner: string;
|
|
49
|
+
readonly vaultId: string;
|
|
50
|
+
readonly pocketId: number;
|
|
51
|
+
readonly epoch: number;
|
|
52
|
+
readonly hwKind: HwKind;
|
|
53
|
+
readonly maxSeq: number;
|
|
54
|
+
readonly hwAnchor: Uint8Array;
|
|
55
|
+
readonly appIdHash: Uint8Array;
|
|
56
|
+
readonly attestationDigest: Uint8Array;
|
|
57
|
+
readonly merkleProofs?: readonly (readonly Uint8Array[])[];
|
|
58
|
+
readonly leafPubkeys65?: readonly Uint8Array[];
|
|
59
|
+
readonly securityLevel?: "strongbox" | "tee";
|
|
60
|
+
readonly packageName?: string;
|
|
61
|
+
readonly aaguidEnv?: "production" | "development";
|
|
62
|
+
/** Build the ready-to-sign Soroban `UserVault.deposit_hw(...)` operation for these exact verified params. */
|
|
63
|
+
buildDepositOp(params: {
|
|
64
|
+
readonly token: string;
|
|
65
|
+
readonly amount: bigint;
|
|
66
|
+
readonly exitDelaySecs?: bigint;
|
|
67
|
+
}): StellarSdk.xdr.Operation;
|
|
68
|
+
}
|
|
69
|
+
export interface HwAttestCertResult {
|
|
70
|
+
readonly cert: HwGenesisCert;
|
|
71
|
+
readonly certDto: HwGenesisCertDto;
|
|
72
|
+
readonly verifierPubkey: Uint8Array;
|
|
73
|
+
readonly verifierPubkeyHex: string;
|
|
74
|
+
readonly vaultId: string;
|
|
75
|
+
readonly tokenContractId: string;
|
|
76
|
+
readonly merkleProofs?: readonly (readonly Uint8Array[])[];
|
|
77
|
+
readonly leafPubkeys65?: readonly Uint8Array[];
|
|
78
|
+
readonly securityLevel?: "strongbox" | "tee";
|
|
79
|
+
readonly packageName?: string;
|
|
80
|
+
readonly aaguidEnv?: "production" | "development";
|
|
81
|
+
}
|
|
82
|
+
export interface HwSettleResult {
|
|
83
|
+
readonly status: "L1_FINAL" | "CREDIT_PARKED";
|
|
84
|
+
readonly txHash?: string;
|
|
85
|
+
readonly ledgerSeq?: number;
|
|
86
|
+
readonly alreadySettled?: boolean;
|
|
87
|
+
readonly vaultId?: string;
|
|
88
|
+
readonly recipient?: string;
|
|
89
|
+
readonly token?: string;
|
|
90
|
+
readonly amount?: string;
|
|
91
|
+
readonly advisoryTags?: readonly string[];
|
|
92
|
+
}
|
|
93
|
+
export declare class HwGatewayClient {
|
|
94
|
+
readonly baseUrl: string;
|
|
95
|
+
private readonly fetchFn;
|
|
96
|
+
private readonly timeoutMs;
|
|
97
|
+
private readonly posApiKey?;
|
|
98
|
+
constructor(options: HwGatewayClientOptions);
|
|
99
|
+
private requestJson;
|
|
100
|
+
getHealth(): Promise<HwGatewayHealthInfo>;
|
|
101
|
+
private parsePreview;
|
|
102
|
+
private parseCert;
|
|
103
|
+
previewIosAttestation(params: {
|
|
104
|
+
readonly owner: string;
|
|
105
|
+
readonly pocketId: number;
|
|
106
|
+
readonly epoch: number;
|
|
107
|
+
readonly maxSeq?: number;
|
|
108
|
+
readonly factoryVer?: number;
|
|
109
|
+
/** Raw CBOR bytes or base64 string from `DCAppAttestService.attestKey`. */
|
|
110
|
+
readonly attestationObject: Uint8Array | string;
|
|
111
|
+
}): Promise<HwAttestPreviewResult>;
|
|
112
|
+
certifyIosPocket(params: {
|
|
113
|
+
readonly networkHint: NetworkHint;
|
|
114
|
+
readonly owner: string;
|
|
115
|
+
readonly pocketId: number;
|
|
116
|
+
readonly epoch: number;
|
|
117
|
+
readonly factoryVer?: number;
|
|
118
|
+
readonly attestationObject: Uint8Array | string;
|
|
119
|
+
readonly expectedVerifierPubkey?: Uint8Array;
|
|
120
|
+
}): Promise<HwAttestCertResult>;
|
|
121
|
+
previewAndroidAttestation(params: {
|
|
122
|
+
readonly owner: string;
|
|
123
|
+
readonly pocketId: number;
|
|
124
|
+
readonly epoch: number;
|
|
125
|
+
readonly factoryVer?: number;
|
|
126
|
+
/** Either full per-key cert chains `[leaf, ...intermediates]` OR deduplicated `leafCerts` + `issuerChain`. */
|
|
127
|
+
readonly keyChains?: readonly (readonly (Uint8Array | string)[])[];
|
|
128
|
+
readonly leafCerts?: readonly (Uint8Array | string)[];
|
|
129
|
+
readonly issuerChain?: readonly (Uint8Array | string)[];
|
|
130
|
+
}): Promise<HwAttestPreviewResult>;
|
|
131
|
+
certifyAndroidPocket(params: {
|
|
132
|
+
readonly networkHint: NetworkHint;
|
|
133
|
+
readonly owner: string;
|
|
134
|
+
readonly pocketId: number;
|
|
135
|
+
readonly epoch: number;
|
|
136
|
+
readonly factoryVer?: number;
|
|
137
|
+
readonly keyChains?: readonly (readonly (Uint8Array | string)[])[];
|
|
138
|
+
readonly leafCerts?: readonly (Uint8Array | string)[];
|
|
139
|
+
readonly issuerChain?: readonly (Uint8Array | string)[];
|
|
140
|
+
readonly expectedVerifierPubkey?: Uint8Array;
|
|
141
|
+
}): Promise<HwAttestCertResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Settle a hardware-backed payment via `POST /v2/settle/hw`.
|
|
144
|
+
* Accepts EITHER a framed `SMESHH1...` string / `Smeshh1Packet` OR explicit `{ cert, entry }`.
|
|
145
|
+
*/
|
|
146
|
+
settleHwPayment(params: {
|
|
147
|
+
readonly payload: string | Smeshh1Packet;
|
|
148
|
+
readonly seq?: number;
|
|
149
|
+
readonly actualTip?: bigint;
|
|
150
|
+
readonly gateway?: string;
|
|
151
|
+
} | {
|
|
152
|
+
readonly cert: HwGenesisCert;
|
|
153
|
+
readonly entry: HwPaymentEntry;
|
|
154
|
+
readonly actualTip?: bigint;
|
|
155
|
+
readonly gateway?: string;
|
|
156
|
+
}): Promise<HwSettleResult>;
|
|
157
|
+
}
|
|
158
|
+
export declare const HW_SESSION_SCHEMA_VERSION: 1;
|
|
159
|
+
export interface PreparedHwPayment {
|
|
160
|
+
readonly seq: number;
|
|
161
|
+
readonly to: WireAddress;
|
|
162
|
+
readonly toStrKey: string;
|
|
163
|
+
readonly amount: bigint;
|
|
164
|
+
readonly maxTip: bigint;
|
|
165
|
+
readonly cumulativeSpent: bigint;
|
|
166
|
+
readonly expiryTs: bigint;
|
|
167
|
+
readonly expiryLedger: number;
|
|
168
|
+
readonly orderId: bigint;
|
|
169
|
+
/** Exact 32-byte `"SMW2_HWINTENT"` digest to pass to iOS `generateAssertion` or Android `SHA256withECDSA`. */
|
|
170
|
+
readonly hwIntentDigest: Uint8Array;
|
|
171
|
+
/** For Android pockets: pre-selected leaf pubkey & Merkle sibling proof for `seq`. */
|
|
172
|
+
readonly androidLeafPubkey65?: Uint8Array;
|
|
173
|
+
readonly androidMerkleProof?: readonly Uint8Array[];
|
|
174
|
+
/** Present when a non-zero `(to, orderId)` was already signed in this session (retry without burning `seq + 1`). */
|
|
175
|
+
readonly alreadySignedEntry?: HwPaymentEntry;
|
|
176
|
+
}
|
|
177
|
+
export interface CommittedHwPayment {
|
|
178
|
+
readonly entry: HwPaymentEntry;
|
|
179
|
+
readonly packet: Smeshh1Packet;
|
|
180
|
+
readonly smeshh1: string;
|
|
181
|
+
readonly qr: Smeshh1QrPayload;
|
|
182
|
+
readonly deduplicated: boolean;
|
|
183
|
+
}
|
|
184
|
+
export declare class HwPocketSession {
|
|
185
|
+
readonly networkHint: NetworkHint;
|
|
186
|
+
readonly networkId: Uint8Array;
|
|
187
|
+
readonly cert: HwGenesisCert;
|
|
188
|
+
readonly verifierPubkey: Uint8Array;
|
|
189
|
+
readonly merkleProofs?: readonly (readonly Uint8Array[])[];
|
|
190
|
+
readonly leafPubkeys65?: readonly Uint8Array[];
|
|
191
|
+
private readonly entriesList;
|
|
192
|
+
constructor(params: {
|
|
193
|
+
readonly networkHint: NetworkHint;
|
|
194
|
+
readonly cert: HwGenesisCert;
|
|
195
|
+
readonly verifierPubkey: Uint8Array | string;
|
|
196
|
+
readonly entries?: readonly HwPaymentEntry[];
|
|
197
|
+
readonly merkleProofs?: readonly (readonly Uint8Array[])[];
|
|
198
|
+
readonly leafPubkeys65?: readonly Uint8Array[];
|
|
199
|
+
});
|
|
200
|
+
/** Helper to compute the `"SMW2_HWCHAL"` 32-byte challenge before calling `DCAppAttestService` / Android KeyStore. */
|
|
201
|
+
static attestationChallenge(params: {
|
|
202
|
+
readonly networkHint: NetworkHint;
|
|
203
|
+
readonly vaultId: Uint8Array | string;
|
|
204
|
+
readonly pocketId: number;
|
|
205
|
+
readonly epoch: number;
|
|
206
|
+
readonly seq: number;
|
|
207
|
+
}): Uint8Array;
|
|
208
|
+
get vaultId(): string;
|
|
209
|
+
get tokenContractId(): string;
|
|
210
|
+
get entries(): readonly HwPaymentEntry[];
|
|
211
|
+
get nextSeq(): number;
|
|
212
|
+
get remainingCount(): number;
|
|
213
|
+
get cumulativeSpent(): bigint;
|
|
214
|
+
get remainingBalance(): bigint;
|
|
215
|
+
/**
|
|
216
|
+
* Prepare the next offline hardware payment.
|
|
217
|
+
* Deduplicates retries for identical non-zero `(to, orderId)` without burning `seq + 1` (`AGENTS.md` §1.6).
|
|
218
|
+
*/
|
|
219
|
+
preparePayment(params: {
|
|
220
|
+
readonly to: string | WireAddress;
|
|
221
|
+
readonly amount: bigint;
|
|
222
|
+
readonly maxTip?: bigint;
|
|
223
|
+
readonly expiryTs: bigint;
|
|
224
|
+
readonly expiryLedger: number;
|
|
225
|
+
readonly orderId: bigint;
|
|
226
|
+
readonly exitMarginSecs?: bigint;
|
|
227
|
+
}): PreparedHwPayment;
|
|
228
|
+
/**
|
|
229
|
+
* Prepare the next offline payment directly from a scanned merchant `SREQ1` invoice,
|
|
230
|
+
* automatically verifying token/network/verifier match, safely capping untrusted `SREQ1.tip`
|
|
231
|
+
* (`AGENTS.md` §1.6), and clamping `expiryTs`/`expiryLedger` inside the safe exit horizon.
|
|
232
|
+
*/
|
|
233
|
+
preparePaymentFromInvoice(invoice: Sreq1Packet, options: {
|
|
234
|
+
readonly localNowTs: bigint;
|
|
235
|
+
readonly localLedgerSeq?: number;
|
|
236
|
+
readonly maxTipBps?: number;
|
|
237
|
+
readonly exitMarginSecs?: bigint;
|
|
238
|
+
readonly tokenResolver?: TokenResolver;
|
|
239
|
+
}): PreparedHwPayment;
|
|
240
|
+
/**
|
|
241
|
+
* Commit an iOS `DCAppAttestService.generateAssertion` signature (accepts raw ASN.1 DER OR 64B low-S).
|
|
242
|
+
* Verifies P-256 signature locally STRICTLY BEFORE mutating session state (`AGENTS.md` §1.1).
|
|
243
|
+
*/
|
|
244
|
+
commitIosPayment(prepared: PreparedHwPayment, assertion: {
|
|
245
|
+
readonly authData: Uint8Array;
|
|
246
|
+
/** Either raw ASN.1 DER from Apple Secure Enclave OR already-normalized 64B low-S `(r || s)`. */
|
|
247
|
+
readonly signature: Uint8Array;
|
|
248
|
+
}): CommittedHwPayment;
|
|
249
|
+
/**
|
|
250
|
+
* Commit an Android KeyMint / StrongBox single-use signature (accepts ASN.1 DER OR 64B low-S).
|
|
251
|
+
* Verifies Merkle inclusion + P-256 signature locally STRICTLY BEFORE mutating session state (`AGENTS.md` §1.1).
|
|
252
|
+
*/
|
|
253
|
+
commitAndroidPayment(prepared: PreparedHwPayment, sigParams: {
|
|
254
|
+
/** Either ASN.1 DER from `Signature("SHA256withECDSA")` OR canonical 64B low-S `(r || s)`. */
|
|
255
|
+
readonly signature: Uint8Array;
|
|
256
|
+
readonly leafPubkey65?: Uint8Array;
|
|
257
|
+
readonly merkleProof?: readonly Uint8Array[];
|
|
258
|
+
}): CommittedHwPayment;
|
|
259
|
+
buildPacketUpTo(seq: number): Smeshh1Packet;
|
|
260
|
+
buildCurrentPacket(): Smeshh1Packet;
|
|
261
|
+
encodeCurrentQr(options?: {
|
|
262
|
+
readonly staticQrMaxChars?: number;
|
|
263
|
+
readonly maxChunkBytes?: number;
|
|
264
|
+
}): Smeshh1QrPayload;
|
|
265
|
+
encodeCurrentBleChunks(attValueMtu: number, msgId?: number): Uint8Array[];
|
|
266
|
+
/** Serialize session state to versioned portable JSON for Keychain / Keystore / MMKV / SecureStore. */
|
|
267
|
+
toJson(): string;
|
|
268
|
+
/** Restore a persisted `HwPocketSession` from versioned JSON (re-verifying `HwGenesisCert`!). */
|
|
269
|
+
static fromJson(json: string): HwPocketSession;
|
|
270
|
+
}
|