@fairmint/canton-node-sdk 0.0.282 → 0.0.283

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 (72) hide show
  1. package/README.md +128 -154
  2. package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts.map +1 -1
  3. package/build/src/utils/external-signing/wallet-ownership-challenger.js +2 -3
  4. package/build/src/utils/external-signing/wallet-ownership-challenger.js.map +1 -1
  5. package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -1
  6. package/build/src/utils/external-signing/wallet-ownership.js +8 -18
  7. package/build/src/utils/external-signing/wallet-ownership.js.map +1 -1
  8. package/build/src/wallets/acs.d.ts +2 -1
  9. package/build/src/wallets/acs.d.ts.map +1 -1
  10. package/build/src/wallets/acs.js +6 -31
  11. package/build/src/wallets/acs.js.map +1 -1
  12. package/build/src/wallets/cip103.d.ts +32 -68
  13. package/build/src/wallets/cip103.d.ts.map +1 -1
  14. package/build/src/wallets/cip103.js +112 -230
  15. package/build/src/wallets/cip103.js.map +1 -1
  16. package/build/src/wallets/commands.d.ts +39 -6
  17. package/build/src/wallets/commands.d.ts.map +1 -1
  18. package/build/src/wallets/commands.js +50 -5
  19. package/build/src/wallets/commands.js.map +1 -1
  20. package/build/src/wallets/contracts.d.ts +12 -0
  21. package/build/src/wallets/contracts.d.ts.map +1 -1
  22. package/build/src/wallets/contracts.js +21 -5
  23. package/build/src/wallets/contracts.js.map +1 -1
  24. package/build/src/wallets/da-utilities/client.d.ts +61 -29
  25. package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
  26. package/build/src/wallets/da-utilities/client.js +78 -75
  27. package/build/src/wallets/da-utilities/client.js.map +1 -1
  28. package/build/src/wallets/errors.d.ts +11 -8
  29. package/build/src/wallets/errors.d.ts.map +1 -1
  30. package/build/src/wallets/errors.js +13 -3
  31. package/build/src/wallets/errors.js.map +1 -1
  32. package/build/src/wallets/holdings.d.ts +14 -4
  33. package/build/src/wallets/holdings.d.ts.map +1 -1
  34. package/build/src/wallets/holdings.js +27 -47
  35. package/build/src/wallets/holdings.js.map +1 -1
  36. package/build/src/wallets/index.d.ts +17 -21
  37. package/build/src/wallets/index.d.ts.map +1 -1
  38. package/build/src/wallets/index.js +14 -23
  39. package/build/src/wallets/index.js.map +1 -1
  40. package/build/src/wallets/instrument.js +1 -1
  41. package/build/src/wallets/instrument.js.map +1 -1
  42. package/build/src/wallets/ownership.d.ts +20 -26
  43. package/build/src/wallets/ownership.d.ts.map +1 -1
  44. package/build/src/wallets/ownership.js +33 -27
  45. package/build/src/wallets/ownership.js.map +1 -1
  46. package/build/src/wallets/session.d.ts +30 -68
  47. package/build/src/wallets/session.d.ts.map +1 -1
  48. package/build/src/wallets/session.js +119 -167
  49. package/build/src/wallets/session.js.map +1 -1
  50. package/build/src/wallets/store.d.ts +148 -86
  51. package/build/src/wallets/store.d.ts.map +1 -1
  52. package/build/src/wallets/store.js +267 -99
  53. package/build/src/wallets/store.js.map +1 -1
  54. package/build/src/wallets/templates.d.ts +10 -23
  55. package/build/src/wallets/templates.d.ts.map +1 -1
  56. package/build/src/wallets/templates.js +9 -33
  57. package/build/src/wallets/templates.js.map +1 -1
  58. package/build/src/wallets/types.d.ts +6 -20
  59. package/build/src/wallets/types.d.ts.map +1 -1
  60. package/build/src/wallets/wallet.d.ts +130 -74
  61. package/build/src/wallets/wallet.d.ts.map +1 -1
  62. package/build/src/wallets/wallet.js +347 -185
  63. package/build/src/wallets/wallet.js.map +1 -1
  64. package/package.json +1 -1
  65. package/build/src/wallets/cip56-core.d.ts +0 -175
  66. package/build/src/wallets/cip56-core.d.ts.map +0 -1
  67. package/build/src/wallets/cip56-core.js +0 -325
  68. package/build/src/wallets/cip56-core.js.map +0 -1
  69. package/build/src/wallets/token-registry.d.ts +0 -97
  70. package/build/src/wallets/token-registry.d.ts.map +0 -1
  71. package/build/src/wallets/token-registry.js +0 -19
  72. package/build/src/wallets/token-registry.js.map +0 -1
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MAX_PREAPPROVAL_INSTRUMENTS = void 0;
4
4
  exports.extraArgs = extraArgs;
5
5
  exports.acceptMintOfferCommand = acceptMintOfferCommand;
6
+ exports.rejectMintOfferCommand = rejectMintOfferCommand;
7
+ exports.cancelBurnRequestCommand = cancelBurnRequestCommand;
6
8
  exports.requestBurnCommand = requestBurnCommand;
7
9
  exports.transferCommand = transferCommand;
8
10
  exports.transferInstructionCommand = transferInstructionCommand;
