@fairmint/canton-node-sdk 0.0.276 → 0.0.278

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.
Files changed (92) hide show
  1. package/README.md +108 -0
  2. package/build/src/da-registry/setup/steps.js +2 -1
  3. package/build/src/da-registry/setup/steps.js.map +1 -1
  4. package/build/src/da-registry/templates.d.ts +4 -0
  5. package/build/src/da-registry/templates.d.ts.map +1 -1
  6. package/build/src/da-registry/templates.js +4 -0
  7. package/build/src/da-registry/templates.js.map +1 -1
  8. package/build/src/index.d.ts +1 -0
  9. package/build/src/index.d.ts.map +1 -1
  10. package/build/src/index.js +24 -1
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/utils/external-signing/index.d.ts +1 -0
  13. package/build/src/utils/external-signing/index.d.ts.map +1 -1
  14. package/build/src/utils/external-signing/index.js +1 -0
  15. package/build/src/utils/external-signing/index.js.map +1 -1
  16. package/build/src/utils/external-signing/wallet-ownership.d.ts +69 -0
  17. package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -0
  18. package/build/src/utils/external-signing/wallet-ownership.js +179 -0
  19. package/build/src/utils/external-signing/wallet-ownership.js.map +1 -0
  20. package/build/src/utils/token-standard/v1/constants.d.ts +2 -0
  21. package/build/src/utils/token-standard/v1/constants.d.ts.map +1 -1
  22. package/build/src/utils/token-standard/v1/constants.js +3 -1
  23. package/build/src/utils/token-standard/v1/constants.js.map +1 -1
  24. package/build/src/wallets/acs.d.ts +9 -0
  25. package/build/src/wallets/acs.d.ts.map +1 -0
  26. package/build/src/wallets/acs.js +87 -0
  27. package/build/src/wallets/acs.js.map +1 -0
  28. package/build/src/wallets/cip103.d.ts +174 -0
  29. package/build/src/wallets/cip103.d.ts.map +1 -0
  30. package/build/src/wallets/cip103.js +452 -0
  31. package/build/src/wallets/cip103.js.map +1 -0
  32. package/build/src/wallets/commands.d.ts +60 -0
  33. package/build/src/wallets/commands.d.ts.map +1 -0
  34. package/build/src/wallets/commands.js +121 -0
  35. package/build/src/wallets/commands.js.map +1 -0
  36. package/build/src/wallets/contracts.d.ts +63 -0
  37. package/build/src/wallets/contracts.d.ts.map +1 -0
  38. package/build/src/wallets/contracts.js +117 -0
  39. package/build/src/wallets/contracts.js.map +1 -0
  40. package/build/src/wallets/da-utilities/client.d.ts +75 -0
  41. package/build/src/wallets/da-utilities/client.d.ts.map +1 -0
  42. package/build/src/wallets/da-utilities/client.js +238 -0
  43. package/build/src/wallets/da-utilities/client.js.map +1 -0
  44. package/build/src/wallets/decimal.d.ts +9 -0
  45. package/build/src/wallets/decimal.d.ts.map +1 -0
  46. package/build/src/wallets/decimal.js +29 -0
  47. package/build/src/wallets/decimal.js.map +1 -0
  48. package/build/src/wallets/errors.d.ts +66 -0
  49. package/build/src/wallets/errors.d.ts.map +1 -0
  50. package/build/src/wallets/errors.js +71 -0
  51. package/build/src/wallets/errors.js.map +1 -0
  52. package/build/src/wallets/holdings.d.ts +48 -0
  53. package/build/src/wallets/holdings.d.ts.map +1 -0
  54. package/build/src/wallets/holdings.js +198 -0
  55. package/build/src/wallets/holdings.js.map +1 -0
  56. package/build/src/wallets/index.d.ts +23 -0
  57. package/build/src/wallets/index.d.ts.map +1 -0
  58. package/build/src/wallets/index.js +36 -0
  59. package/build/src/wallets/index.js.map +1 -0
  60. package/build/src/wallets/instrument.d.ts +5 -0
  61. package/build/src/wallets/instrument.d.ts.map +1 -0
  62. package/build/src/wallets/instrument.js +18 -0
  63. package/build/src/wallets/instrument.js.map +1 -0
  64. package/build/src/wallets/json.d.ts +16 -0
  65. package/build/src/wallets/json.d.ts.map +1 -0
  66. package/build/src/wallets/json.js +27 -0
  67. package/build/src/wallets/json.js.map +1 -0
  68. package/build/src/wallets/ownership.d.ts +79 -0
  69. package/build/src/wallets/ownership.d.ts.map +1 -0
  70. package/build/src/wallets/ownership.js +202 -0
  71. package/build/src/wallets/ownership.js.map +1 -0
  72. package/build/src/wallets/templates.d.ts +36 -0
  73. package/build/src/wallets/templates.d.ts.map +1 -0
  74. package/build/src/wallets/templates.js +70 -0
  75. package/build/src/wallets/templates.js.map +1 -0
  76. package/build/src/wallets/token-registry.d.ts +95 -0
  77. package/build/src/wallets/token-registry.d.ts.map +1 -0
  78. package/build/src/wallets/token-registry.js +19 -0
  79. package/build/src/wallets/token-registry.js.map +1 -0
  80. package/build/src/wallets/token-standard-wallet.d.ts +146 -0
  81. package/build/src/wallets/token-standard-wallet.d.ts.map +1 -0
  82. package/build/src/wallets/token-standard-wallet.js +269 -0
  83. package/build/src/wallets/token-standard-wallet.js.map +1 -0
  84. package/build/src/wallets/token-wallet.d.ts +50 -0
  85. package/build/src/wallets/token-wallet.d.ts.map +1 -0
  86. package/build/src/wallets/token-wallet.js +175 -0
  87. package/build/src/wallets/token-wallet.js.map +1 -0
  88. package/build/src/wallets/types.d.ts +74 -0
  89. package/build/src/wallets/types.d.ts.map +1 -0
  90. package/build/src/wallets/types.js +3 -0
  91. package/build/src/wallets/types.js.map +1 -0
  92. package/package.json +1 -1
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Generic CIP-56 (token standard V1) holder actions through any CIP-0103 wallet provider and any `TokenRegistry`: list
3
+ * the registry's holdings, preview and run a transfer, and answer pending transfers. Registry-specific actions (DA's
4
+ * mint offers, burn requests and preapprovals) build on it in `token-wallet.ts`.
5
+ */
6
+ import { type Cip103Provider, type Cip103Wallet, type WalletReadRetryOptions } from './cip103';
7
+ import type { TransferOffer } from './contracts';
8
+ import { type Holding } from './holdings';
9
+ import { type ReadContracts, type TokenRegistry, type TransferKind } from './token-registry';
10
+ import type { ContractFilter, InstrumentId, SubmitResult } from './types';
11
+ /** Transfers: `executeBefore` = now + 24 h, a common wallet default. */
12
+ export declare const TRANSFER_TTL_MS: number;
13
+ /**
14
+ * `requestedAt` = now − 60 s for transfers and burn requests: registries require it in the past by ledger time, and the
15
+ * client's clock can run ahead of the participant's.
16
+ */
17
+ export declare const REQUESTED_AT_SKEW_MS: number;
18
+ export interface TokenStandardWalletOptions<R extends TokenRegistry = TokenRegistry> {
19
+ /**
20
+ * Any CIP-0103 (Canton dApp API) provider, already connected by the dApp: Loop's `loop.getCip103Provider()`, a
21
+ * `@canton-network/dapp-sdk` provider, `window.canton`, …
22
+ */
23
+ readonly provider: Cip103Provider;
24
+ /** Act as this party. Defaults to the wallet's primary account, read on every action. */
25
+ readonly partyId?: string;
26
+ readonly registry: R;
27
+ /** Defaults to the system clock. */
28
+ readonly now?: () => Date;
29
+ /** How reads back off when the wallet rate-limits them (CIP-0103 -32005). Writes are never retried. */
30
+ readonly readRetry?: WalletReadRetryOptions;
31
+ }
32
+ /** The CIP-56 state of the wallet party, read as one snapshot. */
33
+ export interface TokenStandardState {
34
+ /** The party the snapshot was read for. */
35
+ readonly partyId: string;
36
+ /** The ledger offset every list was read at. */
37
+ readonly offset: number;
38
+ /** The wallet party's holdings this registry serves, locked ones included. */
39
+ readonly holdings: Holding[];
40
+ readonly transferOffers: TransferOffers;
41
+ }
42
+ export interface TransferRequest {
43
+ readonly receiver: string;
44
+ readonly instrumentId: InstrumentId;
45
+ /** Positive decimal, at most 10 places. */
46
+ readonly amount: string;
47
+ }
48
+ export interface TransferOptions extends TransferRequest {
49
+ /** Shown to the receiver as the transfer's reason (`splice.lfdecentralizedtrust.org/reason`). */
50
+ readonly memo?: string;
51
+ /**
52
+ * Submit only if the receiver pre-approved the transfer (the registry answers `direct`). Anything else is refused
53
+ * with `preapproval-required` before signing, so no offer is ever created.
54
+ */
55
+ readonly requirePreapproval?: boolean;
56
+ /**
57
+ * The kind `previewTransfer` reported and the user confirmed. When the registry now answers another kind (a
58
+ * preapproval expired or appeared in between), the transfer is refused with `kind-changed` before signing.
59
+ */
60
+ readonly expectedKind?: TransferKind;
61
+ }
62
+ export interface TransferResult extends SubmitResult {
63
+ readonly kind: TransferKind;
64
+ }
65
+ export interface TransferOffers {
66
+ /** Offers to the wallet party, which it can accept or reject. */
67
+ readonly incoming: TransferOffer[];
68
+ /** The wallet party's own offers, which it can withdraw. */
69
+ readonly outgoing: TransferOffer[];
70
+ }
71
+ /**
72
+ * The CIP-56 actions on one registry's instruments. One write action at a time: a write started while another is in
73
+ * progress (from its first read to its submission's outcome) is refused at once with `busy`, so two writes never pick
74
+ * the same holdings. Reads and previews are not limited.
75
+ *
76
+ * Reads: `loadState` and the `list*` methods all read one snapshot (one ledger-end call and one paged ACS stream with
77
+ * every filter the wallet needs; a registry that declares no `pendingTransferFilters` costs one more ACS stream, read
78
+ * at the same offset), and calls made while a snapshot is in flight share it instead of reading again, unless a write
79
+ * settled since it started. Load a page with `loadState`; writes do their own fresh reads.
80
+ */
81
+ export interface TokenStandardWallet {
82
+ /** The party every action reads and acts as. */
83
+ partyId(): Promise<string>;
84
+ /** Holdings and transfer offers, from one snapshot. */
85
+ loadState(): Promise<TokenStandardState>;
86
+ /** The wallet party's holdings this registry serves, locked ones included (`locked: true`). */
87
+ listHoldings(): Promise<Holding[]>;
88
+ /** How the registry would run this transfer, without submitting it. */
89
+ previewTransfer(request: TransferRequest): Promise<TransferKind>;
90
+ transfer(options: TransferOptions): Promise<TransferResult>;
91
+ listTransferOffers(): Promise<TransferOffers>;
92
+ acceptTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
93
+ rejectTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
94
+ withdrawTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
95
+ }
96
+ export declare function requireNonEmpty(value: string, field: string): string;
97
+ /** Milliseconds of a caller's `Date`; `invalid-input` for an invalid one (NaN), which `toISOString` would throw on. */
98
+ export declare function requireTime(date: Date, field: string): number;
99
+ /** ISO-8601 of a time in milliseconds; `invalid-input` when it is outside the `Date` range. */
100
+ export declare function isoTime(ms: number, field: string): string;
101
+ export declare function requireInstrumentId(instrumentId: InstrumentId): InstrumentId;
102
+ /** One state snapshot of the wallet party. */
103
+ export interface StateSnapshot {
104
+ readonly wallet: Cip103Wallet;
105
+ readonly offset: number;
106
+ /** The wallet party's holdings the registry serves, selected from the snapshot as a write's fresh read selects them. */
107
+ readonly holdings: Holding[];
108
+ /**
109
+ * Serves the snapshot's own filters from the snapshot; any other filter is read from the wallet at the snapshot's
110
+ * offset (once per filter), so every list read through it belongs to the same snapshot.
111
+ */
112
+ readonly read: ReadContracts;
113
+ }
114
+ /** What a registry-specific extension builds on: the wallet as the current party, its holdings, the write guard. */
115
+ export interface TokenStandardCore {
116
+ readonly api: TokenStandardWallet;
117
+ /** The clock in milliseconds; `invalid-input` when it gives an invalid `Date`. */
118
+ readonly now: () => number;
119
+ /** The wallet as the current party: resolved per action, so an account switch in the wallet is followed. */
120
+ readonly connect: () => Promise<Cip103Wallet>;
121
+ /** The party's unlocked and locked holdings that the registry serves, freshly read (for writes). */
122
+ readonly holdingsOf: (wallet: Cip103Wallet) => Promise<Holding[]>;
123
+ /**
124
+ * One snapshot of every state filter (holdings, the registry's pending transfers and the extension's own filters).
125
+ * Concurrent calls for the same party share the snapshot in flight unless a write settled since it started.
126
+ */
127
+ readonly snapshot: () => Promise<StateSnapshot>;
128
+ /** The CIP-56 state in a snapshot. */
129
+ readonly stateOf: (snapshot: StateSnapshot) => Promise<TokenStandardState>;
130
+ /**
131
+ * Run a write action alone: refused with `busy` (before `action` starts) while another write of this token wallet is
132
+ * in progress, and released when `action` settles, whether it succeeded or failed.
133
+ */
134
+ readonly exclusive: <T>(action: () => Promise<T>) => Promise<T>;
135
+ }
136
+ /**
137
+ * The generic CIP-56 core; `createTokenWallet` adds DA's actions on top of it, and its own filters to the state
138
+ * snapshot through `extraStateFilters`.
139
+ */
140
+ export declare function tokenStandardCore(options: TokenStandardWalletOptions, extraStateFilters?: readonly ContractFilter[]): TokenStandardCore;
141
+ /**
142
+ * CIP-56 holder actions on the instruments of any `TokenRegistry` through a CIP-0103 provider. For DA Utility Registry
143
+ * instruments use `createTokenWallet`, which adds DA's mint, burn and preapproval actions.
144
+ */
145
+ export declare function createTokenStandardWallet(options: TokenStandardWalletOptions): TokenStandardWallet;
146
+ //# sourceMappingURL=token-standard-wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-standard-wallet.d.ts","sourceRoot":"","sources":["../../../src/wallets/token-standard-wallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC5B,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAMxE,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGlB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAkB,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1F,wEAAwE;AACxE,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAiB,CAAC;AAEnD,MAAM,WAAW,0BAA0B,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa;IACjF;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,yFAAyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrB,oCAAoC;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,uGAAuG;IACvG,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CAC7C;AAED,kEAAkE;AAClE,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC7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Q,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3E;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACjE;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,0BAA0B,EACnC,iBAAiB,GAAE,SAAS,cAAc,EAAO,GAChD,iBAAiB,CAmOnB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CAElG"}
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REQUESTED_AT_SKEW_MS = exports.TRANSFER_TTL_MS = void 0;
4
+ exports.requireNonEmpty = requireNonEmpty;
5
+ exports.requireTime = requireTime;
6
+ exports.isoTime = isoTime;
7
+ exports.requireInstrumentId = requireInstrumentId;
8
+ exports.tokenStandardCore = tokenStandardCore;
9
+ exports.createTokenStandardWallet = createTokenStandardWallet;
10
+ /**
11
+ * Generic CIP-56 (token standard V1) holder actions through any CIP-0103 wallet provider and any `TokenRegistry`: list
12
+ * the registry's holdings, preview and run a transfer, and answer pending transfers. Registry-specific actions (DA's
13
+ * mint offers, burn requests and preapprovals) build on it in `token-wallet.ts`.
14
+ */
15
+ const cip103_1 = require("./cip103");
16
+ const commands_1 = require("./commands");
17
+ const errors_1 = require("./errors");
18
+ const holdings_1 = require("./holdings");
19
+ const constants_1 = require("../utils/token-standard/v1/constants");
20
+ const templates_1 = require("./templates");
21
+ const token_registry_1 = require("./token-registry");
22
+ const SECOND_MS = 1000;
23
+ const DAY_MS = 24 * 60 * 60 * SECOND_MS;
24
+ /** Transfers: `executeBefore` = now + 24 h, a common wallet default. */
25
+ exports.TRANSFER_TTL_MS = DAY_MS;
26
+ /**
27
+ * `requestedAt` = now − 60 s for transfers and burn requests: registries require it in the past by ledger time, and the
28
+ * client's clock can run ahead of the participant's.
29
+ */
30
+ exports.REQUESTED_AT_SKEW_MS = 60 * SECOND_MS;
31
+ function requireNonEmpty(value, field) {
32
+ if (value.trim().length === 0) {
33
+ throw new errors_1.TokenWalletError('invalid-input', `${field} is required`);
34
+ }
35
+ return value;
36
+ }
37
+ /** Milliseconds of a caller's `Date`; `invalid-input` for an invalid one (NaN), which `toISOString` would throw on. */
38
+ function requireTime(date, field) {
39
+ const ms = date instanceof Date ? date.getTime() : Number.NaN;
40
+ if (!Number.isFinite(ms)) {
41
+ throw new errors_1.TokenWalletError('invalid-input', `${field} is not a valid time`);
42
+ }
43
+ return ms;
44
+ }
45
+ /** ISO-8601 of a time in milliseconds; `invalid-input` when it is outside the `Date` range. */
46
+ function isoTime(ms, field) {
47
+ return new Date(requireTime(new Date(ms), field)).toISOString();
48
+ }
49
+ function requireInstrumentId(instrumentId) {
50
+ return {
51
+ admin: requireNonEmpty(instrumentId.admin, 'instrumentId.admin'),
52
+ id: requireNonEmpty(instrumentId.id, 'instrumentId.id'),
53
+ };
54
+ }
55
+ const HOLDING_FILTER = { interfaceId: constants_1.TOKEN_STANDARD_V1_HOLDING_INTERFACE_ID };
56
+ /**
57
+ * The generic CIP-56 core; `createTokenWallet` adds DA's actions on top of it, and its own filters to the state
58
+ * snapshot through `extraStateFilters`.
59
+ */
60
+ function tokenStandardCore(options, extraStateFilters = []) {
61
+ const { provider, registry } = options;
62
+ const clock = options.now ?? (() => new Date());
63
+ const now = () => requireTime(clock(), 'now()');
64
+ if (options.partyId !== undefined)
65
+ requireNonEmpty(options.partyId, 'partyId');
66
+ async function partyId() {
67
+ return options.partyId ?? (0, cip103_1.primaryPartyId)(provider);
68
+ }
69
+ const walletOptions = options.readRetry !== undefined ? { readRetry: options.readRetry } : {};
70
+ async function connect() {
71
+ return (0, cip103_1.cip103Wallet)(provider, await partyId(), walletOptions);
72
+ }
73
+ // Checked and taken synchronously (before the first await), so a second write started in the same tick is refused
74
+ // and two writes never select the same holdings.
75
+ let busy = false;
76
+ // Bumped when a write settles: a snapshot started before then may predate the write, so later reads do not join it.
77
+ let writesSettled = 0;
78
+ async function exclusive(action) {
79
+ if (busy) {
80
+ throw new errors_1.TokenWalletError('busy', 'Another wallet action is in progress; nothing was submitted');
81
+ }
82
+ busy = true;
83
+ try {
84
+ return await action();
85
+ }
86
+ finally {
87
+ busy = false;
88
+ writesSettled += 1;
89
+ }
90
+ }
91
+ /**
92
+ * The validated holdings among `contracts`: of the registry (`servesHolding`, which checks template and signatories),
93
+ * readable by `parseHolding` (HoldingV1 view, else the create argument) and owned by `owner`. Writes and the snapshot
94
+ * both select holdings with this alone, over the same holding filters, so they see the same holdings: whatever passes
95
+ * implements HoldingV1 or is of one of the registry's holding templates, so a holding-filter read returns it too.
96
+ * (Matching the snapshot by filter instead would drop a holding whose HoldingV1 view the ledger failed to compute.)
97
+ */
98
+ function holdingsIn(owner, contracts) {
99
+ return contracts.flatMap((contract) => {
100
+ if (!registry.servesHolding(contract))
101
+ return [];
102
+ const holding = (0, holdings_1.parseHolding)(contract);
103
+ return holding !== null && holding.owner === owner ? [holding] : [];
104
+ });
105
+ }
106
+ const holdingFilters = [HOLDING_FILTER, ...(registry.holdingFilters ?? [])];
107
+ async function holdingsOf(wallet) {
108
+ return holdingsIn(wallet.partyId, (await wallet.readActiveContracts(holdingFilters)).contracts);
109
+ }
110
+ const stateFilters = [
111
+ ...holdingFilters,
112
+ ...(registry.pendingTransferFilters ?? []),
113
+ ...extraStateFilters,
114
+ ];
115
+ const stateFilterKeys = new Set(stateFilters.map(templates_1.contractFilterKey));
116
+ async function takeSnapshot(party) {
117
+ const wallet = (0, cip103_1.cip103Wallet)(provider, party, walletOptions);
118
+ const { offset, contracts } = await wallet.readActiveContracts(stateFilters);
119
+ // A filter the snapshot did not carry (a registry without `pendingTransferFilters`) is read at the snapshot's
120
+ // offset, not at a new ledger end, and once per snapshot however many lists ask for it.
121
+ const extraReads = new Map();
122
+ const read = async (filter) => {
123
+ const key = (0, templates_1.contractFilterKey)(filter);
124
+ if (stateFilterKeys.has(key))
125
+ return contracts.filter((contract) => (0, templates_1.contractMatchesFilter)(contract, filter));
126
+ let pending = extraReads.get(key);
127
+ if (pending === undefined) {
128
+ pending = wallet.listActiveContracts(filter, { activeAtOffset: offset });
129
+ extraReads.set(key, pending);
130
+ // A failed read is not kept, so a later list of the same snapshot tries again.
131
+ pending.catch(() => {
132
+ if (extraReads.get(key) === pending)
133
+ extraReads.delete(key);
134
+ });
135
+ }
136
+ return [...(await pending)];
137
+ };
138
+ return { wallet, offset, holdings: holdingsIn(party, contracts), read };
139
+ }
140
+ // Keyed by party as well: without a pinned `partyId`, a read after an account switch must not join the previous
141
+ // party's snapshot.
142
+ let inFlight;
143
+ async function snapshot() {
144
+ const party = await partyId();
145
+ const settled = writesSettled;
146
+ if (inFlight?.writesSettled === settled && inFlight.party === party)
147
+ return inFlight.promise;
148
+ const promise = takeSnapshot(party).finally(() => {
149
+ if (inFlight?.promise === promise)
150
+ inFlight = undefined;
151
+ });
152
+ inFlight = { writesSettled: settled, party, promise };
153
+ return promise;
154
+ }
155
+ async function stateOf(taken) {
156
+ return {
157
+ partyId: taken.wallet.partyId,
158
+ offset: taken.offset,
159
+ holdings: [...taken.holdings],
160
+ transferOffers: await transferOffersOf(taken.wallet.partyId, taken.read),
161
+ };
162
+ }
163
+ /** Select inputs and ask the registry for the factory; the factory must be an expected, disclosed template. */
164
+ async function prepareTransfer(wallet, request) {
165
+ const instrumentId = requireInstrumentId(request.instrumentId);
166
+ const receiver = requireNonEmpty(request.receiver, 'receiver');
167
+ const selection = (0, holdings_1.selectHoldings)(await holdingsOf(wallet), {
168
+ owner: wallet.partyId,
169
+ instrumentId,
170
+ amount: request.amount,
171
+ });
172
+ const at = now();
173
+ const transfer = {
174
+ sender: wallet.partyId,
175
+ receiver,
176
+ amount: selection.amount,
177
+ instrumentId,
178
+ requestedAt: isoTime(at - exports.REQUESTED_AT_SKEW_MS, 'requestedAt'),
179
+ executeBefore: isoTime(at + exports.TRANSFER_TTL_MS, 'executeBefore'),
180
+ inputHoldingCids: selection.inputHoldingCids,
181
+ meta: {
182
+ values: request.memo !== undefined && request.memo.length > 0
183
+ ? { [constants_1.TOKEN_STANDARD_V1_REASON_META_KEY]: request.memo }
184
+ : {},
185
+ },
186
+ };
187
+ const factory = await registry.transferFactory({
188
+ expectedAdmin: instrumentId.admin,
189
+ transfer,
190
+ });
191
+ const factoryError = (0, token_registry_1.factoryTemplateError)(factory, registry.expectedTransferFactoryTemplates);
192
+ if (factoryError !== null)
193
+ throw new errors_1.RegistryResponseError(factoryError);
194
+ return { transfer, factory };
195
+ }
196
+ async function runTransfer(request) {
197
+ const wallet = await connect();
198
+ const { transfer: spec, factory } = await prepareTransfer(wallet, request);
199
+ const kind = factory.transferKind;
200
+ if (request.requirePreapproval === true && kind !== 'direct') {
201
+ throw new errors_1.TokenWalletError('preapproval-required', `The receiver has no matching transfer preapproval (the registry would make a${kind === 'offer' ? 'n offer' : ` ${kind} transfer`}); nothing was submitted`);
202
+ }
203
+ if (request.expectedKind !== undefined && kind !== request.expectedKind) {
204
+ throw new errors_1.TokenWalletError('kind-changed', `The registry would now make a${kind === 'offer' ? 'n' : ''} ${kind} transfer, not the previewed ${request.expectedKind}; nothing was submitted`);
205
+ }
206
+ const result = await wallet.submit({
207
+ commands: [
208
+ (0, commands_1.transferCommand)({
209
+ factoryId: factory.factoryId,
210
+ expectedAdmin: spec.instrumentId.admin,
211
+ transfer: spec,
212
+ context: factory.choiceContextData,
213
+ }),
214
+ ],
215
+ disclosedContracts: factory.disclosedContracts,
216
+ });
217
+ return { kind, ...result };
218
+ }
219
+ async function transferOffersOf(party, read) {
220
+ const offers = await registry.pendingTransfers(read);
221
+ return {
222
+ incoming: offers.filter((o) => o.receiver === party && o.sender !== party),
223
+ outgoing: offers.filter((o) => o.sender === party),
224
+ };
225
+ }
226
+ async function runAnswerTransferOffer(transferOfferCid, action) {
227
+ const wallet = await connect();
228
+ const { incoming, outgoing } = await transferOffersOf(wallet.partyId, async (filter) => wallet.listActiveContracts(filter));
229
+ const offer = (action === 'withdraw' ? outgoing : incoming).find((o) => o.contractId === transferOfferCid);
230
+ if (!offer) {
231
+ throw new errors_1.TokenWalletError('not-found', `Transfer offer ${transferOfferCid} is not among the wallet's ${action === 'withdraw' ? 'outgoing' : 'incoming'} offers`);
232
+ }
233
+ const context = await registry.transferInstructionContext(offer.instrumentId.admin, transferOfferCid, action);
234
+ return wallet.submit({
235
+ commands: [(0, commands_1.transferInstructionCommand)(transferOfferCid, action, context.choiceContextData)],
236
+ disclosedContracts: context.disclosedContracts,
237
+ });
238
+ }
239
+ return {
240
+ now,
241
+ connect,
242
+ holdingsOf,
243
+ exclusive,
244
+ snapshot,
245
+ stateOf,
246
+ api: {
247
+ partyId,
248
+ loadState: async () => stateOf(await snapshot()),
249
+ listHoldings: async () => [...(await snapshot()).holdings],
250
+ previewTransfer: async (request) => (await prepareTransfer(await connect(), request)).factory.transferKind,
251
+ transfer: async (request) => exclusive(async () => runTransfer(request)),
252
+ listTransferOffers: async () => {
253
+ const taken = await snapshot();
254
+ return transferOffersOf(taken.wallet.partyId, taken.read);
255
+ },
256
+ acceptTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'accept')),
257
+ rejectTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'reject')),
258
+ withdrawTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'withdraw')),
259
+ },
260
+ };
261
+ }
262
+ /**
263
+ * CIP-56 holder actions on the instruments of any `TokenRegistry` through a CIP-0103 provider. For DA Utility Registry
264
+ * instruments use `createTokenWallet`, which adds DA's mint, burn and preapproval actions.
265
+ */
266
+ function createTokenStandardWallet(options) {
267
+ return tokenStandardCore(options).api;
268
+ }
269
+ //# sourceMappingURL=token-standard-wallet.js.map
@@ -0,0 +1 @@
1
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0,0 +1,50 @@
1
+ import { type BurnRequest, type MintOffer } from './contracts';
2
+ import { type DaUtilitiesClient } from './da-utilities/client';
3
+ import { type TokenStandardState, type TokenStandardWallet, type TokenStandardWalletOptions } from './token-standard-wallet';
4
+ import type { InstrumentId, SubmitResult } from './types';
5
+ /** Burn requests: `executeBefore` defaults to now + 7 days, giving the registrar a week to accept or reject. */
6
+ export declare const BURN_TTL_MS: number;
7
+ /** A burn reference: no personal data (DA's operator and the registrar see it). */
8
+ export declare const BURN_REFERENCE_PATTERN: RegExp;
9
+ export type TokenWalletOptions = TokenStandardWalletOptions<DaUtilitiesClient>;
10
+ export interface BurnRequestOptions {
11
+ readonly instrumentId: InstrumentId;
12
+ readonly amount: string;
13
+ /** Matches {@link BURN_REFERENCE_PATTERN}; never personal data. */
14
+ readonly reference: string;
15
+ /** Defaults to now + 7 days. */
16
+ readonly executeBefore?: Date;
17
+ }
18
+ /** Everything a token wallet page shows, read as one snapshot of the ledger. */
19
+ export interface TokenWalletState extends TokenStandardState {
20
+ readonly mintOffers: MintOffer[];
21
+ readonly burnRequests: BurnRequest[];
22
+ }
23
+ export interface TokenWallet extends TokenStandardWallet {
24
+ /**
25
+ * Holdings, transfer offers, mint offers and burn requests from one snapshot: one ledger-end call and one paged ACS
26
+ * stream for all four. Load a page with this rather than the four `list*` calls (which share one snapshot when called
27
+ * together, but each still filters it).
28
+ */
29
+ loadState(): Promise<TokenWalletState>;
30
+ /** Mint offers to the wallet party, made under their instrument admin's registry service. */
31
+ listMintOffers(): Promise<MintOffer[]>;
32
+ acceptMintOffer(mintOfferCid: string, options?: {
33
+ expectedRegistrar?: string;
34
+ }): Promise<SubmitResult>;
35
+ /** File a burn (redemption) request; DA locks the amount until the registrar accepts or rejects it. */
36
+ requestBurn(options: BurnRequestOptions): Promise<SubmitResult>;
37
+ /**
38
+ * Experimental: create the wallet party's DA transfer preapproval for an instrument admin (every instrument of the
39
+ * admin when `instrumentIds` is empty or omitted, else up to 10). No live create has been observed yet.
40
+ */
41
+ createTransferPreapproval(options: {
42
+ instrumentAdmin: string;
43
+ instrumentIds?: readonly string[];
44
+ }): Promise<SubmitResult>;
45
+ /** The wallet party's open burn requests (pending redemptions). */
46
+ listBurnRequests(): Promise<BurnRequest[]>;
47
+ }
48
+ /** A `TokenWallet` over a CIP-0103 provider, using DA's Utilities API for choice contexts. */
49
+ export declare function createTokenWallet(options: TokenWalletOptions): TokenWallet;
50
+ //# sourceMappingURL=token-wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-wallet.d.ts","sourceRoot":"","sources":["../../../src/wallets/token-wallet.ts"],"names":[],"mappings":"AAeA,OAAO,EAAoD,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACjH,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAK1F,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAChC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAkC,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1F,gHAAgH;AAChH,eAAO,MAAM,WAAW,QAAa,CAAC;AACtC,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,QAAuC,CAAC;AAE3E,MAAM,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;AAE/E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC;CAC/B;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC;IACjC,QA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