@temple-digital-group/temple-canton-js 2.0.3-beta.0 → 2.0.3-beta.1

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 (2) hide show
  1. package/package.json +3 -2
  2. package/src/canton/index.js +0 -171
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temple-digital-group/temple-canton-js",
3
- "version": "2.0.3-beta.0",
3
+ "version": "2.0.3-beta.1",
4
4
  "description": "JavaScript library for interacting with Temple Canton blockchain",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -34,7 +34,8 @@
34
34
  "scripts": {
35
35
  "start": "node index.js",
36
36
  "build": "tsc",
37
- "prepublishOnly": "npm run build"
37
+ "smoke": "node scripts/smoke-import.mjs",
38
+ "prepublishOnly": "npm run build && npm run smoke"
38
39
  },
39
40
  "dependencies": {
40
41
  "axios": "^1.13.1",
@@ -3017,177 +3017,6 @@ export async function isUserOnboarded(user = null, returnCommand = false) {
3017
3017
  }
3018
3018
  }
3019
3019
 
3020
- /**
3021
- * Build an Allocation_Withdraw ExerciseCommand for one or more stuck allocation CIDs.
3022
- * Returns the command(s) ready for submission via wallet adapter or ledger API.
3023
- *
3024
- * @param {Object} opts
3025
- * @param {string|string[]} opts.allocationCids - Single CID or array of allocation contract IDs
3026
- * @param {string} opts.assetId - The asset symbol ("Amulet", "CC", "USDCx", etc.)
3027
- * @param {string} [opts.sender] - Party ID. Falls back to wallet adapter or VALIDATOR_USER_PARTY_ID.
3028
- * @param {Object} [opts.disclosures] - Pre-fetched disclosures (optional, will be resolved if missing)
3029
- * @returns {Promise<Object>} { commands: [...] } array of { command, endpoint } objects, or { error }
3030
- */
3031
- export async function buildAllocationWithdrawCommand(opts) {
3032
- const { disclosures, userId } = opts || {};
3033
- const assetId = (opts.assetId === "CC" || opts.assetId === "cc") ? "Amulet" : opts.assetId;
3034
- const sender = getAdapterPartyId() || opts.sender || config.VALIDATOR_USER_PARTY_ID;
3035
-
3036
- if (!opts.allocationCids || !sender || !assetId) {
3037
- return { error: "buildAllocationWithdrawCommand: allocationCids, sender, and assetId are required" };
3038
- }
3039
-
3040
- const cids = Array.isArray(opts.allocationCids) ? opts.allocationCids : [opts.allocationCids];
3041
- if (cids.length === 0) {
3042
- return { error: "buildAllocationWithdrawCommand: allocationCids must not be empty" };
3043
- }
3044
-
3045
- const isAmulet = assetId === "Amulet";
3046
-
3047
- // --- Resolve context and disclosures (once for all CIDs) ---
3048
- let choiceContextData = {};
3049
- let disclosedContracts = [];
3050
-
3051
- if (shouldUseLedgerForMetadata()) {
3052
- if (isAmulet) {
3053
- const amuletCtx = await resolveAmuletContext({ investor: sender, holdingIds: [], transferAmount: 0 });
3054
- if (!amuletCtx) {
3055
- return { error: "buildAllocationWithdrawCommand: failed to resolve Amulet context from ledger" };
3056
- }
3057
- const contextKeys = amuletCtx.contextKeys;
3058
- choiceContextData = {
3059
- values: {
3060
- [contextKeys.amuletRules]: { tag: "AV_ContractId", value: amuletCtx.amuletRules.contractCid },
3061
- [contextKeys.openRound]: { tag: "AV_ContractId", value: amuletCtx.openMiningRound.contractCid },
3062
- [contextKeys.featuredAppRight]: { tag: "AV_ContractId", value: amuletCtx.featuredAppRight.contractCid },
3063
- [contextKeys.expireLock]: { tag: "AV_Bool", value: true },
3064
- },
3065
- };
3066
- disclosedContracts = [
3067
- { templateId: amuletCtx.amuletRules.templateId || null, contractId: amuletCtx.amuletRules.contractCid, createdEventBlob: amuletCtx.amuletRules.disclosureCid, synchronizerId: amuletCtx.amuletRules.synchronizerId },
3068
- { templateId: amuletCtx.openMiningRound.templateId || null, contractId: amuletCtx.openMiningRound.contractCid, createdEventBlob: amuletCtx.openMiningRound.disclosureCid, synchronizerId: amuletCtx.openMiningRound.synchronizerId },
3069
- { templateId: amuletCtx.externalAmuletRules.templateId || null, contractId: amuletCtx.externalAmuletRules.contractCid, createdEventBlob: amuletCtx.externalAmuletRules.disclosureCid, synchronizerId: amuletCtx.externalAmuletRules.synchronizerId },
3070
- ];
3071
- if (amuletCtx.featuredAppRight?.contractCid && amuletCtx.featuredAppRight?.disclosureCid) {
3072
- disclosedContracts.push({ templateId: amuletCtx.featuredAppRight.templateId || null, contractId: amuletCtx.featuredAppRight.contractCid, createdEventBlob: amuletCtx.featuredAppRight.disclosureCid, synchronizerId: amuletCtx.featuredAppRight.synchronizerId });
3073
- }
3074
- } else {
3075
- const instrumentDef = resolveInstrumentDefinition(assetId);
3076
- const networkDef = instrumentDef?.[config.NETWORK];
3077
- const registrar = networkDef?.registrar || getInstrumentRegistrar(assetId) || config.VALIDATOR_REGISTRAR_PARTY_ID;
3078
- const [allocFactory, instConfig] = await Promise.all([
3079
- resolveUtilityAllocationFactory(registrar, sender),
3080
- resolveUtilityInstrumentConfiguration(assetId, registrar),
3081
- ]);
3082
- if (instConfig) {
3083
- choiceContextData = {
3084
- values: {
3085
- [DEFAULT_UTILITY_CONTEXT_KEYS.instrumentConfiguration]: { tag: "AV_ContractId", value: instConfig.contractCid },
3086
- [DEFAULT_UTILITY_CONTEXT_KEYS.instrumentConfigurationPrefixed]: { tag: "AV_ContractId", value: instConfig.contractCid },
3087
- [DEFAULT_UTILITY_CONTEXT_KEYS.senderCredentials]: { tag: "AV_List", value: [] },
3088
- [DEFAULT_UTILITY_CONTEXT_KEYS.senderCredentialsPrefixed]: { tag: "AV_List", value: [] },
3089
- [DEFAULT_UTILITY_CONTEXT_KEYS.receiverCredentials]: { tag: "AV_List", value: [] },
3090
- [DEFAULT_UTILITY_CONTEXT_KEYS.receiverCredentialsPrefixed]: { tag: "AV_List", value: [] },
3091
- [DEFAULT_AMULET_CONTEXT_KEYS.expireLock]: { tag: "AV_Bool", value: true },
3092
- },
3093
- };
3094
- disclosedContracts.push({ templateId: null, contractId: instConfig.contractCid, createdEventBlob: instConfig.disclosureCid, synchronizerId: instConfig.synchronizerId });
3095
- }
3096
- if (allocFactory) {
3097
- disclosedContracts.push({ templateId: null, contractId: allocFactory.contractCid, createdEventBlob: allocFactory.disclosureCid, synchronizerId: allocFactory.synchronizerId });
3098
- }
3099
- }
3100
- } else if (isAmulet) {
3101
- // Resolve via disclosures API
3102
- let resolvedData = disclosures?.disclosures || disclosures || null;
3103
- if (!resolvedData?.choiceContext) {
3104
- const disclosuresResult = await getDisclosures(sender);
3105
- resolvedData = disclosuresResult?.disclosures;
3106
- if (disclosuresResult?.error || !resolvedData?.choiceContext) {
3107
- return { error: `buildAllocationWithdrawCommand: failed to resolve Amulet disclosures: ${disclosuresResult?.message || disclosuresResult?.error || "missing choiceContext"}` };
3108
- }
3109
- }
3110
- choiceContextData = resolvedData.choiceContext.choiceContextData || {};
3111
- const values = choiceContextData.values;
3112
- if (values && !values[DEFAULT_AMULET_CONTEXT_KEYS.expireLock]) {
3113
- values[DEFAULT_AMULET_CONTEXT_KEYS.expireLock] = { tag: "AV_Bool", value: true };
3114
- }
3115
- disclosedContracts = (resolvedData.choiceContext.disclosedContracts || []).map(dc => ({
3116
- templateId: dc.templateId, contractId: dc.contractId, createdEventBlob: dc.createdEventBlob, synchronizerId: dc.synchronizerId,
3117
- }));
3118
- } else {
3119
- // Utility: build context from catalog data (no ledger/validator access needed)
3120
- const instrumentDef = resolveInstrumentDefinition(assetId);
3121
- const networkContracts = instrumentDef?.[config.NETWORK];
3122
- if (!networkContracts) {
3123
- return { error: `buildAllocationWithdrawCommand: no ${config.NETWORK} config for ${assetId} in instrument catalog` };
3124
- }
3125
- const instConfig = networkContracts.instrumentConfiguration;
3126
- const allocFactory = networkContracts.allocationFactory;
3127
- const synchronizerId = networkContracts.synchronizerId;
3128
-
3129
- if (!instConfig?.contractId || !instConfig?.eventBlob) {
3130
- return { error: `buildAllocationWithdrawCommand: instrumentConfiguration missing for ${assetId} on ${config.NETWORK}` };
3131
- }
3132
-
3133
- choiceContextData = {
3134
- values: {
3135
- [DEFAULT_UTILITY_CONTEXT_KEYS.instrumentConfiguration]: { tag: "AV_ContractId", value: instConfig.contractId },
3136
- [DEFAULT_UTILITY_CONTEXT_KEYS.instrumentConfigurationPrefixed]: { tag: "AV_ContractId", value: instConfig.contractId },
3137
- [DEFAULT_UTILITY_CONTEXT_KEYS.senderCredentials]: { tag: "AV_List", value: [] },
3138
- [DEFAULT_UTILITY_CONTEXT_KEYS.senderCredentialsPrefixed]: { tag: "AV_List", value: [] },
3139
- [DEFAULT_UTILITY_CONTEXT_KEYS.receiverCredentials]: { tag: "AV_List", value: [] },
3140
- [DEFAULT_UTILITY_CONTEXT_KEYS.receiverCredentialsPrefixed]: { tag: "AV_List", value: [] },
3141
- [DEFAULT_AMULET_CONTEXT_KEYS.expireLock]: { tag: "AV_Bool", value: true },
3142
- },
3143
- };
3144
- disclosedContracts.push({
3145
- templateId: instConfig.templateId || null,
3146
- contractId: instConfig.contractId,
3147
- createdEventBlob: instConfig.eventBlob,
3148
- synchronizerId: synchronizerId,
3149
- });
3150
- if (allocFactory?.contractId && allocFactory?.eventBlob) {
3151
- disclosedContracts.push({
3152
- templateId: allocFactory.templateId || null,
3153
- contractId: allocFactory.contractId,
3154
- createdEventBlob: allocFactory.eventBlob,
3155
- synchronizerId: synchronizerId,
3156
- });
3157
- }
3158
- }
3159
-
3160
- // --- Build one command per allocation CID ---
3161
- const endpoint = `${config.VALIDATOR_API_URL}/v2/commands/submit-and-wait`;
3162
- const commands = cids.map(cid => {
3163
- const allocationCid = normalizeContractId(cid);
3164
- const command = {
3165
- commands: [{
3166
- ExerciseCommand: {
3167
- templateId: "#splice-api-token-allocation-v1:Splice.Api.Token.AllocationV1:Allocation",
3168
- contractId: allocationCid,
3169
- choice: "Allocation_Withdraw",
3170
- choiceArgument: {
3171
- extraArgs: {
3172
- context: choiceContextData,
3173
- meta: { values: {} },
3174
- },
3175
- },
3176
- },
3177
- }],
3178
- commandId: randomUUID(),
3179
- userId: userId || getUserId() || config.AUTH0_USER_ID || "temple",
3180
- applicationId: "temple",
3181
- actAs: [sender],
3182
- disclosedContracts: [...disclosedContracts],
3183
- };
3184
- dedupeDisclosedContracts(command);
3185
- return { command, endpoint };
3186
- });
3187
-
3188
- return { commands };
3189
- }
3190
-
3191
3020
  /**
3192
3021
  * Get all balances for a party, grouped by asset type.
3193
3022
  * Returns Amulet, locked Amulet, and utility token holdings with totals.