9
11
  exports.createDaTransferPreapprovalCommand = createDaTransferPreapprovalCommand;
12
+ exports.withdrawTransferPreapprovalCommand = withdrawTransferPreapprovalCommand;
10
13
  const templates_1 = require("../da-registry/templates");
11
14
  const constants_1 = require("../utils/token-standard/v1/constants");
12
15
  /** Splice `ExtraArgs`: the registry's context, unchanged, and empty metadata. */
@@ -27,6 +30,35 @@ function acceptMintOfferCommand(mintOfferCid, context) {
27
30
  },
28
31
  };
29
32
  }
33
+ /**
34
+ * The holder rejects a DA mint offer (`MintOffer_Reject`: `{reason, extraArgs: Optional ExtraArgs}`). DA needs no
35
+ * choice context for it.
36
+ */
37
+ function rejectMintOfferCommand(mintOfferCid, reason) {
38
+ return {
39
+ ExerciseCommand: {
40
+ templateId: templates_1.DA_REGISTRY_TEMPLATES.mintOffer,
41
+ contractId: mintOfferCid,
42
+ choice: 'MintOffer_Reject',
43
+ choiceArgument: { reason, extraArgs: null },
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * The holder cancels its burn request, and DA unlocks the amount. `BurnRequest_Cancel` takes `{extraArgs: Optional
49
+ * ExtraArgs}` and is controlled by the burn's holder (DA's `utility-registry-app-v0` 0.9.2, as embedded in
50
+ * `Fairmint/canton` `config/third-party-dars/tradecraft/canton-swap-amm-vault-1.3.19.dar`).
51
+ */
52
+ function cancelBurnRequestCommand(burnRequestCid) {
53
+ return {
54
+ ExerciseCommand: {
55
+ templateId: templates_1.DA_REGISTRY_TEMPLATES.burnRequest,
56
+ contractId: burnRequestCid,
57
+ choice: 'BurnRequest_Cancel',
58
+ choiceArgument: { extraArgs: null },
59
+ },
60
+ };
61
+ }
30
62
  /**
31
63
  * The holder's burn request (`AllocationFactory_RequestBurn`, controlled by the holder): DA merges and splits
32
64
  * `holdingCids`, locks exactly the amount to the registrar and creates a `BurnRequest`. `meta` is left empty.
@@ -99,11 +131,9 @@ function transferInstructionCommand(transferInstructionCid, action, context) {
99
131
  /** DA allows up to 10 instrument ids per preapproval; an empty list covers every instrument of the admin. */
100
132
  exports.MAX_PREAPPROVAL_INSTRUMENTS = 10;
101
133
  /**
102
- * The receiver's DA transfer preapproval (a plain create; signatory the receiver, observer DA's operator). Transfers of
103
- * the allowed instruments then complete at once instead of waiting for the receiver to accept.
104
- *
105
- * Experimental: the same command as `da-registry`'s `createTransferPreapproval`, but no holder-side create of it has
106
- * been observed on a live network yet.
134
+ * The receiver's DA transfer preapproval (a plain create; signatory the receiver, observer DA's operator), the same
135
+ * command as `da-registry`'s `createTransferPreapproval`. Transfers of the allowed instruments then complete at once
136
+ * instead of waiting for the receiver to accept.
107
137
  */
108
138
  function createDaTransferPreapprovalCommand(params) {
109
139
  return {
@@ -118,4 +148,19 @@ function createDaTransferPreapprovalCommand(params) {
118
148
  },
119
149
  };
120
150
  }
151
+ /**
152
+ * The receiver withdraws its DA transfer preapproval. `TransferPreapproval_Withdraw` takes `{actor: Party}`, is
153
+ * controlled by `actor` and checks it against the contract's receiver and operator (DA's `utility-registry-app-v0`
154
+ * 0.9.2, as embedded in `Fairmint/canton` `config/third-party-dars/tradecraft/canton-swap-amm-vault-1.3.19.dar`).
155
+ */
156
+ function withdrawTransferPreapprovalCommand(preapprovalCid, actor) {
157
+ return {
158
+ ExerciseCommand: {
159
+ templateId: templates_1.DA_REGISTRY_TEMPLATES.transferPreapproval,
160
+ contractId: preapprovalCid,
161
+ choice: 'TransferPreapproval_Withdraw',
162
+ choiceArgument: { actor },
163
+ },
164
+ };
165
+ }
121
166
  //# sourceMappingURL=commands.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/wallets/commands.ts"],"names":[],"mappings":";;;;;;;;;AASA,wDAAiE;AACjE,oEAI8C;AAI9C,iFAAiF;AACjF,mBAA0B,OAA0B;IAClD,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;AACvE,CAAC;AAED,SAAS,gBAAgB,CAAC,YAA0B;IAClD,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC;AAC5D,CAAC;AAED,+DAA+D;AAC/D,gCAAuC,YAAoB,EAAE,OAA0B;IACrF,OAAO;QACL,eAAe,EAAE;YACf,UAAU,EAAE,iCAAqB,CAAC,SAAS;YAC3C,UAAU,EAAE,YAAY;YACxB,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE;SAClD;KACF,CAAC;AACJ,CAAC;AAYD;;;GAGG;AACH,4BAAmC,MAMlC;IACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,OAAO;QACL,eAAe,EAAE;YACf,UAAU,EAAE,iCAAqB,CAAC,iBAAiB;YACnD,UAAU,EAAE,MAAM,CAAC,oBAAoB;YACvC,MAAM,EAAE,+BAA+B;YACvC,cAAc,EAAE;gBACd,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,IAAI,EAAE;oBACJ,YAAY,EAAE,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC;oBACjD,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,aAAa,EA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UAAU,EAAE,sBAAsB;YAClC,MAAM,EAAE,4BAA4B,CAAC,MAAM,CAAC;YAC5C,cAAc,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE;SAClD;KACF,CAAC;AACJ,CAAC;AAED,6GAA6G;AAChG,QAAA,2BAA2B,GAAG,EAAE,CAAC;AAE9C;;;;GAIG;AACH,4CAAmD,MAKlD;IACC,OAAO;QACL,aAAa,EAAE;YACb,UAAU,EAAE,iCAAqB,CAAC,mBAAmB;YACrD,eAAe,EAAE;gBACf,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,eAAe,EAAE,MAAM,CAAC,eAAe;gBACvC,oBAAoB,EAAE,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;aACjE;SACF;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,4CAAmD,cAAsB,EAAE,KAAa;IACtF,OAAO;QACL,eAAe,EAAE;YACf,UAAU,EAAE,iCAAqB,CAAC,mBAAmB;YACrD,UAAU,EAAE,cAAc;YAC1B,MAAM,EAAE,8BAA8B;YACtC,cAAc,EAAE,EAAE,KAAK,EAAE;SAC1B;KACF,CAAC;AACJ,CAAC"}
@@ -36,6 +36,16 @@ export interface BurnRequest extends RegistryParties {
36
36
  /** The holding DA locked for the burn: the registrar's accept burns it, a reject or cancel unlocks it. */
37
37
  readonly lockedHoldingCid: string;
38
38
  }
39
+ /** The receiver's standing acceptance of an instrument admin's transfers, so they complete at once. */
40
+ export interface TransferPreapproval {
41
+ readonly contractId: string;
42
+ /** DA's operator party. */
43
+ readonly operator: string;
44
+ readonly receiver: string;
45
+ readonly instrumentAdmin: string;
46
+ /** The instruments it covers; empty: every instrument of `instrumentAdmin`. */
47
+ readonly instrumentIds: readonly string[];
48
+ }
39
49
  /**
40
50
  * A DA `MintOffer` (`{operator, provider, mint: {instrumentId, amount, holder, reference, requestedAt,
41
51
  * executeBefore}}`).
@@ -45,6 +55,8 @@ export declare function parseMintOffer(contract: ActiveContract): MintOffer | nu
45
55
  export declare function parseTransferOffer(contract: ActiveContract): TransferOffer | null;
46
56
  /** A DA `BurnRequest` (`{operator, provider, burn: {...}, lockedHoldingCid}`). */
47
57
  export declare function parseBurnRequest(contract: ActiveContract): BurnRequest | null;
58
+ /** A DA `TransferPreapproval` (`{operator, receiver, instrumentAdmin, instrumentAllowances: [{id}]}`). */
59
+ export declare function parseTransferPreapproval(contract: ActiveContract): TransferPreapproval | null;
48
60
  /**
49
61
  * Whether a registry contract was made under a trusted registry service of its instrument admin: a trusted provider
50
62
  * signed it and it names DA's operator. The create argument alone proves nothing (any party can create a look-alike
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/wallets/contracts.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5D,UAAU,eAAe;IACvB,2BAA2B;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,qHAAqH;IACrH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,SAAU,SAAQ,eAAe;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,Q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AAS,MAAM,EAAE,GACjE,OAAO,CAMT"}
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMintOffer = parseMintOffer;
4
4
  exports.parseTransferOffer = parseTransferOffer;
5
5
  exports.parseBurnRequest = parseBurnRequest;
6
+ exports.parseTransferPreapproval = parseTransferPreapproval;
6
7
  exports.isFromRegistry = isFromRegistry;
7
8
  /**
8
- * Readers for the DA Registry contracts a holder acts on: mint offers, transfer offers and burn requests. Each returns
9
- * null for a contract of another template or one whose create argument does not read.
9
+ * Readers for the DA Registry contracts a holder acts on: mint offers, transfer offers, burn requests and transfer
10
+ * preapprovals. Each returns null for a contract of another template or package, or one whose create argument does not
11
+ * read.
10
12
  */
11
13
  const instrument_1 = require("./instrument");
12
14
  const json_1 = require("./json");
@@ -29,9 +31,7 @@ function text(value) {
29
31
  return typeof value === 'string' ? value : null;
30
32
  }
31
33
  function argumentsOf(contract, templateId) {
32
- if (!(0, templates_2.sameQualifiedName)(contract.templateId, templateId))
33
- return null;
34
- return contract.createArgument;
34
+ return (0, templates_2.isTemplate)(contract, templateId) ? contract.createArgument : null;
35
35
  }
36
36
  /**
37
37
  * A DA `MintOffer` (`{operator, provider, mint: {instrumentId, amount, holder, reference, requestedAt,
@@ -98,6 +98,22 @@ function parseBurnRequest(contract) {
98
98
  reference,
99
99
  };
100
100
  }
101
+ /** A DA `TransferPreapproval` (`{operator, receiver, instrumentAdmin, instrumentAllowances: [{id}]}`). */
102
+ function parseTransferPreapproval(contract) {
103
+ const args = argumentsOf(contract, templates_1.DA_REGISTRY_TEMPLATES.transferPreapproval);
104
+ const allowances = args?.['instrumentAllowances'];
105
+ if (args === null || !Array.isArray(allowances))
106
+ return null;
107
+ const parties = strings(args, ['operator', 'receiver', 'instrumentAdmin']);
108
+ const instrumentIds = allowances.map((allowance) => (0, json_1.isRecord)(allowance) ? (0, json_1.nonEmptyString)(allowance['id']) : undefined);
109
+ if (!parties || instrumentIds.includes(undefined))
110
+ return null;
111
+ return {
112
+ contractId: contract.contractId,
113
+ ...parties,
114
+ instrumentIds: instrumentIds.filter((id) => id !== undefined),
115
+ };
116
+ }
101
117
  /**
102
118
  * Whether a registry contract was made under a trusted registry service of its instrument admin: a trusted provider
103
119
  * signed it and it names DA's operator. The create argument alone proves nothing (any party can create a look-alike
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/wallets/contracts.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,6CAAgD;AAChD,iCAAkD;AAClD,wDAAiE;AACjE,2CAAgD;AAEhD,oEAAyF;AA2CzF,0DAA0D;AAC1D,SAAS,OAAO,CAAmB,MAA+B,EAAE,IAAkB;IACpF,MAAM,MAAM,GAA+B,EAAE,CAAC;IAC9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAA,qBAAc,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAA2B,CAAC;AACrC,CAAC;AAED,6DAA6D;AAC7D,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,QAAwB,EAAE,UAAkB;IAC/D,IAAI,CAAC,IAAA,6BAAiB,EAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,OAAO,QAAQ,CAAC,cAAc,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,wBAA+B,QAAwB;IACrD,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,EAAE,iCAAqB,CAAC,SAAS,CAAC,CAAC;IACpE,MAA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Ac,EAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAClE,CAAC;IACF,IAAI,CAAC,OAAO,IAAI,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO;QACL,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,GAAG,OAAO;QACV,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,wBACE,QAAmE,EACnE,WAA8B,EAC9B,UAAkB,EAClB,kBAAkE;IAElE,OAAO,CACL,QAAQ,CAAC,QAAQ,KAAK,UAAU;QAChC,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC3E,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxC,CAAC;AACJ,CAAC"}
@@ -1,5 +1,7 @@
1
- import type { ChoiceContext, FactoryWithChoiceContext, TokenRegistry } from '../token-registry';
2
- import type { ActiveContract, DisclosedContract, InstrumentId } from '../types';
1
+ import type { InstrumentMetadata } from '../holdings';
2
+ import { type JsonObject } from '../json';
3
+ import type { TransferInstructionAction, TransferSpec } from '../commands';
4
+ import type { DisclosedContract, InstrumentId } from '../types';
3
5
  export type DaNetwork = 'devnet' | 'mainnet';
4
6
  /** DA Utilities API base URL per network. */
5
7
  export declare const DA_UTILITIES_BASE_URLS: Readonly<Record<DaNetwork, string>>;
@@ -13,14 +15,15 @@ export type FetchLike = (url: string, init: {
13
15
  status: number;
14
16
  text(): Promise<string>;
15
17
  }>;
16
- export type DaUtilitiesTarget = {
17
- network: DaNetwork;
18
- } | {
19
- baseUrl: string;
20
- };
21
- export interface DaUtilitiesClientOptions {
18
+ /** How a wallet reaches DA's Utilities API. */
19
+ export interface DaRegistryOptions {
20
+ /**
21
+ * Defaults to DA's own URL for the wallet's network (`https://api.utilities.digitalasset-dev.com` on DevNet,
22
+ * `https://api.utilities.digitalasset.com` on MainNet); for example a proxy.
23
+ */
24
+ readonly baseUrl?: string;
22
25
  /** Defaults to `globalThis.fetch`. */
23
- fetch?: FetchLike;
26
+ readonly fetch?: FetchLike;
24
27
  /**
25
28
  * The registry providers to trust, per instrument admin (registrar party id → provider party ids). DA's registry lets
26
29
  * a registrar be served by another party's provider service; its mint offers, transfer offers and burn requests are
@@ -28,7 +31,33 @@ export interface DaUtilitiesClientOptions {
28
31
  * is also its own provider); an admin not listed trusts only itself. Offers and requests of any other provider are
29
32
  * never listed or acted on.
30
33
  */
31
- trustedProviders?: Readonly<Record<string, readonly string[]>>;
34
+ readonly trustedProviders?: Readonly<Record<string, readonly string[]>>;
35
+ }
36
+ /** Splice `ChoiceContext` data: passed through unchanged as `extraArgs.context`. */
37
+ export interface ChoiceContextData {
38
+ readonly values: JsonObject;
39
+ }
40
+ /** What the registry returns for a choice: its context, and the contracts to disclose with the submission. */
41
+ export interface ChoiceContext {
42
+ readonly choiceContextData: ChoiceContextData;
43
+ readonly disclosedContracts: readonly DisclosedContract[];
44
+ }
45
+ /** A factory to exercise, with its choice context. */
46
+ export interface FactoryWithChoiceContext extends ChoiceContext {
47
+ readonly factoryId: string;
48
+ }
49
+ /**
50
+ * How the registry will run a transfer:
51
+ *
52
+ * - `offer`: a pending transfer the receiver must accept before it expires. The sender's tokens stay locked until the
53
+ * offer is accepted, rejected by the receiver or withdrawn by the sender; expiry alone only stops acceptance and does
54
+ * not unlock them (withdraw an expired offer to get them back);
55
+ * - `direct`: the receiver pre-approved transfers, so the holdings move at once;
56
+ * - `self`: sender and receiver are the same party (the holdings are merged or split).
57
+ */
58
+ export type TransferKind = 'offer' | 'direct' | 'self';
59
+ export interface TransferFactory extends FactoryWithChoiceContext {
60
+ readonly transferKind: TransferKind;
32
61
  }
33
62
  export interface BurnRequestContextArgs {
34
63
  readonly holder: string;
@@ -37,39 +66,40 @@ export interface BurnRequestContextArgs {
37
66
  readonly instrumentId: InstrumentId;
38
67
  }
39
68
  /**
40
- * DA's Utilities API: the CIP-56 registry methods plus DA's own mint and burn endpoints. It serves DA Registry
41
- * `Holding`s only: a holding counts when its registrar signed it, and an offer or request when a provider trusted for
42
- * its instrument admin signed it and it names DA's operator.
69
+ * DA's Utilities API for one network. An offer or request counts as DA's when a provider trusted for its instrument
70
+ * admin signed it and it names DA's operator.
43
71
  */
44
- export interface DaUtilitiesClient extends TokenRegistry {
45
- readonly baseUrl: string;
72
+ export interface DaUtilitiesClient {
46
73
  /** The providers trusted for an instrument admin: the `trustedProviders` entry, else the admin itself. */
47
74
  readonly trustedProvidersOf: (instrumentAdmin: string) => readonly string[];
48
75
  /** DA's operator party (`GET /api/utilities/v0/operator`), fetched once; a failed lookup is retried next call. */
49
76
  operatorParty(): Promise<string>;
77
+ /** The transfer factory for a transfer, and how DA will run it. */
78
+ transferFactory(expectedAdmin: string, transfer: TransferSpec): Promise<TransferFactory>;
79
+ /** Context to accept, reject or withdraw a pending transfer. */
80
+ transferInstructionContext(registrar: string, instructionCid: string, action: TransferInstructionAction): Promise<ChoiceContext>;
50
81
  /** Context to exercise `MintOffer_Accept` on the offer. */
51
82
  mintOfferAcceptContext(mintOfferCid: string): Promise<ChoiceContext>;
52
83
  /** The allocation factory and context to exercise `AllocationFactory_RequestBurn`. */
53
84
  burnRequestContext(args: BurnRequestContextArgs): Promise<FactoryWithChoiceContext>;
85
+ /**
86
+ * The instrument's CIP-56 metadata, or undefined on any failure (an error status, a malformed answer). An answer is
87
+ * kept for the client's lifetime; a failure is asked again next call.
88
+ */
89
+ instrumentMetadata(instrumentId: InstrumentId): Promise<InstrumentMetadata | undefined>;
54
90
  }
55
91
  /**
56
- * Whether `registry` is DA's Utility Registry client (it has every member of `DaUtilitiesClient`: a non-empty `baseUrl`
57
- * and the functions DA's actions need), so a `Wallet` over it offers DA's mint, burn and preapproval actions. A
58
- * registry with only some of those members is not: its wallet keeps every CIP-56 action and refuses DA's with
59
- * `unsupported-by-registry`.
92
+ * `Module:Entity` of the templates DA names as the transfer factory, per kind: a direct transfer runs through the
93
+ * receiver's `TransferPreapproval`, an offer or a self-transfer never does.
60
94
  */
61
- export declare function isDaUtilitiesClient(registry: TokenRegistry): registry is DaUtilitiesClient;
62
- /** `Module:Entity` of the templates DA names as a transfer factory. */
63
- export declare const DA_TRANSFER_FACTORY_TEMPLATES: readonly string[];
95
+ export declare const DA_TRANSFER_FACTORY_TEMPLATES: Readonly<Record<TransferKind, readonly string[]>>;
64
96
  /** `Module:Entity` of the template DA names as the burn (`AllocationFactory_RequestBurn`) factory. */
65
97
  export declare const DA_BURN_FACTORY_TEMPLATES: readonly string[];
66
98
  /**
67
- * Whether a contract is a DA Registry `Holding` its instrument admin signed. The holding's signatories are its
68
- * registrar (the instrument admin), its owner and any lockers; DA's operator is only an observer. The template name and
69
- * interface view alone prove nothing: any party can create a look-alike from its own package, with the wallet party as
70
- * observer, so only the registrar's signature makes a holding real.
99
+ * Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
100
+ * that names any other contract is refused before anything is signed.
71
101
  */
72
- export declare function isGenuineDaHolding(contract: ActiveContract): boolean;
102
+ export declare function factoryTemplateError(factory: FactoryWithChoiceContext, expectedTemplates: readonly string[]): string | null;
73
103
  /**
74
104
  * A DA disclosed contract stripped to the fields the Ledger API accepts: DA adds `createdAt`, `domainId` and debug
75
105
  * fields, which the ledger refuses.
@@ -77,6 +107,8 @@ export declare function isGenuineDaHolding(contract: ActiveContract): boolean;
77
107
  export declare function parseDisclosedContract(raw: unknown): DisclosedContract;
78
108
  /** A `ChoiceContext` response: `choiceContextData` and `disclosedContracts` are both required. */
79
109
  export declare function parseChoiceContext(raw: unknown): ChoiceContext;
80
- /** A client for DA's Utilities API on a network (or any base URL, e.g. a proxy). */
81
- export declare function createDaUtilitiesClient(target: DaUtilitiesTarget, options?: DaUtilitiesClientOptions): DaUtilitiesClient;
110
+ /** The global `fetch`, looked up at call time; without one it throws, naming the `option` to pass instead. */
111
+ export declare function globalFetch(option: string): FetchLike;
112
+ /** A client for DA's Utilities API on a network (at `options.baseUrl` when given). */
113
+ export declare function createDaUtilitiesClient(network: DaNetwork, options?: DaRegistryOptions): DaUtilitiesClient;
82
114
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/wallets/da-utilities/client.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,aAAa,EAId,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhF,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE7C,6CAA6C;AAC7C,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAGtE,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IACJ,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KACE,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAAC;AAEvE,MAAM,MAAM,iBAAiB,GAAG;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E,MAAM,WAAW,wBAAwB;IACvC,sCAAsC;IACtC,KAAK,CA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M,EACtB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,2DAA2D;IAC3D,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACrE,sFAAsF;IACtF,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACpF;;;OAGG;IACH,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;CACzF;AAKD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC,CAI3F,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAAyC,CAAC;AAEjG;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,wBAAwB,EACjC,iBAAiB,EAAE,SAAS,MAAM,EAAE,GACnC,MAAM,GAAG,IAAI,CASf;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,iBAAiB,CAmBtE;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAgB9D;AAqBD,8GAA8G;AAC9G,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAMrD;AAaD,sFAAsF;AACtF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,GAAE,iBAAsB,GAAG,iBAAiB,CAqI9G"}
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DA_BURN_FACTORY_TEMPLATES = exports.DA_TRANSFER_FACTORY_TEMPLATES = exports.DA_UTILITIES_BASE_URLS = void 0;
4
- exports.isDaUtilitiesClient = isDaUtilitiesClient;
5
- exports.isGenuineDaHolding = isGenuineDaHolding;
4
+ exports.factoryTemplateError = factoryTemplateError;
6
5
  exports.parseDisclosedContract = parseDisclosedContract;
7
6
  exports.parseChoiceContext = parseChoiceContext;
7
+ exports.globalFetch = globalFetch;
8
8
  exports.createDaUtilitiesClient = createDaUtilitiesClient;
9
9
  /**
10
- * Digital Asset's public Utilities API (no auth, CORS open), for the choice contexts the holder-side DA Registry
11
- * actions need. Browser-safe: it uses an injectable `fetch` and sends only `content-type: application/json`.
10
+ * Digital Asset's public Utilities API (no auth, CORS open): the choice contexts and factories the holder-side DA
11
+ * Registry actions need, and the CIP-56 instrument metadata. Browser-safe: it uses an injectable `fetch` and sends only
12
+ * `content-type: application/json`.
12
13
  *
13
- * Endpoints: DA's Utilities OpenAPI (`utility.yaml` v2.2.0) and token-standard transfer-instruction V1 spec.
14
+ * Endpoints: DA's Utilities OpenAPI (`utility.yaml` v2.2.0), and the token standard transfer-instruction V1 and
15
+ * metadata V1 specs under `/api/token-standard/v0/registrars/{admin}`.
14
16
  */
15
- const contracts_1 = require("../contracts");
16
17
  const errors_1 = require("../errors");
17
18
  const holdings_1 = require("../holdings");
18
19
  const json_1 = require("../json");
@@ -23,46 +24,31 @@ exports.DA_UTILITIES_BASE_URLS = {
23
24
  devnet: 'https://api.utilities.digitalasset-dev.com',
24
25
  mainnet: 'https://api.utilities.digitalasset.com',
25
26
  };
26
- /** The members DA's actions need beyond `TokenRegistry`. */
27
- const DA_UTILITIES_CLIENT_MEMBERS = [
28
- 'operatorParty',
29
- 'trustedProvidersOf',
30
- 'mintOfferAcceptContext',
31
- 'burnRequestContext',
32
- ];
27
+ const templateNames = (keys) => keys.map((key) => (0, templates_2.requireQualifiedName)(templates_1.DA_REGISTRY_TEMPLATES[key]));
33
28
  /**
34
- * Whether `registry` is DA's Utility Registry client (it has every member of `DaUtilitiesClient`: a non-empty `baseUrl`
35
- * and the functions DA's actions need), so a `Wallet` over it offers DA's mint, burn and preapproval actions. A
36
- * registry with only some of those members is not: its wallet keeps every CIP-56 action and refuses DA's with
37
- * `unsupported-by-registry`.
29
+ * `Module:Entity` of the templates DA names as the transfer factory, per kind: a direct transfer runs through the
30
+ * receiver's `TransferPreapproval`, an offer or a self-transfer never does.
38
31
  */
39
- function isDaUtilitiesClient(registry) {
40
- const members = registry;
41
- const { baseUrl } = members;
42
- return (typeof baseUrl === 'string' &&
43
- baseUrl.length > 0 &&
44
- DA_UTILITIES_CLIENT_MEMBERS.every((member) => typeof members[member] === 'function'));
45
- }
46
- /** `Module:Entity` of the templates DA names as a transfer factory. */
47
- exports.DA_TRANSFER_FACTORY_TEMPLATES = ['transferRule', 'transferPreapproval', 'allocationFactory'].map((key) => (0, templates_2.requireQualifiedName)(templates_1.DA_REGISTRY_TEMPLATES[key]));
32
+ exports.DA_TRANSFER_FACTORY_TEMPLATES = {
33
+ direct: templateNames(['transferPreapproval']),
34
+ offer: templateNames(['transferRule', 'allocationFactory']),
35
+ self: templateNames(['transferRule', 'allocationFactory']),
36
+ };
48
37
  /** `Module:Entity` of the template DA names as the burn (`AllocationFactory_RequestBurn`) factory. */
49
- exports.DA_BURN_FACTORY_TEMPLATES = [
50
- (0, templates_2.requireQualifiedName)(templates_1.DA_REGISTRY_TEMPLATES.allocationFactory),
51
- ];
52
- const DA_HOLDING_PACKAGE_NAME = (0, templates_2.packageNameOf)(templates_1.DA_REGISTRY_TEMPLATES.holding);
38
+ exports.DA_BURN_FACTORY_TEMPLATES = templateNames(['allocationFactory']);
53
39
  /**
54
- * Whether a contract is a DA Registry `Holding` its instrument admin signed. The holding's signatories are its
55
- * registrar (the instrument admin), its owner and any lockers; DA's operator is only an observer. The template name and
56
- * interface view alone prove nothing: any party can create a look-alike from its own package, with the wallet party as
57
- * observer, so only the registrar's signature makes a holding real.
40
+ * Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
41
+ * that names any other contract is refused before anything is signed.
58
42
  */
59
- function isGenuineDaHolding(contract) {
60
- if (!(0, templates_2.sameQualifiedName)(contract.templateId, templates_1.DA_REGISTRY_TEMPLATES.holding) ||
61
- (contract.packageName !== undefined && contract.packageName !== DA_HOLDING_PACKAGE_NAME)) {
62
- return false;
43
+ function factoryTemplateError(factory, expectedTemplates) {
44
+ const disclosed = factory.disclosedContracts.find((contract) => contract.contractId === factory.factoryId);
45
+ if (!disclosed) {
46
+ return 'The registry named a factory it did not disclose.';
63
47
  }
64
- const holding = (0, holdings_1.parseHolding)(contract);
65
- return holding !== null && contract.signatories.includes(holding.instrumentId.admin);
48
+ const name = (0, templates_2.qualifiedName)(disclosed.templateId);
49
+ return name !== null && expectedTemplates.includes(name)
50
+ ? null
51
+ : `The registry named a factory of an unexpected template (${disclosed.templateId}).`;
66
52
  }
67
53
  /**
68
54
  * A DA disclosed contract stripped to the fields the Ledger API accepts: DA adds `createdAt`, `domainId` and debug
@@ -119,18 +105,32 @@ function parseTransferFactory(raw) {
119
105
  }
120
106
  return { ...factory, transferKind };
121
107
  }
122
- /** The global `fetch`, looked up at call time. */
123
- const globalFetch = async (url, init) => {
124
- const { fetch } = globalThis;
125
- if (typeof fetch !== 'function') {
126
- throw new TypeError('No global fetch: pass { fetch } to createDaUtilitiesClient');
127
- }
128
- return fetch(url, init);
129
- };
130
- /** A client for DA's Utilities API on a network (or any base URL, e.g. a proxy). */
131
- function createDaUtilitiesClient(target, options = {}) {
132
- const baseUrl = trimTrailingSlashes('network' in target ? exports.DA_UTILITIES_BASE_URLS[target.network] : target.baseUrl);
133
- const fetchFn = options.fetch ?? globalFetch;
108
+ /** The global `fetch`, looked up at call time; without one it throws, naming the `option` to pass instead. */
109
+ function globalFetch(option) {
110
+ return async (url, init) => {
111
+ const { fetch } = globalThis;
112
+ if (typeof fetch !== 'function')
113
+ throw new TypeError(`No global fetch: pass ${option}`);
114
+ return fetch(url, init);
115
+ };
116
+ }
117
+ /** CIP-56 `Instrument` metadata of `id`, or undefined when the answer is of another instrument or malformed. */
118
+ function parseInstrumentMetadata(raw, id) {
119
+ if (!(0, json_1.isRecord)(raw) || raw['id'] !== id)
120
+ return undefined;
121
+ const { name, symbol } = raw;
122
+ // The spec's default when the registry leaves it out.
123
+ const decimals = raw['decimals'] ?? 10;
124
+ if (typeof name !== 'string' || typeof symbol !== 'string')
125
+ return undefined;
126
+ if (typeof decimals !== 'number' || !Number.isInteger(decimals) || decimals < 0 || decimals > 10)
127
+ return undefined;
128
+ return { name, symbol, decimals };
129
+ }
130
+ /** A client for DA's Utilities API on a network (at `options.baseUrl` when given). */
131
+ function createDaUtilitiesClient(network, options = {}) {
132
+ const baseUrl = trimTrailingSlashes(options.baseUrl ?? exports.DA_UTILITIES_BASE_URLS[network]);
133
+ const fetchFn = options.fetch ?? globalFetch('registry.fetch');
134
134
  const trustedProvidersOf = trustedProvidersResolver(options.trustedProviders);
135
135
  async function call(method, path, body) {
136
136
  const url = `${baseUrl}${path}`;
@@ -151,7 +151,7 @@ function createDaUtilitiesClient(target, options = {}) {
151
151
  throw new errors_1.RegistryResponseError(`Registry returned non-JSON for ${url}`);
152
152
  }
153
153
  }
154
- const registrarPath = (registrar) => `/api/token-standard/v0/registrars/${encodeURIComponent(registrar)}/registry/transfer-instruction/v1`;
154
+ const registryPath = (registrar) => `/api/token-standard/v0/registrars/${encodeURIComponent(registrar)}/registry`;
155
155
  async function fetchOperator() {
156
156
  const raw = await call('GET', '/api/utilities/v0/operator');
157
157
  const partyId = (0, json_1.isRecord)(raw) ? (0, json_1.nonEmptyString)(raw['partyId']) : undefined;
@@ -168,27 +168,30 @@ function createDaUtilitiesClient(target, options = {}) {
168
168
  }));
169
169
  return operatorPromise;
170
170
  }
171
+ const metadata = new Map();
172
+ /** A lookup still unanswered after this long gives undefined (and is retried next time), so a load never hangs on it. */
173
+ const METADATA_TIMEOUT_MS = 5000;
174
+ async function instrumentMetadata(instrumentId) {
175
+ const key = (0, holdings_1.instrumentKey)(instrumentId);
176
+ let pending = metadata.get(key);
177
+ if (pending === undefined) {
178
+ let timer;
179
+ const timedOut = new Promise((resolve) => {
180
+ timer = setTimeout(() => resolve(undefined), METADATA_TIMEOUT_MS);
181
+ });
182
+ const lookup = call('GET', `${registryPath(instrumentId.admin)}/metadata/v1/instruments/${encodeURIComponent(instrumentId.id)}`).then((raw) => parseInstrumentMetadata(raw, instrumentId.id), () => undefined);
183
+ pending = Promise.race([lookup, timedOut]).finally(() => clearTimeout(timer));
184
+ metadata.set(key, pending);
185
+ }
186
+ const answer = await pending;
187
+ if (answer === undefined && metadata.get(key) === pending)
188
+ metadata.delete(key);
189
+ return answer;
190
+ }
171
191
  return {
172
- baseUrl,
173
- expectedTransferFactoryTemplates: exports.DA_TRANSFER_FACTORY_TEMPLATES,
174
- pendingTransferFilters: [{ templateId: templates_1.DA_REGISTRY_TEMPLATES.transferOffer }],
175
- // The template filter carries the create argument, which `parseHolding` reads when there is no HoldingV1 view.
176
- holdingFilters: [{ templateId: templates_1.DA_REGISTRY_TEMPLATES.holding }],
177
- operatorParty,
178
192
  trustedProvidersOf,
179
- servesHolding: isGenuineDaHolding,
180
- async pendingTransfers(read) {
181
- const [contracts, operator] = await Promise.all([
182
- read({ templateId: templates_1.DA_REGISTRY_TEMPLATES.transferOffer }),
183
- operatorParty(),
184
- ]);
185
- return contracts.flatMap((contract) => {
186
- const offer = (0, contracts_1.parseTransferOffer)(contract);
187
- return offer !== null && (0, contracts_1.isFromRegistry)(offer, contract.signatories, operator, trustedProvidersOf)
188
- ? [offer]
189
- : [];
190
- });
191
- },
193
+ operatorParty,
194
+ instrumentMetadata,
192
195
  async mintOfferAcceptContext(mintOfferCid) {
193
196
  return parseChoiceContext(await call('POST', `/api/utilities/v0/registry/mint/v0/offer/${encodeURIComponent(mintOfferCid)}/choice-contexts/accept`, {}));
194
197
  },
@@ -199,8 +202,8 @@ function createDaUtilitiesClient(target, options = {}) {
199
202
  instrumentId: { admin: instrumentId.admin, id: instrumentId.id },
200
203
  }));
201
204
  },
202
- async transferFactory({ expectedAdmin, transfer }) {
203
- return parseTransferFactory(await call('POST', `${registrarPath(expectedAdmin)}/transfer-factory`, {
205
+ async transferFactory(expectedAdmin, transfer) {
206
+ return parseTransferFactory(await call('POST', `${registryPath(expectedAdmin)}/transfer-instruction/v1/transfer-factory`, {
204
207
  choiceArguments: {
205
208
  expectedAdmin,
206
209
  transfer: {
@@ -225,7 +228,7 @@ function createDaUtilitiesClient(target, options = {}) {
225
228
  }));
226
229
  },
227
230
  async transferInstructionContext(registrar, instructionCid, action) {
228
- return parseChoiceContext(await call('POST', `${registrarPath(registrar)}/${encodeURIComponent(instructionCid)}/choice-contexts/${action}`, { excludeDebugFields: true }));
231
+ return parseChoiceContext(await call('POST', `${registryPath(registrar)}/transfer-instruction/v1/${encodeURIComponent(instructionCid)}/choice-contexts/${action}`, { excludeDebugFields: true }));
229
232
  },
230
233
  };
231
234
  }