@chironbuilder/ootle-sdk 0.1.1 → 0.1.3
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/dist/storage.d.ts +6 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +30 -2
- package/dist/wallet.d.ts +31 -0
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +119 -12
- package/package.json +1 -1
package/dist/storage.d.ts
CHANGED
|
@@ -40,7 +40,12 @@ export interface PendingShield {
|
|
|
40
40
|
export declare function localAccountId(index: number): string;
|
|
41
41
|
/** Runs a whole read-modify-write cycle to completion before the next one starts, so two
|
|
42
42
|
* concurrent callers (two tabs, a page request racing a popup request) can't interleave their
|
|
43
|
-
* read-modify-write on this key and silently clobber each other's write.
|
|
43
|
+
* read-modify-write on this key and silently clobber each other's write.
|
|
44
|
+
*
|
|
45
|
+
* Never nest a call to this (or to another function that itself calls this, like every setter in
|
|
46
|
+
* this file) inside a `serialized()` callback if you can avoid it -- the fallback above keeps it
|
|
47
|
+
* from deadlocking, but the nested call then runs *outside* the ordering guarantee this exists to
|
|
48
|
+
* provide. */
|
|
44
49
|
export declare function serialized<T>(fn: () => Promise<T>): Promise<T>;
|
|
45
50
|
export declare function listShieldedOutputs(accountId: string): Promise<ShieldedOutputRecord[]>;
|
|
46
51
|
export declare function addShieldedOutput(record: ShieldedOutputRecord): Promise<void>;
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAC5C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA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,GAAG,OAAO,CAAC,IAAI,CAAC,CASlG;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC,CAEnE;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAM5E;AAED,wBAAsB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9E;AAED,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3F;AAED,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKzG;AAED;yBACyB;AACzB,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAExE;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAInF;AAED;;mFAEmF;AACnF,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpD"}
|
package/dist/storage.js
CHANGED
|
@@ -40,11 +40,39 @@ async function write(patch) {
|
|
|
40
40
|
await store().set(STORAGE_KEY, { ...(await read()), ...patch });
|
|
41
41
|
}
|
|
42
42
|
let writeQueue = Promise.resolve();
|
|
43
|
+
// >0 while a callback passed to `serialized()` is actually running (including across its own
|
|
44
|
+
// `await`s) -- lets a call from *inside* that callback detect it's nested and run immediately
|
|
45
|
+
// instead of queuing behind a queue slot that can only advance once it finishes, which is a
|
|
46
|
+
// deadlock (confirmed empirically: wallet.ts's recordKnownVersions() used to wrap a call to
|
|
47
|
+
// setKnownVersions() -- which serializes its own write -- in its own serialized() block; the
|
|
48
|
+
// inner call waited for the outer call's queue slot to free up, which was itself awaiting the
|
|
49
|
+
// inner call). Safe for genuinely concurrent (non-nested) callers: `depth` is only ever
|
|
50
|
+
// incremented inside the deferred callback below, never at the synchronous call site, so two
|
|
51
|
+
// unrelated top-level `serialized()` calls dispatched back-to-back both see `depth === 0` and
|
|
52
|
+
// queue normally regardless of how their execution ends up overlapping in time -- this only ever
|
|
53
|
+
// fires for a call genuinely reachable from within an already-running callback's own call graph.
|
|
54
|
+
let depth = 0;
|
|
43
55
|
/** Runs a whole read-modify-write cycle to completion before the next one starts, so two
|
|
44
56
|
* concurrent callers (two tabs, a page request racing a popup request) can't interleave their
|
|
45
|
-
* read-modify-write on this key and silently clobber each other's write.
|
|
57
|
+
* read-modify-write on this key and silently clobber each other's write.
|
|
58
|
+
*
|
|
59
|
+
* Never nest a call to this (or to another function that itself calls this, like every setter in
|
|
60
|
+
* this file) inside a `serialized()` callback if you can avoid it -- the fallback above keeps it
|
|
61
|
+
* from deadlocking, but the nested call then runs *outside* the ordering guarantee this exists to
|
|
62
|
+
* provide. */
|
|
46
63
|
export function serialized(fn) {
|
|
47
|
-
|
|
64
|
+
if (depth > 0)
|
|
65
|
+
return fn();
|
|
66
|
+
const run = async () => {
|
|
67
|
+
depth++;
|
|
68
|
+
try {
|
|
69
|
+
return await fn();
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
depth--;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const result = writeQueue.then(run, run);
|
|
48
76
|
writeQueue = result.then(() => undefined, () => undefined);
|
|
49
77
|
return result;
|
|
50
78
|
}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -387,6 +387,37 @@ export declare class OotleAccount implements WalletAccountApi {
|
|
|
387
387
|
withdrawStealthAndExecute(resourceAddress: string, amount: bigint, workspaceVarName: string, followUpInstructions: Instruction[], relatedComponents?: string[], maxFee?: bigint): Promise<{
|
|
388
388
|
transactionId: string;
|
|
389
389
|
}>;
|
|
390
|
+
/**
|
|
391
|
+
* Redeems one *specific, externally-known* stealth (freestanding) UTXO — a commitment this
|
|
392
|
+
* account was told about out of band (e.g. a ticket/ballot/voucher token some other party
|
|
393
|
+
* minted straight to this wallet's address), as opposed to `withdrawStealthAndExecute`'s
|
|
394
|
+
* *amount* drawn from this account's own tracked vault balance. Reveals the output's full
|
|
395
|
+
* value as a `Bucket` on the workspace under id `0`, then runs `followUpInstructions` (which
|
|
396
|
+
* must reference that bucket via `{Workspace: {id: 0, offset: null}}`) in the same signed
|
|
397
|
+
* transaction — e.g. handing it straight to a voting/redemption contract's own method.
|
|
398
|
+
*
|
|
399
|
+
* `revealedAmount` must be the output's *actual* value — there is no client-side way to
|
|
400
|
+
* discover it other than decrypting the UTXO (which this method's `WalletStealthAuthorizer`
|
|
401
|
+
* step does internally, using this account's own view secret, as part of resolving the
|
|
402
|
+
* spend); the caller is expected to already know it from whatever protocol minted the token
|
|
403
|
+
* (e.g. a fixed "amount-1 ballot" convention). A wrong value fails the balance proof inside
|
|
404
|
+
* `prepare()`, not silently.
|
|
405
|
+
*
|
|
406
|
+
* Bypasses the `StealthTransfer` fluent builder (its `spendStealthInput` targets *this
|
|
407
|
+
* account's own* previously-shielded outputs, tracked in local storage — see `unshield`'s doc
|
|
408
|
+
* comment on why no scan-by-commitment API exists for outputs this account never shielded
|
|
409
|
+
* itself) and instead hand-builds the same wire statement `unshield`/`shield`/
|
|
410
|
+
* `withdrawStealthAndExecute` produce via the builder, the same way the reference voter
|
|
411
|
+
* client for this pattern does (a zero-stealth-input-count, `KeyPath`-witnessed, fully-revealed
|
|
412
|
+
* transfer) — `WalletStealthAuthorizer.prepare()` fetches and unblinds the named commitment the
|
|
413
|
+
* same way regardless of which path built the statement.
|
|
414
|
+
*
|
|
415
|
+
* @param relatedComponents Every *other* component `followUpInstructions` touches — same
|
|
416
|
+
* reasoning as `withdrawStealthAndExecute`'s own parameter of the same name.
|
|
417
|
+
*/
|
|
418
|
+
redeemStealthOutputAndExecute(resourceAddress: string, commitmentHex: string, revealedAmount: bigint, followUpInstructions: Instruction[], relatedComponents?: string[], maxFee?: bigint): Promise<{
|
|
419
|
+
transactionId: string;
|
|
420
|
+
}>;
|
|
390
421
|
/**
|
|
391
422
|
* Funds an HTLC (hashed timelock contract): creates a stealth output for `amount` of
|
|
392
423
|
* `resourceAddress`, gated not by a normal one-time stealth key but by a two-leaf TIP-0006
|
package/dist/wallet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EA0BR,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,aAAa,EACb,mCAAmC,EACnC,WAAW,EAIX,mBAAmB,EACnB,aAAa,EACd,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAYxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI9D,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAcrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIzD,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf;;;wCAGoC;IACpC,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;kCAE8B;IAC9B,2BAA2B,EAAE,MAAM,CAAC;IACpC;yEACqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB;sEACkE;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;oDACgD;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mCAAmC,CAAC,CAwB9C;AAmBD,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,eAAe,EACzB,YAAY,EAAE,mBAAmB,EAAE,EACnC,OAAO,SAAI,EACX,YAAY,SAAM,GACjB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAUhC;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQpG;AAmBD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5E;AAOD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAGvG"}
|
package/dist/wallet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OotleWallet, StealthTransfer, TransactionBuilder, WalletStealthAuthorizer, WasmStealthCrypto, XTR_FAUCET_CLAIM_RESOURCE_ADDRESS, XTR_FAUCET_COMPONENT_ADDRESS, XTR_FAUCET_VAULT_ADDRESS, amountLiteral, createOutput, decryptOwnedUtxo, defaultIndexerUrl, getVaultIdsForAccount, resolveMaxEpoch, resolveTransaction, resourceAddressLiteral, sealTransaction, sendTransaction, signTransaction, stealthUtxoSubstateId, submitTransaction, } from "@tari-project/ootle";
|
|
1
|
+
import { Mask, OotleWallet, StealthInput, StealthInputsStatement, StealthOutputsStatement, StealthTransfer, StealthTransferStatement, TransactionBuilder, WalletStealthAuthorizer, WasmStealthCrypto, XTR_FAUCET_CLAIM_RESOURCE_ADDRESS, XTR_FAUCET_COMPONENT_ADDRESS, XTR_FAUCET_VAULT_ADDRESS, amountLiteral, createOutput, decryptOwnedUtxo, defaultIndexerUrl, getVaultIdsForAccount, resolveMaxEpoch, resolveTransaction, resourceAddressLiteral, sealTransaction, sendTransaction, signTransaction, stealthUtxoSubstateId, submitTransaction, } from "@tari-project/ootle";
|
|
2
2
|
import { IndexerProvider } from "@tari-project/ootle-indexer";
|
|
3
3
|
import { SecretKeyWallet } from "@tari-project/ootle-secret-key-wallet";
|
|
4
4
|
import { buildScriptPathWitness, buildStealthTransferStatement, createConfidentialWithdrawProofLiteral, createStealthOutputWitness, parseOotleAddress, publicKeyFromSecretKey, schnorrSign, stealthDhSecret, validateStealthTransfer, } from "@tari-project/ootle-wasm";
|
|
@@ -8,7 +8,7 @@ import { deriveAccountKeys } from "./derivation.js";
|
|
|
8
8
|
import { htlcConditions } from "./htlc.js";
|
|
9
9
|
import { buildOwnershipProofMessage, buildWalletOwnershipMessage } from "./ownershipProof.js";
|
|
10
10
|
import { toOotleNetwork } from "./ootleNetwork.js";
|
|
11
|
-
import { addPendingShield, addShieldedOutput, getKnownVersions, getPrivatePaymentScanCursor, listPendingShields, listShieldedOutputs, localAccountId, markShieldedOutputSpent, removePendingShield,
|
|
11
|
+
import { addPendingShield, addShieldedOutput, getKnownVersions, getPrivatePaymentScanCursor, listPendingShields, listShieldedOutputs, localAccountId, markShieldedOutputSpent, removePendingShield, setKnownVersions, setPrivatePaymentScanCursor, } from "./storage.js";
|
|
12
12
|
import { withTimeout } from "./timeout.js";
|
|
13
13
|
import { fromHex, toHex } from "./vault.js";
|
|
14
14
|
/**
|
|
@@ -993,6 +993,111 @@ export class OotleAccount {
|
|
|
993
993
|
await recordKnownVersions(response);
|
|
994
994
|
return { transactionId };
|
|
995
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* Redeems one *specific, externally-known* stealth (freestanding) UTXO — a commitment this
|
|
998
|
+
* account was told about out of band (e.g. a ticket/ballot/voucher token some other party
|
|
999
|
+
* minted straight to this wallet's address), as opposed to `withdrawStealthAndExecute`'s
|
|
1000
|
+
* *amount* drawn from this account's own tracked vault balance. Reveals the output's full
|
|
1001
|
+
* value as a `Bucket` on the workspace under id `0`, then runs `followUpInstructions` (which
|
|
1002
|
+
* must reference that bucket via `{Workspace: {id: 0, offset: null}}`) in the same signed
|
|
1003
|
+
* transaction — e.g. handing it straight to a voting/redemption contract's own method.
|
|
1004
|
+
*
|
|
1005
|
+
* `revealedAmount` must be the output's *actual* value — there is no client-side way to
|
|
1006
|
+
* discover it other than decrypting the UTXO (which this method's `WalletStealthAuthorizer`
|
|
1007
|
+
* step does internally, using this account's own view secret, as part of resolving the
|
|
1008
|
+
* spend); the caller is expected to already know it from whatever protocol minted the token
|
|
1009
|
+
* (e.g. a fixed "amount-1 ballot" convention). A wrong value fails the balance proof inside
|
|
1010
|
+
* `prepare()`, not silently.
|
|
1011
|
+
*
|
|
1012
|
+
* Bypasses the `StealthTransfer` fluent builder (its `spendStealthInput` targets *this
|
|
1013
|
+
* account's own* previously-shielded outputs, tracked in local storage — see `unshield`'s doc
|
|
1014
|
+
* comment on why no scan-by-commitment API exists for outputs this account never shielded
|
|
1015
|
+
* itself) and instead hand-builds the same wire statement `unshield`/`shield`/
|
|
1016
|
+
* `withdrawStealthAndExecute` produce via the builder, the same way the reference voter
|
|
1017
|
+
* client for this pattern does (a zero-stealth-input-count, `KeyPath`-witnessed, fully-revealed
|
|
1018
|
+
* transfer) — `WalletStealthAuthorizer.prepare()` fetches and unblinds the named commitment the
|
|
1019
|
+
* same way regardless of which path built the statement.
|
|
1020
|
+
*
|
|
1021
|
+
* @param relatedComponents Every *other* component `followUpInstructions` touches — same
|
|
1022
|
+
* reasoning as `withdrawStealthAndExecute`'s own parameter of the same name.
|
|
1023
|
+
*/
|
|
1024
|
+
async redeemStealthOutputAndExecute(resourceAddress, commitmentHex, revealedAmount, followUpInstructions, relatedComponents = [], maxFee = 100000n) {
|
|
1025
|
+
if (revealedAmount <= 0n) {
|
|
1026
|
+
throw new Error(`redeemStealthOutputAndExecute: revealedAmount must be > 0, got ${revealedAmount}`);
|
|
1027
|
+
}
|
|
1028
|
+
if (!/^[0-9a-f]{64}$/i.test(commitmentHex)) {
|
|
1029
|
+
throw new Error(`redeemStealthOutputAndExecute: commitmentHex must be exactly 64 hex characters (32 bytes)`);
|
|
1030
|
+
}
|
|
1031
|
+
const provider = await this.getProvider();
|
|
1032
|
+
const account = await this.getComponentAddress();
|
|
1033
|
+
const commitment = fromHex(commitmentHex);
|
|
1034
|
+
// An "incomplete" statement: the input side only names the commitment being spent (its mask
|
|
1035
|
+
// and value are recovered later, by the authorizer, from the on-chain UTXO) and declares a
|
|
1036
|
+
// `KeyPath` witness — ordinary one-time-key ownership, the same proof shield/unshield/
|
|
1037
|
+
// withdrawStealthAndExecute use, as opposed to htlcClaim/htlcRefund's script-path leaf. The
|
|
1038
|
+
// output side is empty (no new stealth output at all): the full value is revealed instead.
|
|
1039
|
+
const inputsJson = JSON.stringify({
|
|
1040
|
+
inputs: [{ commitment: commitmentHex, witness: "KeyPath" }],
|
|
1041
|
+
revealed_amount: "0",
|
|
1042
|
+
});
|
|
1043
|
+
const outputsJson = JSON.stringify({
|
|
1044
|
+
outputs: [],
|
|
1045
|
+
revealed_output_amount: revealedAmount.toString(),
|
|
1046
|
+
agg_range_proof: "",
|
|
1047
|
+
});
|
|
1048
|
+
const statement = new StealthTransferStatement(new StealthInputsStatement([], 0n, inputsJson), new StealthOutputsStatement(outputsJson));
|
|
1049
|
+
const maxEpoch = await resolveMaxEpoch(provider);
|
|
1050
|
+
const builder = TransactionBuilder.new(this.network, maxEpoch)
|
|
1051
|
+
.addInstruction({
|
|
1052
|
+
StealthTransfer: {
|
|
1053
|
+
resource_address_ref: { Address: resourceAddress },
|
|
1054
|
+
statement: { __ootleRawJson: statement.toCompactJson() },
|
|
1055
|
+
revealed_input_bucket: null,
|
|
1056
|
+
},
|
|
1057
|
+
})
|
|
1058
|
+
// Claims workspace id 0 for the revealed bucket above — followUpInstructions must reference
|
|
1059
|
+
// it as a plain numeric `{Workspace: {id: 0, offset: null}}`, not a named `{Workspace: ".."}`
|
|
1060
|
+
// (name resolution only applies to instructions built through *this* same chain; raw
|
|
1061
|
+
// pre-built instructions bypass it, same constraint `withdrawStealthAndExecute` documents).
|
|
1062
|
+
.saveVar("redeemed")
|
|
1063
|
+
.withInstructions(followUpInstructions)
|
|
1064
|
+
.feeTransactionPayFromComponent(account, maxFee)
|
|
1065
|
+
.addInput({ substate_id: resourceAddress, version: null })
|
|
1066
|
+
.addInput({ substate_id: stealthUtxoSubstateId(resourceAddress, commitment), version: null })
|
|
1067
|
+
.addInput({ substate_id: account, version: null });
|
|
1068
|
+
for (const vaultId of await getVaultIdsForAccount(provider, account)) {
|
|
1069
|
+
builder.addInput({ substate_id: vaultId, version: null });
|
|
1070
|
+
}
|
|
1071
|
+
for (const component of relatedComponents) {
|
|
1072
|
+
builder.addInput({ substate_id: component, version: null });
|
|
1073
|
+
for (const vaultId of await getVaultIdsForAccount(provider, component)) {
|
|
1074
|
+
builder.addInput({ substate_id: vaultId, version: null });
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
const unsignedTx = await resolveTransaction(provider, builder.buildUnsignedTransaction());
|
|
1078
|
+
const spec = {
|
|
1079
|
+
unsignedTx,
|
|
1080
|
+
statement,
|
|
1081
|
+
outputMask: Mask.zero(),
|
|
1082
|
+
state: {
|
|
1083
|
+
resource: resourceAddress,
|
|
1084
|
+
revealedInput: null,
|
|
1085
|
+
inputsToSpend: new Map([[commitmentHex, { input: new StealthInput(commitment), owner: account }]]),
|
|
1086
|
+
outputs: [],
|
|
1087
|
+
revealedOutputAmount: revealedAmount,
|
|
1088
|
+
},
|
|
1089
|
+
requiredSigners: [account],
|
|
1090
|
+
inputs: [{ input: new StealthInput(commitment), owner: account }],
|
|
1091
|
+
};
|
|
1092
|
+
const wallet = new OotleWallet().registerKeyProvider(account, this.signer).setDefaultSigner(account);
|
|
1093
|
+
const viewSecret = await this.signer.getViewSecret();
|
|
1094
|
+
const authorized = await WalletStealthAuthorizer.fromSpec(wallet, spec, { viewSecret, crypto: new WasmStealthCrypto(this.network) }).prepare(provider);
|
|
1095
|
+
const envelope = await authorized.seal();
|
|
1096
|
+
const transactionId = await submitTransaction(provider, envelope);
|
|
1097
|
+
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the redemption transaction");
|
|
1098
|
+
await recordKnownVersions(response);
|
|
1099
|
+
return { transactionId };
|
|
1100
|
+
}
|
|
996
1101
|
/**
|
|
997
1102
|
* Funds an HTLC (hashed timelock contract): creates a stealth output for `amount` of
|
|
998
1103
|
* `resourceAddress`, gated not by a normal one-time stealth key but by a two-leaf TIP-0006
|
|
@@ -1766,16 +1871,18 @@ async function recordKnownVersions(response) {
|
|
|
1766
1871
|
const updates = new Map();
|
|
1767
1872
|
for (const [id, substate] of upSubstates)
|
|
1768
1873
|
updates.set(id, substate.version);
|
|
1769
|
-
//
|
|
1770
|
-
//
|
|
1771
|
-
//
|
|
1772
|
-
//
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1874
|
+
// No extra `serialized()` wrap needed here (and one would deadlock: `setKnownVersions` below
|
|
1875
|
+
// already serializes its own write against storage.ts's shared queue, and queuing this whole
|
|
1876
|
+
// function behind that same queue would make it wait on a write that is itself waiting for this
|
|
1877
|
+
// function to finish). `loadKnownVersions()` returns the same cached, shared Map every time
|
|
1878
|
+
// (mutated in place, never replaced), so two concurrent confirmations both mutate one object
|
|
1879
|
+
// synchronously — no read-modify-write race to protect against — and whichever of their
|
|
1880
|
+
// `setKnownVersions` writes lands last still snapshots the *fully* merged map at that point, so
|
|
1881
|
+
// nothing is lost regardless of write order.
|
|
1882
|
+
const known = await loadKnownVersions();
|
|
1883
|
+
for (const [id, version] of updates)
|
|
1884
|
+
known.set(id, version);
|
|
1885
|
+
await setKnownVersions(Object.fromEntries(known));
|
|
1779
1886
|
}
|
|
1780
1887
|
/**
|
|
1781
1888
|
* Forgets what we thought we knew about these substates' versions, after the chain has told us a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chironbuilder/ootle-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Shared TypeScript client for Tari Ootle (L2): account derivation, balances, transactions, HTLCs, and stealth/confidential transfers — the account core behind Sapient and the Tari L1 web wallet's Ootle support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|