@fairmint/canton-node-sdk 0.0.276 → 0.0.277
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 +45 -0
- package/build/src/da-registry/setup/steps.js +2 -1
- package/build/src/da-registry/setup/steps.js.map +1 -1
- package/build/src/da-registry/templates.d.ts +4 -0
- package/build/src/da-registry/templates.d.ts.map +1 -1
- package/build/src/da-registry/templates.js +4 -0
- package/build/src/da-registry/templates.js.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +24 -1
- package/build/src/index.js.map +1 -1
- package/build/src/utils/token-standard/v1/constants.d.ts +2 -0
- package/build/src/utils/token-standard/v1/constants.d.ts.map +1 -1
- package/build/src/utils/token-standard/v1/constants.js +3 -1
- package/build/src/utils/token-standard/v1/constants.js.map +1 -1
- package/build/src/wallets/acs.d.ts +9 -0
- package/build/src/wallets/acs.d.ts.map +1 -0
- package/build/src/wallets/acs.js +87 -0
- package/build/src/wallets/acs.js.map +1 -0
- package/build/src/wallets/cip103.d.ts +96 -0
- package/build/src/wallets/cip103.d.ts.map +1 -0
- package/build/src/wallets/cip103.js +330 -0
- package/build/src/wallets/cip103.js.map +1 -0
- package/build/src/wallets/commands.d.ts +60 -0
- package/build/src/wallets/commands.d.ts.map +1 -0
- package/build/src/wallets/commands.js +121 -0
- package/build/src/wallets/commands.js.map +1 -0
- package/build/src/wallets/contracts.d.ts +63 -0
- package/build/src/wallets/contracts.d.ts.map +1 -0
- package/build/src/wallets/contracts.js +117 -0
- package/build/src/wallets/contracts.js.map +1 -0
- package/build/src/wallets/da-utilities/client.d.ts +75 -0
- package/build/src/wallets/da-utilities/client.d.ts.map +1 -0
- package/build/src/wallets/da-utilities/client.js +235 -0
- package/build/src/wallets/da-utilities/client.js.map +1 -0
- package/build/src/wallets/decimal.d.ts +9 -0
- package/build/src/wallets/decimal.d.ts.map +1 -0
- package/build/src/wallets/decimal.js +29 -0
- package/build/src/wallets/decimal.js.map +1 -0
- package/build/src/wallets/errors.d.ts +48 -0
- package/build/src/wallets/errors.d.ts.map +1 -0
- package/build/src/wallets/errors.js +57 -0
- package/build/src/wallets/errors.js.map +1 -0
- package/build/src/wallets/holdings.d.ts +48 -0
- package/build/src/wallets/holdings.d.ts.map +1 -0
- package/build/src/wallets/holdings.js +198 -0
- package/build/src/wallets/holdings.js.map +1 -0
- package/build/src/wallets/index.d.ts +20 -0
- package/build/src/wallets/index.d.ts.map +1 -0
- package/build/src/wallets/index.js +29 -0
- package/build/src/wallets/index.js.map +1 -0
- package/build/src/wallets/instrument.d.ts +5 -0
- package/build/src/wallets/instrument.d.ts.map +1 -0
- package/build/src/wallets/instrument.js +18 -0
- package/build/src/wallets/instrument.js.map +1 -0
- package/build/src/wallets/json.d.ts +16 -0
- package/build/src/wallets/json.d.ts.map +1 -0
- package/build/src/wallets/json.js +27 -0
- package/build/src/wallets/json.js.map +1 -0
- package/build/src/wallets/templates.d.ts +21 -0
- package/build/src/wallets/templates.d.ts.map +1 -0
- package/build/src/wallets/templates.js +46 -0
- package/build/src/wallets/templates.js.map +1 -0
- package/build/src/wallets/token-registry.d.ts +84 -0
- package/build/src/wallets/token-registry.d.ts.map +1 -0
- package/build/src/wallets/token-registry.js +19 -0
- package/build/src/wallets/token-registry.js.map +1 -0
- package/build/src/wallets/token-standard-wallet.d.ts +105 -0
- package/build/src/wallets/token-standard-wallet.d.ts.map +1 -0
- package/build/src/wallets/token-standard-wallet.js +193 -0
- package/build/src/wallets/token-standard-wallet.js.map +1 -0
- package/build/src/wallets/token-wallet.d.ts +39 -0
- package/build/src/wallets/token-wallet.d.ts.map +1 -0
- package/build/src/wallets/token-wallet.js +165 -0
- package/build/src/wallets/token-wallet.js.map +1 -0
- package/build/src/wallets/types.d.ts +74 -0
- package/build/src/wallets/types.d.ts.map +1 -0
- package/build/src/wallets/types.js +3 -0
- package/build/src/wallets/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CIP-56 (token standard V1) registry seam: what a transfer, or an answer to a pending transfer, needs from the
|
|
3
|
+
* instrument's registry off ledger. DA's Utility Registry implements it today (`createDaUtilitiesClient`); another
|
|
4
|
+
* registry (for example Canton Coin) is a new implementation of this interface.
|
|
5
|
+
*/
|
|
6
|
+
import type { TransferOffer } from './contracts';
|
|
7
|
+
import type { JsonObject } from './json';
|
|
8
|
+
import type { ActiveContract, ContractFilter, DisclosedContract, InstrumentId } from './types';
|
|
9
|
+
/** Splice `ChoiceContext` data: passed through unchanged as `extraArgs.context`. */
|
|
10
|
+
export interface ChoiceContextData {
|
|
11
|
+
readonly values: JsonObject;
|
|
12
|
+
}
|
|
13
|
+
/** What the registry returns for a choice: its context, and the contracts to disclose with the submission. */
|
|
14
|
+
export interface ChoiceContext {
|
|
15
|
+
readonly choiceContextData: ChoiceContextData;
|
|
16
|
+
readonly disclosedContracts: readonly DisclosedContract[];
|
|
17
|
+
}
|
|
18
|
+
/** A factory to exercise, with its choice context. */
|
|
19
|
+
export interface FactoryWithChoiceContext extends ChoiceContext {
|
|
20
|
+
readonly factoryId: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* How the registry will run a transfer:
|
|
24
|
+
*
|
|
25
|
+
* - `offer`: a pending transfer the receiver must accept;
|
|
26
|
+
* - `direct`: the receiver pre-approved transfers, so the holdings move at once;
|
|
27
|
+
* - `self`: sender and receiver are the same party.
|
|
28
|
+
*/
|
|
29
|
+
export type TransferKind = 'offer' | 'direct' | 'self';
|
|
30
|
+
export interface TransferFactory extends FactoryWithChoiceContext {
|
|
31
|
+
readonly transferKind: TransferKind;
|
|
32
|
+
}
|
|
33
|
+
/** The CIP-56 `Transfer` record. */
|
|
34
|
+
export interface TransferSpec {
|
|
35
|
+
readonly sender: string;
|
|
36
|
+
readonly receiver: string;
|
|
37
|
+
/** Decimal string. */
|
|
38
|
+
readonly amount: string;
|
|
39
|
+
readonly instrumentId: InstrumentId;
|
|
40
|
+
/** ISO-8601. */
|
|
41
|
+
readonly requestedAt: string;
|
|
42
|
+
/** ISO-8601. */
|
|
43
|
+
readonly executeBefore: string;
|
|
44
|
+
readonly inputHoldingCids: readonly string[];
|
|
45
|
+
readonly meta: {
|
|
46
|
+
readonly values: Readonly<Record<string, string>>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface TransferFactoryArgs {
|
|
50
|
+
readonly expectedAdmin: string;
|
|
51
|
+
readonly transfer: TransferSpec;
|
|
52
|
+
}
|
|
53
|
+
/** An action on a pending transfer: the receiver accepts or rejects, the sender withdraws. */
|
|
54
|
+
export type TransferInstructionAction = 'accept' | 'reject' | 'withdraw';
|
|
55
|
+
/** Reads the wallet party's active contracts matching a filter (the wallet's own ACS). */
|
|
56
|
+
export type ReadContracts = (filter: ContractFilter) => Promise<ActiveContract[]>;
|
|
57
|
+
export interface TokenRegistry {
|
|
58
|
+
/**
|
|
59
|
+
* Whether a holding read through the CIP-56 HoldingV1 interface is one of this registry's, and genuine: of its
|
|
60
|
+
* template and signed by the party that issues it (any party can create a look-alike with the wallet party as
|
|
61
|
+
* observer). A wallet also holds other registries' holdings (Canton Coin, other registries' tokens); the token wallet
|
|
62
|
+
* lists and spends only the ones this returns true for.
|
|
63
|
+
*/
|
|
64
|
+
servesHolding(contract: ActiveContract): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* This registry's pending transfers (CIP-56 TransferInstructions) visible to the wallet, read through `read` and
|
|
67
|
+
* checked to be genuine (made by the registry, not a look-alike any party could create). Both directions: the caller
|
|
68
|
+
* splits them by sender and receiver.
|
|
69
|
+
*/
|
|
70
|
+
pendingTransfers(read: ReadContracts): Promise<TransferOffer[]>;
|
|
71
|
+
/**
|
|
72
|
+
* `Module:Entity` names of the templates this registry's transfer factory may have. A factory of any other template
|
|
73
|
+
* is refused before anything is signed.
|
|
74
|
+
*/
|
|
75
|
+
readonly expectedTransferFactoryTemplates: readonly string[];
|
|
76
|
+
transferFactory(args: TransferFactoryArgs): Promise<TransferFactory>;
|
|
77
|
+
transferInstructionContext(registrar: string, instructionCid: string, action: TransferInstructionAction): Promise<ChoiceContext>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
|
|
81
|
+
* that names any other contract is refused before anything is signed.
|
|
82
|
+
*/
|
|
83
|
+
export declare function factoryTemplateError(factory: FactoryWithChoiceContext, expectedTemplates: readonly string[]): string | null;
|
|
84
|
+
//# sourceMappingURL=token-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-registry.d.ts","sourceRoot":"","sources":["../../../src/wallets/token-registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/F,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AAED,8GAA8G;AAC9G,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC9C,QAAQ,CAAC,kBAAkB,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC3D;AAED,sDAAsD;AACtD,MAAM,WAAW,wBAAyB,SAAQ,aAAa;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,eAAgB,SAAQ,wBAAwB;IAC/D,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;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AAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,wBAAwB,EACjC,iBAAiB,EAAE,SAAS,MAAM,EAAE,GACnC,MAAM,GAAG,IAAI,CASf"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.factoryTemplateError = factoryTemplateError;
|
|
4
|
+
const templates_1 = require("./templates");
|
|
5
|
+
/**
|
|
6
|
+
* Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
|
|
7
|
+
* that names any other contract is refused before anything is signed.
|
|
8
|
+
*/
|
|
9
|
+
function factoryTemplateError(factory, expectedTemplates) {
|
|
10
|
+
const disclosed = factory.disclosedContracts.find((contract) => contract.contractId === factory.factoryId);
|
|
11
|
+
if (!disclosed) {
|
|
12
|
+
return 'The registry named a factory it did not disclose.';
|
|
13
|
+
}
|
|
14
|
+
const name = (0, templates_1.qualifiedName)(disclosed.templateId);
|
|
15
|
+
return name !== null && expectedTemplates.includes(name)
|
|
16
|
+
? null
|
|
17
|
+
: `The registry named a factory of an unexpected template (${disclosed.templateId}).`;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=token-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-registry.js","sourceRoot":"","sources":["../../../src/wallets/token-registry.ts"],"names":[],"mappings":";;;AAOA,2CAA4C;AAqF5C;;;GAGG;AACH,8BACE,OAAiC,EACjC,iBAAoC;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3G,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,mDAAmD,CAAC;IAC7D,CAAC;IACD,MAAM,IAAI,GAAG,IAAA,yBAAa,EAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACjD,OAAO,IAAI,KAAK,IAAI,IAAI,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtD,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,2DAA2D,SAAS,CAAC,UAAU,IAAI,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 } from './cip103';
|
|
7
|
+
import type { TransferOffer } from './contracts';
|
|
8
|
+
import { type Holding } from './holdings';
|
|
9
|
+
import { type TokenRegistry, type TransferKind } from './token-registry';
|
|
10
|
+
import type { 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
|
+
}
|
|
30
|
+
export interface TransferRequest {
|
|
31
|
+
readonly receiver: string;
|
|
32
|
+
readonly instrumentId: InstrumentId;
|
|
33
|
+
/** Positive decimal, at most 10 places. */
|
|
34
|
+
readonly amount: string;
|
|
35
|
+
}
|
|
36
|
+
export interface TransferOptions extends TransferRequest {
|
|
37
|
+
/** Shown to the receiver as the transfer's reason (`splice.lfdecentralizedtrust.org/reason`). */
|
|
38
|
+
readonly memo?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Submit only if the receiver pre-approved the transfer (the registry answers `direct`). Anything else is refused
|
|
41
|
+
* with `preapproval-required` before signing, so no offer is ever created.
|
|
42
|
+
*/
|
|
43
|
+
readonly requirePreapproval?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The kind `previewTransfer` reported and the user confirmed. When the registry now answers another kind (a
|
|
46
|
+
* preapproval expired or appeared in between), the transfer is refused with `kind-changed` before signing.
|
|
47
|
+
*/
|
|
48
|
+
readonly expectedKind?: TransferKind;
|
|
49
|
+
}
|
|
50
|
+
export interface TransferResult extends SubmitResult {
|
|
51
|
+
readonly kind: TransferKind;
|
|
52
|
+
}
|
|
53
|
+
export interface TransferOffers {
|
|
54
|
+
/** Offers to the wallet party, which it can accept or reject. */
|
|
55
|
+
readonly incoming: TransferOffer[];
|
|
56
|
+
/** The wallet party's own offers, which it can withdraw. */
|
|
57
|
+
readonly outgoing: TransferOffer[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The CIP-56 actions on one registry's instruments. One write action at a time: a write started while another is in
|
|
61
|
+
* progress (from its first read to its submission's outcome) is refused at once with `busy`, so two writes never pick
|
|
62
|
+
* the same holdings. Reads and previews are not limited.
|
|
63
|
+
*/
|
|
64
|
+
export interface TokenStandardWallet {
|
|
65
|
+
/** The party every action reads and acts as. */
|
|
66
|
+
partyId(): Promise<string>;
|
|
67
|
+
/** The wallet party's holdings this registry serves, locked ones included (`locked: true`). */
|
|
68
|
+
listHoldings(): Promise<Holding[]>;
|
|
69
|
+
/** How the registry would run this transfer, without submitting it. */
|
|
70
|
+
previewTransfer(request: TransferRequest): Promise<TransferKind>;
|
|
71
|
+
transfer(options: TransferOptions): Promise<TransferResult>;
|
|
72
|
+
listTransferOffers(): Promise<TransferOffers>;
|
|
73
|
+
acceptTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
|
|
74
|
+
rejectTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
|
|
75
|
+
withdrawTransferOffer(transferOfferCid: string): Promise<SubmitResult>;
|
|
76
|
+
}
|
|
77
|
+
export declare function requireNonEmpty(value: string, field: string): string;
|
|
78
|
+
/** Milliseconds of a caller's `Date`; `invalid-input` for an invalid one (NaN), which `toISOString` would throw on. */
|
|
79
|
+
export declare function requireTime(date: Date, field: string): number;
|
|
80
|
+
/** ISO-8601 of a time in milliseconds; `invalid-input` when it is outside the `Date` range. */
|
|
81
|
+
export declare function isoTime(ms: number, field: string): string;
|
|
82
|
+
export declare function requireInstrumentId(instrumentId: InstrumentId): InstrumentId;
|
|
83
|
+
/** What a registry-specific extension builds on: the wallet as the current party, its holdings, the write guard. */
|
|
84
|
+
export interface TokenStandardCore {
|
|
85
|
+
readonly api: TokenStandardWallet;
|
|
86
|
+
/** The clock in milliseconds; `invalid-input` when it gives an invalid `Date`. */
|
|
87
|
+
readonly now: () => number;
|
|
88
|
+
/** The wallet as the current party: resolved per action, so an account switch in the wallet is followed. */
|
|
89
|
+
readonly connect: () => Promise<Cip103Wallet>;
|
|
90
|
+
/** The party's unlocked and locked holdings that the registry serves. */
|
|
91
|
+
readonly holdingsOf: (wallet: Cip103Wallet) => Promise<Holding[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Run a write action alone: refused with `busy` (before `action` starts) while another write of this token wallet is
|
|
94
|
+
* in progress, and released when `action` settles, whether it succeeded or failed.
|
|
95
|
+
*/
|
|
96
|
+
readonly exclusive: <T>(action: () => Promise<T>) => Promise<T>;
|
|
97
|
+
}
|
|
98
|
+
/** The generic CIP-56 core; `createTokenWallet` adds DA's actions on top of it. */
|
|
99
|
+
export declare function tokenStandardCore(options: TokenStandardWalletOptions): TokenStandardCore;
|
|
100
|
+
/**
|
|
101
|
+
* CIP-56 holder actions on the instruments of any `TokenRegistry` through a CIP-0103 provider. For DA Utility Registry
|
|
102
|
+
* instruments use `createTokenWallet`, which adds DA's mint, burn and preapproval actions.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createTokenStandardWallet(options: TokenStandardWalletOptions): TokenStandardWallet;
|
|
105
|
+
//# 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,EAAgC,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAKxE,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D,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,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@
|
|
|
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 token_registry_1 = require("./token-registry");
|
|
21
|
+
const SECOND_MS = 1000;
|
|
22
|
+
const DAY_MS = 24 * 60 * 60 * SECOND_MS;
|
|
23
|
+
/** Transfers: `executeBefore` = now + 24 h, a common wallet default. */
|
|
24
|
+
exports.TRANSFER_TTL_MS = DAY_MS;
|
|
25
|
+
/**
|
|
26
|
+
* `requestedAt` = now − 60 s for transfers and burn requests: registries require it in the past by ledger time, and the
|
|
27
|
+
* client's clock can run ahead of the participant's.
|
|
28
|
+
*/
|
|
29
|
+
exports.REQUESTED_AT_SKEW_MS = 60 * SECOND_MS;
|
|
30
|
+
function requireNonEmpty(value, field) {
|
|
31
|
+
if (value.trim().length === 0) {
|
|
32
|
+
throw new errors_1.TokenWalletError('invalid-input', `${field} is required`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
/** Milliseconds of a caller's `Date`; `invalid-input` for an invalid one (NaN), which `toISOString` would throw on. */
|
|
37
|
+
function requireTime(date, field) {
|
|
38
|
+
const ms = date instanceof Date ? date.getTime() : Number.NaN;
|
|
39
|
+
if (!Number.isFinite(ms)) {
|
|
40
|
+
throw new errors_1.TokenWalletError('invalid-input', `${field} is not a valid time`);
|
|
41
|
+
}
|
|
42
|
+
return ms;
|
|
43
|
+
}
|
|
44
|
+
/** ISO-8601 of a time in milliseconds; `invalid-input` when it is outside the `Date` range. */
|
|
45
|
+
function isoTime(ms, field) {
|
|
46
|
+
return new Date(requireTime(new Date(ms), field)).toISOString();
|
|
47
|
+
}
|
|
48
|
+
function requireInstrumentId(instrumentId) {
|
|
49
|
+
return {
|
|
50
|
+
admin: requireNonEmpty(instrumentId.admin, 'instrumentId.admin'),
|
|
51
|
+
id: requireNonEmpty(instrumentId.id, 'instrumentId.id'),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The generic CIP-56 core; `createTokenWallet` adds DA's actions on top of it. */
|
|
55
|
+
function tokenStandardCore(options) {
|
|
56
|
+
const { provider, registry } = options;
|
|
57
|
+
const clock = options.now ?? (() => new Date());
|
|
58
|
+
const now = () => requireTime(clock(), 'now()');
|
|
59
|
+
if (options.partyId !== undefined)
|
|
60
|
+
requireNonEmpty(options.partyId, 'partyId');
|
|
61
|
+
async function partyId() {
|
|
62
|
+
return options.partyId ?? (0, cip103_1.primaryPartyId)(provider);
|
|
63
|
+
}
|
|
64
|
+
async function connect() {
|
|
65
|
+
return (0, cip103_1.cip103Wallet)(provider, await partyId());
|
|
66
|
+
}
|
|
67
|
+
// Checked and taken synchronously (before the first await), so a second write started in the same tick is refused
|
|
68
|
+
// and two writes never select the same holdings.
|
|
69
|
+
let busy = false;
|
|
70
|
+
async function exclusive(action) {
|
|
71
|
+
if (busy) {
|
|
72
|
+
throw new errors_1.TokenWalletError('busy', 'Another wallet action is in progress; nothing was submitted');
|
|
73
|
+
}
|
|
74
|
+
busy = true;
|
|
75
|
+
try {
|
|
76
|
+
return await action();
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
busy = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function holdingsOf(wallet) {
|
|
83
|
+
const contracts = await wallet.listActiveContracts({
|
|
84
|
+
interfaceId: constants_1.TOKEN_STANDARD_V1_HOLDING_INTERFACE_ID,
|
|
85
|
+
});
|
|
86
|
+
return contracts.flatMap((contract) => {
|
|
87
|
+
if (!registry.servesHolding(contract))
|
|
88
|
+
return [];
|
|
89
|
+
const holding = (0, holdings_1.parseHolding)(contract);
|
|
90
|
+
return holding !== null && holding.owner === wallet.partyId ? [holding] : [];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** Select inputs and ask the registry for the factory; the factory must be an expected, disclosed template. */
|
|
94
|
+
async function prepareTransfer(wallet, request) {
|
|
95
|
+
const instrumentId = requireInstrumentId(request.instrumentId);
|
|
96
|
+
const receiver = requireNonEmpty(request.receiver, 'receiver');
|
|
97
|
+
const selection = (0, holdings_1.selectHoldings)(await holdingsOf(wallet), {
|
|
98
|
+
owner: wallet.partyId,
|
|
99
|
+
instrumentId,
|
|
100
|
+
amount: request.amount,
|
|
101
|
+
});
|
|
102
|
+
const at = now();
|
|
103
|
+
const transfer = {
|
|
104
|
+
sender: wallet.partyId,
|
|
105
|
+
receiver,
|
|
106
|
+
amount: selection.amount,
|
|
107
|
+
instrumentId,
|
|
108
|
+
requestedAt: isoTime(at - exports.REQUESTED_AT_SKEW_MS, 'requestedAt'),
|
|
109
|
+
executeBefore: isoTime(at + exports.TRANSFER_TTL_MS, 'executeBefore'),
|
|
110
|
+
inputHoldingCids: selection.inputHoldingCids,
|
|
111
|
+
meta: {
|
|
112
|
+
values: request.memo !== undefined && request.memo.length > 0
|
|
113
|
+
? { [constants_1.TOKEN_STANDARD_V1_REASON_META_KEY]: request.memo }
|
|
114
|
+
: {},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
const factory = await registry.transferFactory({
|
|
118
|
+
expectedAdmin: instrumentId.admin,
|
|
119
|
+
transfer,
|
|
120
|
+
});
|
|
121
|
+
const factoryError = (0, token_registry_1.factoryTemplateError)(factory, registry.expectedTransferFactoryTemplates);
|
|
122
|
+
if (factoryError !== null)
|
|
123
|
+
throw new errors_1.RegistryResponseError(factoryError);
|
|
124
|
+
return { transfer, factory };
|
|
125
|
+
}
|
|
126
|
+
async function runTransfer(request) {
|
|
127
|
+
const wallet = await connect();
|
|
128
|
+
const { transfer: spec, factory } = await prepareTransfer(wallet, request);
|
|
129
|
+
const kind = factory.transferKind;
|
|
130
|
+
if (request.requirePreapproval === true && kind !== 'direct') {
|
|
131
|
+
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`);
|
|
132
|
+
}
|
|
133
|
+
if (request.expectedKind !== undefined && kind !== request.expectedKind) {
|
|
134
|
+
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`);
|
|
135
|
+
}
|
|
136
|
+
const result = await wallet.submit({
|
|
137
|
+
commands: [
|
|
138
|
+
(0, commands_1.transferCommand)({
|
|
139
|
+
factoryId: factory.factoryId,
|
|
140
|
+
expectedAdmin: spec.instrumentId.admin,
|
|
141
|
+
transfer: spec,
|
|
142
|
+
context: factory.choiceContextData,
|
|
143
|
+
}),
|
|
144
|
+
],
|
|
145
|
+
disclosedContracts: factory.disclosedContracts,
|
|
146
|
+
});
|
|
147
|
+
return { kind, ...result };
|
|
148
|
+
}
|
|
149
|
+
async function transferOffersOf(wallet) {
|
|
150
|
+
const offers = await registry.pendingTransfers(async (filter) => wallet.listActiveContracts(filter));
|
|
151
|
+
return {
|
|
152
|
+
incoming: offers.filter((o) => o.receiver === wallet.partyId && o.sender !== wallet.partyId),
|
|
153
|
+
outgoing: offers.filter((o) => o.sender === wallet.partyId),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function runAnswerTransferOffer(transferOfferCid, action) {
|
|
157
|
+
const wallet = await connect();
|
|
158
|
+
const { incoming, outgoing } = await transferOffersOf(wallet);
|
|
159
|
+
const offer = (action === 'withdraw' ? outgoing : incoming).find((o) => o.contractId === transferOfferCid);
|
|
160
|
+
if (!offer) {
|
|
161
|
+
throw new errors_1.TokenWalletError('not-found', `Transfer offer ${transferOfferCid} is not among the wallet's ${action === 'withdraw' ? 'outgoing' : 'incoming'} offers`);
|
|
162
|
+
}
|
|
163
|
+
const context = await registry.transferInstructionContext(offer.instrumentId.admin, transferOfferCid, action);
|
|
164
|
+
return wallet.submit({
|
|
165
|
+
commands: [(0, commands_1.transferInstructionCommand)(transferOfferCid, action, context.choiceContextData)],
|
|
166
|
+
disclosedContracts: context.disclosedContracts,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
now,
|
|
171
|
+
connect,
|
|
172
|
+
holdingsOf,
|
|
173
|
+
exclusive,
|
|
174
|
+
api: {
|
|
175
|
+
partyId,
|
|
176
|
+
listHoldings: async () => holdingsOf(await connect()),
|
|
177
|
+
previewTransfer: async (request) => (await prepareTransfer(await connect(), request)).factory.transferKind,
|
|
178
|
+
transfer: async (request) => exclusive(async () => runTransfer(request)),
|
|
179
|
+
listTransferOffers: async () => transferOffersOf(await connect()),
|
|
180
|
+
acceptTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'accept')),
|
|
181
|
+
rejectTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'reject')),
|
|
182
|
+
withdrawTransferOffer: async (cid) => exclusive(async () => runAnswerTransferOffer(cid, 'withdraw')),
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* CIP-56 holder actions on the instruments of any `TokenRegistry` through a CIP-0103 provider. For DA Utility Registry
|
|
188
|
+
* instruments use `createTokenWallet`, which adds DA's mint, burn and preapproval actions.
|
|
189
|
+
*/
|
|
190
|
+
function createTokenStandardWallet(options) {
|
|
191
|
+
return tokenStandardCore(options).api;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=token-standard-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-standard-wallet.js","sourceRoot":"","sources":["../../../src/wallets/token-standard-wallet.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;GAIG;AACH,qCAAgG;AAChG,yCAAyE;AAEzE,qCAAmE;AACnE,yCAAwE;AACxE,oEAG8C;AAC9C,qDAO0B;AAG1B,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;AAExC,wEAAwE;AAC3D,QAAA,eAAe,GAAG,MAAM,CAAC;AACtC;;;GAGG;AACU,QAAA,oBAAoB,GAAG,EAAE,GAAG,SAAS,CAAC;AAmEnD,yBAAgC,KAAa,EAAE,KAAa;IAC1D,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,yBAAgB,CAAC,eAAe,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,uHAAuH;AACvH,qBAA4B,IAAU,EAAE,KAAa;IACnD,MAAM,EAAE,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IAC9D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,yBAAgB,CAAC,eAAe,EAAE,GAAG,KAAK,sBAAsB,CAAC,CAAC;I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C,OAAO,CAAC,YAAY;YAC1G,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACxE,kBAAkB,EAAE,KAAK,IAAI,EAAE,CAAC,gBAAgB,CAAC,MAAM,OAAO,EAAE,CAAC;YACjE,mBAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,sBAAsB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAChG,mBAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,sBAAsB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAChG,qBAAqB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,sBAAsB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;SACrG;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,mCAA0C,OAAmC;IAC3E,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type BurnRequest, type MintOffer } from './contracts';
|
|
2
|
+
import { type DaUtilitiesClient } from './da-utilities/client';
|
|
3
|
+
import { 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
|
+
export interface TokenWallet extends TokenStandardWallet {
|
|
19
|
+
/** Mint offers to the wallet party, made under their instrument admin's registry service. */
|
|
20
|
+
listMintOffers(): Promise<MintOffer[]>;
|
|
21
|
+
acceptMintOffer(mintOfferCid: string, options?: {
|
|
22
|
+
expectedRegistrar?: string;
|
|
23
|
+
}): Promise<SubmitResult>;
|
|
24
|
+
/** File a burn (redemption) request; DA locks the amount until the registrar accepts or rejects it. */
|
|
25
|
+
requestBurn(options: BurnRequestOptions): Promise<SubmitResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Experimental: create the wallet party's DA transfer preapproval for an instrument admin (every instrument of the
|
|
28
|
+
* admin when `instrumentIds` is empty or omitted, else up to 10). No live create has been observed yet.
|
|
29
|
+
*/
|
|
30
|
+
createTransferPreapproval(options: {
|
|
31
|
+
instrumentAdmin: string;
|
|
32
|
+
instrumentIds?: readonly string[];
|
|
33
|
+
}): Promise<SubmitResult>;
|
|
34
|
+
/** The wallet party's open burn requests (pending redemptions). */
|
|
35
|
+
listBurnRequests(): Promise<BurnRequest[]>;
|
|
36
|
+
}
|
|
37
|
+
/** A `TokenWallet` over a CIP-0103 provider, using DA's Utilities API for choice contexts. */
|
|
38
|
+
export declare function createTokenWallet(options: TokenWalletOptions): TokenWallet;
|
|
39
|
+
//# 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,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8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAuK1E"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BURN_REFERENCE_PATTERN = exports.BURN_TTL_MS = void 0;
|
|
4
|
+
exports.createTokenWallet = createTokenWallet;
|
|
5
|
+
/**
|
|
6
|
+
* Holder actions on DA Utility Registry instruments through any CIP-0103 wallet provider: the generic CIP-56 actions
|
|
7
|
+
* (`token-standard-wallet.ts`: holdings, transfers, pending transfers) plus DA's own: accept a mint offer, request a
|
|
8
|
+
* burn, create a transfer preapproval, list burn requests. Every write fetches its choice context from the registry,
|
|
9
|
+
* refuses anything that does not check out, and submits as the wallet party only.
|
|
10
|
+
*
|
|
11
|
+
* Scope: DA registry instruments. By default a registrar must be its own registry provider; a registrar served by
|
|
12
|
+
* another provider is trusted only through the registry client's `trustedProviders` option (see `isFromRegistry`).
|
|
13
|
+
*/
|
|
14
|
+
const commands_1 = require("./commands");
|
|
15
|
+
const contracts_1 = require("./contracts");
|
|
16
|
+
const client_1 = require("./da-utilities/client");
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
const holdings_1 = require("./holdings");
|
|
19
|
+
const templates_1 = require("../da-registry/templates");
|
|
20
|
+
const token_registry_1 = require("./token-registry");
|
|
21
|
+
const token_standard_wallet_1 = require("./token-standard-wallet");
|
|
22
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
/** Burn requests: `executeBefore` defaults to now + 7 days, giving the registrar a week to accept or reject. */
|
|
24
|
+
exports.BURN_TTL_MS = 7 * DAY_MS;
|
|
25
|
+
/** A burn reference: no personal data (DA's operator and the registrar see it). */
|
|
26
|
+
exports.BURN_REFERENCE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/;
|
|
27
|
+
/** A `TokenWallet` over a CIP-0103 provider, using DA's Utilities API for choice contexts. */
|
|
28
|
+
function createTokenWallet(options) {
|
|
29
|
+
const { registry } = options;
|
|
30
|
+
const core = (0, token_standard_wallet_1.tokenStandardCore)(options);
|
|
31
|
+
const { connect, exclusive, now } = core;
|
|
32
|
+
async function listMintOffers() {
|
|
33
|
+
const wallet = await connect();
|
|
34
|
+
const [contracts, operator] = await Promise.all([
|
|
35
|
+
wallet.listActiveContracts({
|
|
36
|
+
templateId: templates_1.DA_REGISTRY_TEMPLATES.mintOffer,
|
|
37
|
+
}),
|
|
38
|
+
registry.operatorParty(),
|
|
39
|
+
]);
|
|
40
|
+
return contracts.flatMap((contract) => {
|
|
41
|
+
const offer = (0, contracts_1.parseMintOffer)(contract);
|
|
42
|
+
return offer !== null &&
|
|
43
|
+
offer.holder === wallet.partyId &&
|
|
44
|
+
(0, contracts_1.isFromRegistry)(offer, contract.signatories, operator, registry.trustedProvidersOf)
|
|
45
|
+
? [offer]
|
|
46
|
+
: [];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function runAcceptMintOffer(mintOfferCid, acceptOptions = {}) {
|
|
50
|
+
const wallet = await connect();
|
|
51
|
+
const contracts = await wallet.listActiveContracts({
|
|
52
|
+
templateId: templates_1.DA_REGISTRY_TEMPLATES.mintOffer,
|
|
53
|
+
});
|
|
54
|
+
const contract = contracts.find((c) => c.contractId === mintOfferCid);
|
|
55
|
+
const offer = contract ? (0, contracts_1.parseMintOffer)(contract) : null;
|
|
56
|
+
if (contract === undefined || offer === null) {
|
|
57
|
+
throw new errors_1.TokenWalletError('not-found', `Mint offer ${mintOfferCid} is not among the wallet's active mint offers`);
|
|
58
|
+
}
|
|
59
|
+
if (offer.holder !== wallet.partyId) {
|
|
60
|
+
throw new errors_1.TokenWalletError('not-addressed-to-wallet', `Mint offer ${mintOfferCid} is for ${offer.holder}, not the wallet party`);
|
|
61
|
+
}
|
|
62
|
+
if (!(0, contracts_1.isFromRegistry)(offer, contract.signatories, await registry.operatorParty(), registry.trustedProvidersOf)) {
|
|
63
|
+
throw new errors_1.TokenWalletError('unexpected-registrar', `Mint offer ${mintOfferCid} was not made under a trusted registry service of its instrument admin`);
|
|
64
|
+
}
|
|
65
|
+
if (acceptOptions.expectedRegistrar !== undefined && offer.instrumentId.admin !== acceptOptions.expectedRegistrar) {
|
|
66
|
+
throw new errors_1.TokenWalletError('unexpected-registrar', `Mint offer ${mintOfferCid} is of ${offer.instrumentId.admin}, not the expected registrar`);
|
|
67
|
+
}
|
|
68
|
+
const context = await registry.mintOfferAcceptContext(mintOfferCid);
|
|
69
|
+
return wallet.submit({
|
|
70
|
+
commands: [(0, commands_1.acceptMintOfferCommand)(mintOfferCid, context.choiceContextData)],
|
|
71
|
+
disclosedContracts: context.disclosedContracts,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async function runRequestBurn(burn) {
|
|
75
|
+
const instrumentId = (0, token_standard_wallet_1.requireInstrumentId)(burn.instrumentId);
|
|
76
|
+
if (!exports.BURN_REFERENCE_PATTERN.test(burn.reference)) {
|
|
77
|
+
throw new errors_1.TokenWalletError('invalid-input', 'reference must be 1-100 characters of letters, digits and . _ : - (starting with a letter or digit), with no personal data');
|
|
78
|
+
}
|
|
79
|
+
const at = now();
|
|
80
|
+
const deadline = burn.executeBefore === undefined ? at + exports.BURN_TTL_MS : (0, token_standard_wallet_1.requireTime)(burn.executeBefore, 'executeBefore');
|
|
81
|
+
if (deadline <= at) {
|
|
82
|
+
throw new errors_1.TokenWalletError('invalid-input', 'executeBefore must be in the future');
|
|
83
|
+
}
|
|
84
|
+
const requestedAt = (0, token_standard_wallet_1.isoTime)(at - token_standard_wallet_1.REQUESTED_AT_SKEW_MS, 'requestedAt');
|
|
85
|
+
const executeBefore = (0, token_standard_wallet_1.isoTime)(deadline, 'executeBefore');
|
|
86
|
+
const wallet = await connect();
|
|
87
|
+
const selection = (0, holdings_1.selectHoldings)(await core.holdingsOf(wallet), {
|
|
88
|
+
owner: wallet.partyId,
|
|
89
|
+
instrumentId,
|
|
90
|
+
amount: burn.amount,
|
|
91
|
+
});
|
|
92
|
+
const factory = await registry.burnRequestContext({
|
|
93
|
+
holder: wallet.partyId,
|
|
94
|
+
holdingContractIds: selection.inputHoldingCids,
|
|
95
|
+
instrumentId,
|
|
96
|
+
});
|
|
97
|
+
const factoryError = (0, token_registry_1.factoryTemplateError)(factory, client_1.DA_BURN_FACTORY_TEMPLATES);
|
|
98
|
+
if (factoryError !== null)
|
|
99
|
+
throw new errors_1.RegistryResponseError(factoryError);
|
|
100
|
+
return wallet.submit({
|
|
101
|
+
commands: [
|
|
102
|
+
(0, commands_1.requestBurnCommand)({
|
|
103
|
+
allocationFactoryCid: factory.factoryId,
|
|
104
|
+
expectedAdmin: instrumentId.admin,
|
|
105
|
+
burn: {
|
|
106
|
+
instrumentId,
|
|
107
|
+
amount: selection.amount,
|
|
108
|
+
holder: wallet.partyId,
|
|
109
|
+
reference: burn.reference,
|
|
110
|
+
requestedAt,
|
|
111
|
+
executeBefore,
|
|
112
|
+
},
|
|
113
|
+
holdingCids: selection.inputHoldingCids,
|
|
114
|
+
context: factory.choiceContextData,
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
disclosedContracts: factory.disclosedContracts,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async function runCreateTransferPreapproval(preapproval) {
|
|
121
|
+
const instrumentAdmin = (0, token_standard_wallet_1.requireNonEmpty)(preapproval.instrumentAdmin, 'instrumentAdmin');
|
|
122
|
+
const instrumentIds = [...new Set(preapproval.instrumentIds ?? [])];
|
|
123
|
+
if (instrumentIds.length > commands_1.MAX_PREAPPROVAL_INSTRUMENTS) {
|
|
124
|
+
throw new errors_1.TokenWalletError('invalid-input', `A preapproval allows at most ${commands_1.MAX_PREAPPROVAL_INSTRUMENTS} instrument ids`);
|
|
125
|
+
}
|
|
126
|
+
instrumentIds.forEach((id) => (0, token_standard_wallet_1.requireNonEmpty)(id, 'instrumentIds[]'));
|
|
127
|
+
const wallet = await connect();
|
|
128
|
+
return wallet.submit({
|
|
129
|
+
commands: [
|
|
130
|
+
(0, commands_1.createDaTransferPreapprovalCommand)({
|
|
131
|
+
operator: await registry.operatorParty(),
|
|
132
|
+
receiver: wallet.partyId,
|
|
133
|
+
instrumentAdmin,
|
|
134
|
+
instrumentIds,
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async function listBurnRequests() {
|
|
140
|
+
const wallet = await connect();
|
|
141
|
+
const [contracts, operator] = await Promise.all([
|
|
142
|
+
wallet.listActiveContracts({
|
|
143
|
+
templateId: templates_1.DA_REGISTRY_TEMPLATES.burnRequest,
|
|
144
|
+
}),
|
|
145
|
+
registry.operatorParty(),
|
|
146
|
+
]);
|
|
147
|
+
return contracts.flatMap((contract) => {
|
|
148
|
+
const request = (0, contracts_1.parseBurnRequest)(contract);
|
|
149
|
+
return request !== null &&
|
|
150
|
+
request.holder === wallet.partyId &&
|
|
151
|
+
(0, contracts_1.isFromRegistry)(request, contract.signatories, operator, registry.trustedProvidersOf)
|
|
152
|
+
? [request]
|
|
153
|
+
: [];
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...core.api,
|
|
158
|
+
listMintOffers,
|
|
159
|
+
acceptMintOffer: async (mintOfferCid, acceptOptions) => exclusive(async () => runAcceptMintOffer(mintOfferCid, acceptOptions)),
|
|
160
|
+
requestBurn: async (burn) => exclusive(async () => runRequestBurn(burn)),
|
|
161
|
+
createTransferPreapproval: async (preapproval) => exclusive(async () => runCreateTransferPreapproval(preapproval)),
|
|
162
|
+
listBurnRequests,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=token-wallet.js.map
|