@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,665 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soroban Contract Call Operation Builders for Outpost v1.2 (`VaultFactory` & `UserVault`).
|
|
3
|
+
*
|
|
4
|
+
* Pure browser/WebView/Node compatible (uses `Uint8Array`, zero Node `Buffer` dependencies)
|
|
5
|
+
* and 100% asset-agnostic across all Stellar SAC and SEP-41 token contracts.
|
|
6
|
+
*/
|
|
7
|
+
import * as StellarSdk from "@stellar/stellar-sdk";
|
|
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";
|
|
10
|
+
import { MIN_EXIT_DELAY_SECS, MAX_EXIT_DELAY_SECS } from "./wallet.js";
|
|
11
|
+
import { decodeSmeshc1 } from "./wire.js";
|
|
12
|
+
import { hexToBytes } from "./witnessClient.js";
|
|
13
|
+
import { assertNotMuxedStrKey, assertValidWireAddress, normalizeContractHash, strKeyToWireAddress, wireAddressToStrKey, } from "./xdr.js";
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Internal Normalization & XDR Helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
function normalizeContractStrKey(contract, label) {
|
|
18
|
+
try {
|
|
19
|
+
return StellarSdk.StrKey.encodeContract(normalizeContractHash(contract));
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
throw new Error(`Invalid ${label} contract address: ${err instanceof Error ? err.message : String(err)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function normalizeNonMuxedAddressStrKey(addr, label) {
|
|
26
|
+
if (typeof addr === "string") {
|
|
27
|
+
assertNotMuxedStrKey(addr);
|
|
28
|
+
return wireAddressToStrKey(strKeyToWireAddress(addr));
|
|
29
|
+
}
|
|
30
|
+
assertValidWireAddress(addr);
|
|
31
|
+
const strKey = wireAddressToStrKey(addr);
|
|
32
|
+
if (!strKey) {
|
|
33
|
+
throw new Error(`Invalid ${label} address`);
|
|
34
|
+
}
|
|
35
|
+
return strKey;
|
|
36
|
+
}
|
|
37
|
+
function normalizeFixedBytes(value, expectedLen, label) {
|
|
38
|
+
const bytes = typeof value === "string" ? hexToBytes(value) : new Uint8Array(value);
|
|
39
|
+
assertBytesLength(bytes, expectedLen, label);
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
function normalizeU64BigInt(value, label) {
|
|
43
|
+
if (typeof value === "bigint") {
|
|
44
|
+
if (value < 0n || value > MAX_U64) {
|
|
45
|
+
throw new RangeError(`${label} out of u64 range: ${value}`);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
50
|
+
throw new RangeError(`${label} must be a non-negative safe integer, got ${value}`);
|
|
51
|
+
}
|
|
52
|
+
return BigInt(value);
|
|
53
|
+
}
|
|
54
|
+
function encodeWitnessSigsScVal(witnessSigs, label) {
|
|
55
|
+
if (witnessSigs.length < 1 || witnessSigs.length > MAX_WITNESSES) {
|
|
56
|
+
throw new Error(`${label} must contain between 1 and ${MAX_WITNESSES} signatures, got ${witnessSigs.length}`);
|
|
57
|
+
}
|
|
58
|
+
let prevIdx = -1;
|
|
59
|
+
const entries = [];
|
|
60
|
+
for (let i = 0; i < witnessSigs.length; i++) {
|
|
61
|
+
const entry = witnessSigs[i];
|
|
62
|
+
if (!Number.isInteger(entry.index) || entry.index < 0 || entry.index >= MAX_WITNESSES) {
|
|
63
|
+
throw new Error(`${label}[${i}].index (${entry.index}) must be in 0..${MAX_WITNESSES - 1}`);
|
|
64
|
+
}
|
|
65
|
+
if (entry.index <= prevIdx) {
|
|
66
|
+
throw new Error(`${label} witness indices must be strictly ascending and unique`);
|
|
67
|
+
}
|
|
68
|
+
prevIdx = entry.index;
|
|
69
|
+
const sigBytes = normalizeFixedBytes(entry.signature, 64, `${label}[${i}].signature`);
|
|
70
|
+
entries.push(StellarSdk.xdr.ScVal.scvVec([
|
|
71
|
+
StellarSdk.xdr.ScVal.scvU32(entry.index),
|
|
72
|
+
StellarSdk.xdr.ScVal.scvBytes(sigBytes),
|
|
73
|
+
]));
|
|
74
|
+
}
|
|
75
|
+
return StellarSdk.xdr.ScVal.scvVec(entries);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Low-level Soroban `InvokeHostFunctionOp` (`HostFunctionType::InvokeContract`) builder.
|
|
79
|
+
*/
|
|
80
|
+
export function buildContractCallOp(contractId, method, args, auth = []) {
|
|
81
|
+
if (!method || method.trim().length === 0) {
|
|
82
|
+
throw new Error("Contract method name must be non-empty");
|
|
83
|
+
}
|
|
84
|
+
const strKey = normalizeContractStrKey(contractId, "contractId");
|
|
85
|
+
const invokeArgs = new StellarSdk.xdr.InvokeContractArgs({
|
|
86
|
+
contractAddress: StellarSdk.Address.fromString(strKey).toScAddress(),
|
|
87
|
+
functionName: method,
|
|
88
|
+
args: [...args],
|
|
89
|
+
});
|
|
90
|
+
const func = StellarSdk.xdr.HostFunction.hostFunctionTypeInvokeContract(invokeArgs);
|
|
91
|
+
return StellarSdk.Operation.invokeHostFunction({
|
|
92
|
+
func,
|
|
93
|
+
auth: [...auth],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build `VaultFactory.create_vault(owner: Address) -> Address`.
|
|
98
|
+
*/
|
|
99
|
+
export function buildCreateVaultOp(params) {
|
|
100
|
+
const factoryStrKey = normalizeContractStrKey(params.factoryId, "factoryId");
|
|
101
|
+
const ownerStrKey = normalizeNonMuxedAddressStrKey(params.owner, "owner");
|
|
102
|
+
return buildContractCallOp(factoryStrKey, "create_vault", [
|
|
103
|
+
StellarSdk.Address.fromString(ownerStrKey).toScVal(),
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build read-only view call `VaultFactory.expected_vault(owner: Address) -> Address`.
|
|
108
|
+
*/
|
|
109
|
+
export function buildExpectedVaultOp(params) {
|
|
110
|
+
const factoryStrKey = normalizeContractStrKey(params.factoryId, "factoryId");
|
|
111
|
+
const ownerStrKey = normalizeNonMuxedAddressStrKey(params.owner, "owner");
|
|
112
|
+
return buildContractCallOp(factoryStrKey, "expected_vault", [
|
|
113
|
+
StellarSdk.Address.fromString(ownerStrKey).toScVal(),
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Build read-only view call `VaultFactory.user_vault_wasm_hash() -> BytesN<32>`.
|
|
118
|
+
*/
|
|
119
|
+
export function buildUserVaultWasmHashOp(params) {
|
|
120
|
+
const factoryStrKey = normalizeContractStrKey(params.factoryId, "factoryId");
|
|
121
|
+
return buildContractCallOp(factoryStrKey, "user_vault_wasm_hash", []);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Decode the `Address` (`C...`) returned by `VaultFactory.create_vault` or `expected_vault`.
|
|
125
|
+
*/
|
|
126
|
+
export function parseCreateVaultResult(retval) {
|
|
127
|
+
if (retval.type !== "scvAddress") {
|
|
128
|
+
throw new Error(`Expected scvAddress return value from VaultFactory, got ${retval.type}`);
|
|
129
|
+
}
|
|
130
|
+
const strKey = StellarSdk.Address.fromScVal(retval).toString();
|
|
131
|
+
normalizeContractHash(strKey);
|
|
132
|
+
return strKey;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build `UserVault.deposit(pocket_id, token, amount, device_pubkey, witnesses, witness_threshold, exit_delay_secs)`.
|
|
136
|
+
*/
|
|
137
|
+
export function buildDepositOp(params) {
|
|
138
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
139
|
+
const tokenStrKey = normalizeContractStrKey(params.token, "token");
|
|
140
|
+
if (tokenStrKey === vaultStrKey) {
|
|
141
|
+
throw new Error("deposit `token` cannot equal `vaultId`");
|
|
142
|
+
}
|
|
143
|
+
assertU16(params.pocketId, "pocketId");
|
|
144
|
+
assertBigInt(params.amount, "amount");
|
|
145
|
+
if (params.amount <= 0n || params.amount > MAX_U64) {
|
|
146
|
+
throw new Error(`deposit amount must be > 0 and <= u64::MAX, got ${params.amount}`);
|
|
147
|
+
}
|
|
148
|
+
const devicePubkey = normalizeFixedBytes(params.devicePubkey, 32, "devicePubkey");
|
|
149
|
+
const witnesses = params.witnesses.map((w, i) => normalizeFixedBytes(w, 32, `witnesses[${i}]`));
|
|
150
|
+
assertSortedUniqueWitnesses(witnesses);
|
|
151
|
+
const n = witnesses.length;
|
|
152
|
+
if (!Number.isInteger(params.witnessThreshold) ||
|
|
153
|
+
params.witnessThreshold < 1 ||
|
|
154
|
+
params.witnessThreshold > n ||
|
|
155
|
+
params.witnessThreshold * 2 <= n) {
|
|
156
|
+
throw new Error(`witnessThreshold (${params.witnessThreshold}) must satisfy 0 < t <= n and 2t > n (n=${n})`);
|
|
157
|
+
}
|
|
158
|
+
const exitDelaySecs = normalizeU64BigInt(params.exitDelaySecs, "exitDelaySecs");
|
|
159
|
+
if (exitDelaySecs < MIN_EXIT_DELAY_SECS || exitDelaySecs > MAX_EXIT_DELAY_SECS) {
|
|
160
|
+
throw new Error(`exitDelaySecs (${exitDelaySecs}) must be within [${MIN_EXIT_DELAY_SECS}, ${MAX_EXIT_DELAY_SECS}]`);
|
|
161
|
+
}
|
|
162
|
+
return buildContractCallOp(vaultStrKey, "deposit", [
|
|
163
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
164
|
+
StellarSdk.Address.fromString(tokenStrKey).toScVal(),
|
|
165
|
+
StellarSdk.nativeToScVal(params.amount, { type: "i128" }),
|
|
166
|
+
StellarSdk.xdr.ScVal.scvBytes(devicePubkey),
|
|
167
|
+
StellarSdk.xdr.ScVal.scvVec(witnesses.map((w) => StellarSdk.xdr.ScVal.scvBytes(w))),
|
|
168
|
+
StellarSdk.xdr.ScVal.scvU32(params.witnessThreshold),
|
|
169
|
+
StellarSdk.nativeToScVal(exitDelaySecs, { type: "u64" }),
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Build `UserVault.settle_delegated(...)` either directly from a `SMESHC1` certificate or from
|
|
174
|
+
* explicit fields.
|
|
175
|
+
*/
|
|
176
|
+
export function buildSettleDelegatedOp(params) {
|
|
177
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
178
|
+
let pocketId;
|
|
179
|
+
let epoch;
|
|
180
|
+
let seq;
|
|
181
|
+
let toStrKey;
|
|
182
|
+
let amount;
|
|
183
|
+
let maxTip;
|
|
184
|
+
let actualTip;
|
|
185
|
+
let gatewayStrKey;
|
|
186
|
+
let expiryTs;
|
|
187
|
+
let expiryLedger;
|
|
188
|
+
let orderId;
|
|
189
|
+
let cumulativeSpent;
|
|
190
|
+
let deviceSig;
|
|
191
|
+
let witnessSigsScVal;
|
|
192
|
+
if ("cert" in params) {
|
|
193
|
+
const cert = typeof params.cert === "string" ? decodeSmeshc1(params.cert) : params.cert;
|
|
194
|
+
const { intent } = cert;
|
|
195
|
+
pocketId = intent.pocketId;
|
|
196
|
+
epoch = intent.epoch;
|
|
197
|
+
seq = intent.seq;
|
|
198
|
+
toStrKey = normalizeNonMuxedAddressStrKey(intent.to, "cert.intent.to");
|
|
199
|
+
amount = intent.amount;
|
|
200
|
+
maxTip = intent.maxTip;
|
|
201
|
+
actualTip = params.actualTip ?? 0n;
|
|
202
|
+
gatewayStrKey = normalizeNonMuxedAddressStrKey(params.gateway, "gateway");
|
|
203
|
+
expiryTs = normalizeU64BigInt(intent.expiryTs, "cert.intent.expiryTs");
|
|
204
|
+
expiryLedger = intent.expiryLedger;
|
|
205
|
+
orderId = intent.orderId;
|
|
206
|
+
cumulativeSpent = cert.cumulativeSpent;
|
|
207
|
+
deviceSig = normalizeFixedBytes(intent.deviceSig, 64, "cert.intent.deviceSig");
|
|
208
|
+
witnessSigsScVal = encodeWitnessSigsScVal(cert.witnessSigs, "cert.witnessSigs");
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
pocketId = params.pocketId;
|
|
212
|
+
epoch = params.epoch;
|
|
213
|
+
seq = params.seq;
|
|
214
|
+
toStrKey = normalizeNonMuxedAddressStrKey(params.to, "to");
|
|
215
|
+
amount = params.amount;
|
|
216
|
+
maxTip = params.maxTip;
|
|
217
|
+
actualTip = params.actualTip;
|
|
218
|
+
gatewayStrKey = normalizeNonMuxedAddressStrKey(params.gateway, "gateway");
|
|
219
|
+
expiryTs = normalizeU64BigInt(params.expiryTs, "expiryTs");
|
|
220
|
+
expiryLedger = params.expiryLedger;
|
|
221
|
+
orderId = params.orderId;
|
|
222
|
+
cumulativeSpent = params.cumulativeSpent;
|
|
223
|
+
deviceSig = normalizeFixedBytes(params.deviceSig, 64, "deviceSig");
|
|
224
|
+
witnessSigsScVal = encodeWitnessSigsScVal(params.witnessSigs, "witnessSigs");
|
|
225
|
+
}
|
|
226
|
+
assertU16(pocketId, "pocketId");
|
|
227
|
+
assertU32(epoch, "epoch");
|
|
228
|
+
if (epoch === 0)
|
|
229
|
+
throw new Error("settle_delegated epoch must be >= 1");
|
|
230
|
+
assertU32(seq, "seq");
|
|
231
|
+
if (seq === 0)
|
|
232
|
+
throw new Error("settle_delegated seq must be >= 1");
|
|
233
|
+
assertU32(expiryLedger, "expiryLedger");
|
|
234
|
+
assertBigInt(amount, "amount");
|
|
235
|
+
assertBigInt(maxTip, "maxTip");
|
|
236
|
+
assertBigInt(actualTip, "actualTip");
|
|
237
|
+
assertBigInt(orderId, "orderId");
|
|
238
|
+
assertBigInt(cumulativeSpent, "cumulativeSpent");
|
|
239
|
+
if (toStrKey === vaultStrKey || gatewayStrKey === vaultStrKey) {
|
|
240
|
+
throw new Error("settle_delegated SelfTransfer forbidden: to/gateway cannot equal vaultId");
|
|
241
|
+
}
|
|
242
|
+
if (amount <= 0n || amount > MAX_U64) {
|
|
243
|
+
throw new Error(`settle_delegated amount out of range: ${amount}`);
|
|
244
|
+
}
|
|
245
|
+
if (maxTip < 0n || actualTip < 0n || actualTip > maxTip) {
|
|
246
|
+
throw new Error(`settle_delegated invalid tip: actualTip=${actualTip}, maxTip=${maxTip}`);
|
|
247
|
+
}
|
|
248
|
+
if (orderId < 0n || orderId > MAX_U64) {
|
|
249
|
+
throw new RangeError(`settle_delegated orderId out of u64 range: ${orderId}`);
|
|
250
|
+
}
|
|
251
|
+
if (cumulativeSpent < amount + maxTip) {
|
|
252
|
+
throw new Error(`settle_delegated cumulativeSpent (${cumulativeSpent}) < amount + maxTip (${amount + maxTip})`);
|
|
253
|
+
}
|
|
254
|
+
return buildContractCallOp(vaultStrKey, "settle_delegated", [
|
|
255
|
+
StellarSdk.xdr.ScVal.scvU32(pocketId),
|
|
256
|
+
StellarSdk.xdr.ScVal.scvU32(epoch),
|
|
257
|
+
StellarSdk.xdr.ScVal.scvU32(seq),
|
|
258
|
+
StellarSdk.Address.fromString(toStrKey).toScVal(),
|
|
259
|
+
StellarSdk.nativeToScVal(amount, { type: "i128" }),
|
|
260
|
+
StellarSdk.nativeToScVal(maxTip, { type: "i128" }),
|
|
261
|
+
StellarSdk.nativeToScVal(actualTip, { type: "i128" }),
|
|
262
|
+
StellarSdk.Address.fromString(gatewayStrKey).toScVal(),
|
|
263
|
+
StellarSdk.nativeToScVal(expiryTs, { type: "u64" }),
|
|
264
|
+
StellarSdk.xdr.ScVal.scvU32(expiryLedger),
|
|
265
|
+
StellarSdk.nativeToScVal(orderId, { type: "u64" }),
|
|
266
|
+
StellarSdk.nativeToScVal(cumulativeSpent, { type: "i128" }),
|
|
267
|
+
StellarSdk.xdr.ScVal.scvBytes(deviceSig),
|
|
268
|
+
witnessSigsScVal,
|
|
269
|
+
]);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Build `UserVault.close_pocket_cooperative(pocket_id, to_alt, witness_sigs)`.
|
|
273
|
+
*/
|
|
274
|
+
export function buildClosePocketCooperativeOp(params) {
|
|
275
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
276
|
+
assertU16(params.pocketId, "pocketId");
|
|
277
|
+
const toAltStrKey = normalizeNonMuxedAddressStrKey(params.toAlt, "toAlt");
|
|
278
|
+
if (toAltStrKey === vaultStrKey) {
|
|
279
|
+
throw new Error("close_pocket_cooperative SelfTransfer forbidden: toAlt cannot equal vaultId");
|
|
280
|
+
}
|
|
281
|
+
const witnessSigsScVal = encodeWitnessSigsScVal(params.witnessSigs, "witnessSigs");
|
|
282
|
+
return buildContractCallOp(vaultStrKey, "close_pocket_cooperative", [
|
|
283
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
284
|
+
StellarSdk.Address.fromString(toAltStrKey).toScVal(),
|
|
285
|
+
witnessSigsScVal,
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Build `UserVault.request_exit(pocket_id)` — initiates unilateral timelocked exit (`exit_delay_secs`).
|
|
290
|
+
*/
|
|
291
|
+
export function buildRequestExitOp(params) {
|
|
292
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
293
|
+
assertU16(params.pocketId, "pocketId");
|
|
294
|
+
return buildContractCallOp(vaultStrKey, "request_exit", [
|
|
295
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
296
|
+
]);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Build `UserVault.finalize_exit(pocket_id, to_alt)` — sweeps pocket after `pending_exit_ts` elapses.
|
|
300
|
+
*/
|
|
301
|
+
export function buildFinalizeExitOp(params) {
|
|
302
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
303
|
+
assertU16(params.pocketId, "pocketId");
|
|
304
|
+
const toAltStrKey = normalizeNonMuxedAddressStrKey(params.toAlt, "toAlt");
|
|
305
|
+
if (toAltStrKey === vaultStrKey) {
|
|
306
|
+
throw new Error("finalize_exit SelfTransfer forbidden: toAlt cannot equal vaultId");
|
|
307
|
+
}
|
|
308
|
+
return buildContractCallOp(vaultStrKey, "finalize_exit", [
|
|
309
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
310
|
+
StellarSdk.Address.fromString(toAltStrKey).toScVal(),
|
|
311
|
+
]);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Build `UserVault.claim_credit(recipient, token, to_alt)` — claims parked credits when a classic
|
|
315
|
+
* trustline or SAC transfer previously bounced during `settle_delegated`.
|
|
316
|
+
*/
|
|
317
|
+
export function buildClaimCreditOp(params) {
|
|
318
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
319
|
+
const recipientStrKey = normalizeNonMuxedAddressStrKey(params.recipient, "recipient");
|
|
320
|
+
const tokenStrKey = normalizeContractStrKey(params.token, "token");
|
|
321
|
+
const toAltStrKey = normalizeNonMuxedAddressStrKey(params.toAlt, "toAlt");
|
|
322
|
+
if (toAltStrKey === vaultStrKey) {
|
|
323
|
+
throw new Error("claim_credit SelfTransfer forbidden: toAlt cannot equal vaultId");
|
|
324
|
+
}
|
|
325
|
+
return buildContractCallOp(vaultStrKey, "claim_credit", [
|
|
326
|
+
StellarSdk.Address.fromString(recipientStrKey).toScVal(),
|
|
327
|
+
StellarSdk.Address.fromString(tokenStrKey).toScVal(),
|
|
328
|
+
StellarSdk.Address.fromString(toAltStrKey).toScVal(),
|
|
329
|
+
]);
|
|
330
|
+
}
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
// Read-Only View Call Builders & Decoders
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
/**
|
|
335
|
+
* Build read-only view call `UserVault.pocket_of(pocket_id: u32) -> Option<PocketState>`.
|
|
336
|
+
*/
|
|
337
|
+
export function buildPocketOfOp(params) {
|
|
338
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
339
|
+
assertU16(params.pocketId, "pocketId");
|
|
340
|
+
return buildContractCallOp(vaultStrKey, "pocket_of", [
|
|
341
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
342
|
+
]);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Build read-only view call `UserVault.credit_of(recipient: Address, token: Address) -> i128`.
|
|
346
|
+
*/
|
|
347
|
+
export function buildCreditOfOp(params) {
|
|
348
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
349
|
+
const recipientStrKey = normalizeNonMuxedAddressStrKey(params.recipient, "recipient");
|
|
350
|
+
const tokenStrKey = normalizeContractStrKey(params.token, "token");
|
|
351
|
+
return buildContractCallOp(vaultStrKey, "credit_of", [
|
|
352
|
+
StellarSdk.Address.fromString(recipientStrKey).toScVal(),
|
|
353
|
+
StellarSdk.Address.fromString(tokenStrKey).toScVal(),
|
|
354
|
+
]);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Build read-only view call `UserVault.is_settled(pocket_id: u32, epoch: u32, seq: u32) -> bool`.
|
|
358
|
+
*/
|
|
359
|
+
export function buildIsSettledOp(params) {
|
|
360
|
+
const vaultStrKey = normalizeContractStrKey(params.vaultId, "vaultId");
|
|
361
|
+
assertU16(params.pocketId, "pocketId");
|
|
362
|
+
assertU32(params.epoch, "epoch");
|
|
363
|
+
assertU32(params.seq, "seq");
|
|
364
|
+
return buildContractCallOp(vaultStrKey, "is_settled", [
|
|
365
|
+
StellarSdk.xdr.ScVal.scvU32(params.pocketId),
|
|
366
|
+
StellarSdk.xdr.ScVal.scvU32(params.epoch),
|
|
367
|
+
StellarSdk.xdr.ScVal.scvU32(params.seq),
|
|
368
|
+
]);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Decode `Option<PocketState>` returned by `UserVault.pocket_of(pocket_id)` simulation.
|
|
372
|
+
* Returns `null` when `ScVal` is `scvVoid` (`None`).
|
|
373
|
+
*/
|
|
374
|
+
export function decodePocketStateScVal(scVal) {
|
|
375
|
+
if (scVal.type === "scvVoid") {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
if (scVal.type !== "scvMap" || !scVal.map) {
|
|
379
|
+
throw new Error(`Expected scvMap or scvVoid for PocketState, got ${scVal.type}`);
|
|
380
|
+
}
|
|
381
|
+
const fields = new Map();
|
|
382
|
+
for (const entry of scVal.map) {
|
|
383
|
+
if (entry.key.type === "scvSymbol") {
|
|
384
|
+
fields.set(String(StellarSdk.scValToNative(entry.key)), entry.val);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const getField = (name) => {
|
|
388
|
+
const v = fields.get(name);
|
|
389
|
+
if (!v)
|
|
390
|
+
throw new Error(`PocketState ScVal missing required field "${name}"`);
|
|
391
|
+
return v;
|
|
392
|
+
};
|
|
393
|
+
const tokenVal = getField("token");
|
|
394
|
+
if (tokenVal.type !== "scvAddress") {
|
|
395
|
+
throw new Error(`PocketState.token expected scvAddress, got ${tokenVal.type}`);
|
|
396
|
+
}
|
|
397
|
+
const token = StellarSdk.Address.fromScVal(tokenVal).toString();
|
|
398
|
+
normalizeContractHash(token);
|
|
399
|
+
const balance = StellarSdk.scValToBigInt(getField("balance"));
|
|
400
|
+
const epochTotalDeposited = StellarSdk.scValToBigInt(getField("epoch_total_deposited"));
|
|
401
|
+
const deviceVal = getField("device_pubkey");
|
|
402
|
+
if (deviceVal.type !== "scvBytes") {
|
|
403
|
+
throw new Error(`PocketState.device_pubkey expected scvBytes, got ${deviceVal.type}`);
|
|
404
|
+
}
|
|
405
|
+
const deviceNative = StellarSdk.scValToNative(deviceVal);
|
|
406
|
+
const devicePubkey = new Uint8Array(deviceNative);
|
|
407
|
+
assertBytesLength(devicePubkey, 32, "PocketState.device_pubkey");
|
|
408
|
+
const witnessesVal = getField("witnesses");
|
|
409
|
+
if (witnessesVal.type !== "scvVec" || !witnessesVal.vec) {
|
|
410
|
+
throw new Error(`PocketState.witnesses expected scvVec, got ${witnessesVal.type}`);
|
|
411
|
+
}
|
|
412
|
+
const witnesses = witnessesVal.vec.map((w, idx) => {
|
|
413
|
+
if (w.type !== "scvBytes") {
|
|
414
|
+
throw new Error(`PocketState.witnesses[${idx}] expected scvBytes, got ${w.type}`);
|
|
415
|
+
}
|
|
416
|
+
const wNative = StellarSdk.scValToNative(w);
|
|
417
|
+
const b = new Uint8Array(wNative);
|
|
418
|
+
assertBytesLength(b, 32, `PocketState.witnesses[${idx}]`);
|
|
419
|
+
return b;
|
|
420
|
+
});
|
|
421
|
+
const witnessThreshold = Number(StellarSdk.scValToBigInt(getField("witness_threshold")));
|
|
422
|
+
const exitDelaySecs = StellarSdk.scValToBigInt(getField("exit_delay_secs"));
|
|
423
|
+
const pendingExitTs = StellarSdk.scValToBigInt(getField("pending_exit_ts"));
|
|
424
|
+
const epoch = Number(StellarSdk.scValToBigInt(getField("epoch")));
|
|
425
|
+
return {
|
|
426
|
+
token,
|
|
427
|
+
balance,
|
|
428
|
+
epochTotalDeposited,
|
|
429
|
+
devicePubkey,
|
|
430
|
+
witnesses,
|
|
431
|
+
witnessThreshold,
|
|
432
|
+
exitDelaySecs,
|
|
433
|
+
pendingExitTs,
|
|
434
|
+
epoch,
|
|
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
|
+
}
|