@open-captable-protocol/canton 0.2.194 → 0.2.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/OpenCapTable/capTable/getCapTableState.d.ts +1 -1
- package/dist/functions/OpenCapTable/capTable/getCapTableState.js +1 -1
- package/dist/utils/replicationHelpers.d.ts +31 -26
- package/dist/utils/replicationHelpers.d.ts.map +1 -1
- package/dist/utils/replicationHelpers.js +72 -49
- package/dist/utils/replicationHelpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Query Canton for the current state of a CapTable contract.
|
|
3
3
|
*
|
|
4
4
|
* Provides a snapshot of all OCF entities currently on-chain for an issuer,
|
|
5
|
-
* enabling stateless replication by comparing against
|
|
5
|
+
* enabling stateless replication by comparing against a source of truth.
|
|
6
6
|
*
|
|
7
7
|
* @module getCapTableState
|
|
8
8
|
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Query Canton for the current state of a CapTable contract.
|
|
4
4
|
*
|
|
5
5
|
* Provides a snapshot of all OCF entities currently on-chain for an issuer,
|
|
6
|
-
* enabling stateless replication by comparing against
|
|
6
|
+
* enabling stateless replication by comparing against a source of truth.
|
|
7
7
|
*
|
|
8
8
|
* @module getCapTableState
|
|
9
9
|
*/
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Replication helpers for cap table synchronization.
|
|
3
3
|
*
|
|
4
4
|
* Provides utilities for:
|
|
5
|
-
* - Mapping
|
|
6
|
-
* - Computing replication diffs between
|
|
5
|
+
* - Mapping categorized OCF types to SDK entity types
|
|
6
|
+
* - Computing replication diffs between source and Canton state
|
|
7
7
|
* - Human-readable labels for display
|
|
8
8
|
*
|
|
9
9
|
* @module replicationHelpers
|
|
@@ -11,25 +11,30 @@
|
|
|
11
11
|
import type { OcfEntityType } from '../functions/OpenCapTable/capTable/batchTypes';
|
|
12
12
|
import type { CapTableState } from '../functions/OpenCapTable/capTable/getCapTableState';
|
|
13
13
|
/**
|
|
14
|
-
* Map
|
|
14
|
+
* Map categorized OCF type/subtype to OcfEntityType.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
* - Direct types: STAKEHOLDER, STOCK_CLASS, STOCK_PLAN
|
|
18
|
-
* - Object subtypes:
|
|
19
|
-
* - Transaction subtypes:
|
|
16
|
+
* OCF data may be organized into categories:
|
|
17
|
+
* - Direct types: STAKEHOLDER, STOCK_CLASS, STOCK_PLAN as the category
|
|
18
|
+
* - Object subtypes: category='OBJECT', actual type in subtype
|
|
19
|
+
* - Transaction subtypes: category='TRANSACTION', actual type in subtype (TX_ prefix)
|
|
20
20
|
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
21
|
+
* @param categoryType - The OCF category (STAKEHOLDER, OBJECT, TRANSACTION, etc.)
|
|
22
|
+
* @param subtype - The subtype for OBJECT and TRANSACTION categories
|
|
23
23
|
* @returns The corresponding OcfEntityType, or null if not supported
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* mapCategorizedTypeToEntityType('STAKEHOLDER', null); // 'stakeholder'
|
|
28
|
+
* mapCategorizedTypeToEntityType('DOCUMENT', null); // 'document' (direct type)
|
|
29
|
+
* mapCategorizedTypeToEntityType('OBJECT', 'DOCUMENT'); // 'document' (categorized)
|
|
30
|
+
* mapCategorizedTypeToEntityType('TRANSACTION', 'TX_STOCK_ISSUANCE'); // 'stockIssuance'
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export declare function
|
|
33
|
+
export declare function mapCategorizedTypeToEntityType(categoryType: string, subtype: string | null): OcfEntityType | null;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `mapCategorizedTypeToEntityType` instead. This alias will be removed in a future version.
|
|
36
|
+
*/
|
|
37
|
+
export declare const mapDbTypeToEntityType: typeof mapCategorizedTypeToEntityType;
|
|
33
38
|
/**
|
|
34
39
|
* Get a human-readable label for an entity type with count.
|
|
35
40
|
*
|
|
@@ -46,7 +51,7 @@ export declare function mapDbTypeToEntityType(dbType: string, dbSubtype: string
|
|
|
46
51
|
*/
|
|
47
52
|
export declare function getEntityTypeLabel(type: OcfEntityType, count: number): string;
|
|
48
53
|
/**
|
|
49
|
-
* A single item to be synced
|
|
54
|
+
* A single item to be synced to Canton.
|
|
50
55
|
*/
|
|
51
56
|
export interface ReplicationItem {
|
|
52
57
|
/** OCF object ID */
|
|
@@ -59,14 +64,14 @@ export interface ReplicationItem {
|
|
|
59
64
|
data?: unknown;
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
|
-
* Result of comparing
|
|
67
|
+
* Result of comparing source state (desired) to Canton state (actual).
|
|
63
68
|
*/
|
|
64
69
|
export interface ReplicationDiff {
|
|
65
|
-
/** Items in
|
|
70
|
+
/** Items in source but not in Canton - need to be created */
|
|
66
71
|
creates: ReplicationItem[];
|
|
67
72
|
/** Items in both - may need to be edited */
|
|
68
73
|
edits: ReplicationItem[];
|
|
69
|
-
/** Items in Canton but not in
|
|
74
|
+
/** Items in Canton but not in source - may need to be deleted */
|
|
70
75
|
deletes: ReplicationItem[];
|
|
71
76
|
/** Total number of operations */
|
|
72
77
|
total: number;
|
|
@@ -76,7 +81,7 @@ export interface ReplicationDiff {
|
|
|
76
81
|
*/
|
|
77
82
|
export interface ComputeReplicationDiffOptions {
|
|
78
83
|
/**
|
|
79
|
-
* Whether to include delete operations for items in Canton but not in
|
|
84
|
+
* Whether to include delete operations for items in Canton but not in source.
|
|
80
85
|
* Default: false (safer - doesn't delete data)
|
|
81
86
|
*/
|
|
82
87
|
syncDeletes?: boolean;
|
|
@@ -89,29 +94,29 @@ export interface ComputeReplicationDiffOptions {
|
|
|
89
94
|
alwaysEdit?: boolean;
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
|
-
* Compute what needs to be synced
|
|
97
|
+
* Compute what needs to be synced to Canton.
|
|
93
98
|
*
|
|
94
|
-
* Compares a list of
|
|
99
|
+
* Compares a list of source items (desired state) against Canton state (actual state)
|
|
95
100
|
* and returns operations needed to synchronize them.
|
|
96
101
|
*
|
|
97
|
-
* @param
|
|
102
|
+
* @param sourceItems - OCF items from any source (desired state)
|
|
98
103
|
* @param cantonState - Current Canton state from getCapTableState()
|
|
99
104
|
* @param options - Sync options
|
|
100
105
|
* @returns Replication diff with creates, edits, and deletes
|
|
101
106
|
*
|
|
102
107
|
* @example
|
|
103
108
|
* ```typescript
|
|
104
|
-
* const
|
|
109
|
+
* const sourceItems = [
|
|
105
110
|
* { ocfId: 'stakeholder-1', entityType: 'stakeholder', data: {...} },
|
|
106
111
|
* { ocfId: 'stock-class-1', entityType: 'stockClass', data: {...} },
|
|
107
112
|
* ];
|
|
108
113
|
* const cantonState = await getCapTableState(client, issuerPartyId);
|
|
109
|
-
* const diff = computeReplicationDiff(
|
|
110
|
-
* // diff.creates = items in
|
|
111
|
-
* // diff.deletes = items in Canton but not
|
|
114
|
+
* const diff = computeReplicationDiff(sourceItems, cantonState, { syncDeletes: true });
|
|
115
|
+
* // diff.creates = items in source but not Canton
|
|
116
|
+
* // diff.deletes = items in Canton but not source
|
|
112
117
|
* ```
|
|
113
118
|
*/
|
|
114
|
-
export declare function computeReplicationDiff(
|
|
119
|
+
export declare function computeReplicationDiff(sourceItems: Array<{
|
|
115
120
|
ocfId: string;
|
|
116
121
|
entityType: OcfEntityType;
|
|
117
122
|
data: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicationHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/replicationHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qDAAqD,CAAC;
|
|
1
|
+
{"version":3,"file":"replicationHelpers.d.ts","sourceRoot":"","sources":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,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,EAC/E,WAAW,EAAE,aAAa,EAC1B,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAiFjB"}
|
|
@@ -3,43 +3,61 @@
|
|
|
3
3
|
* Replication helpers for cap table synchronization.
|
|
4
4
|
*
|
|
5
5
|
* Provides utilities for:
|
|
6
|
-
* - Mapping
|
|
7
|
-
* - Computing replication diffs between
|
|
6
|
+
* - Mapping categorized OCF types to SDK entity types
|
|
7
|
+
* - Computing replication diffs between source and Canton state
|
|
8
8
|
* - Human-readable labels for display
|
|
9
9
|
*
|
|
10
10
|
* @module replicationHelpers
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.mapDbTypeToEntityType =
|
|
13
|
+
exports.mapDbTypeToEntityType = void 0;
|
|
14
|
+
exports.mapCategorizedTypeToEntityType = mapCategorizedTypeToEntityType;
|
|
14
15
|
exports.getEntityTypeLabel = getEntityTypeLabel;
|
|
15
16
|
exports.computeReplicationDiff = computeReplicationDiff;
|
|
16
17
|
const planSecurityAliases_1 = require("./planSecurityAliases");
|
|
17
18
|
// ============================================================================
|
|
18
|
-
//
|
|
19
|
+
// Categorized Type Mapping
|
|
19
20
|
// ============================================================================
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
* These types
|
|
22
|
+
* Object type mappings shared between DIRECT_TYPE_MAP and OBJECT_SUBTYPE_MAP.
|
|
23
|
+
* These types can be stored either directly (e.g., type='DOCUMENT') or
|
|
24
|
+
* categorized (e.g., type='OBJECT', subtype='DOCUMENT').
|
|
25
|
+
*
|
|
26
|
+
* IMPORTANT: Add new object types here to ensure both direct and categorized
|
|
27
|
+
* formats are supported consistently.
|
|
28
|
+
*/
|
|
29
|
+
const OBJECT_TYPES = {
|
|
30
|
+
DOCUMENT: 'document',
|
|
31
|
+
VESTING_TERMS: 'vestingTerms',
|
|
32
|
+
STOCK_LEGEND_TEMPLATE: 'stockLegendTemplate',
|
|
33
|
+
VALUATION: 'valuation',
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Direct category type to OcfEntityType mappings.
|
|
37
|
+
* These types use the category directly as the type identifier.
|
|
38
|
+
*
|
|
39
|
+
* Note: Some databases store object types directly (DOCUMENT, VESTING_TERMS, etc.)
|
|
40
|
+
* rather than using the OBJECT category with subtypes. Both formats are supported.
|
|
23
41
|
*/
|
|
24
42
|
const DIRECT_TYPE_MAP = {
|
|
43
|
+
// Core entity types
|
|
25
44
|
STAKEHOLDER: 'stakeholder',
|
|
26
45
|
STOCK_CLASS: 'stockClass',
|
|
27
46
|
STOCK_PLAN: 'stockPlan',
|
|
47
|
+
// Object types (some DBs store these directly instead of OBJECT/subtype)
|
|
48
|
+
...OBJECT_TYPES,
|
|
28
49
|
};
|
|
29
50
|
/**
|
|
30
51
|
* OBJECT subtype to OcfEntityType mappings.
|
|
31
|
-
* These
|
|
52
|
+
* These use category='OBJECT' with the actual type in the subtype field.
|
|
32
53
|
*/
|
|
33
54
|
const OBJECT_SUBTYPE_MAP = {
|
|
34
|
-
|
|
35
|
-
VESTING_TERMS: 'vestingTerms',
|
|
36
|
-
STOCK_LEGEND_TEMPLATE: 'stockLegendTemplate',
|
|
37
|
-
VALUATION: 'valuation',
|
|
55
|
+
...OBJECT_TYPES,
|
|
38
56
|
};
|
|
39
57
|
/**
|
|
40
58
|
* TRANSACTION subtype to OcfEntityType mappings.
|
|
41
|
-
* These
|
|
42
|
-
*
|
|
59
|
+
* These use category='TRANSACTION' with the actual type in the subtype field.
|
|
60
|
+
* Subtypes use TX_ prefix with UPPER_SNAKE_CASE, SDK uses camelCase.
|
|
43
61
|
*/
|
|
44
62
|
const TRANSACTION_SUBTYPE_MAP = {
|
|
45
63
|
// Stock Transactions (9 types)
|
|
@@ -101,39 +119,44 @@ const TRANSACTION_SUBTYPE_MAP = {
|
|
|
101
119
|
TX_PLAN_SECURITY_RETRACTION: 'planSecurityRetraction',
|
|
102
120
|
};
|
|
103
121
|
/**
|
|
104
|
-
* Map
|
|
122
|
+
* Map categorized OCF type/subtype to OcfEntityType.
|
|
105
123
|
*
|
|
106
|
-
*
|
|
107
|
-
* - Direct types: STAKEHOLDER, STOCK_CLASS, STOCK_PLAN
|
|
108
|
-
* - Object subtypes:
|
|
109
|
-
* - Transaction subtypes:
|
|
124
|
+
* OCF data may be organized into categories:
|
|
125
|
+
* - Direct types: STAKEHOLDER, STOCK_CLASS, STOCK_PLAN as the category
|
|
126
|
+
* - Object subtypes: category='OBJECT', actual type in subtype
|
|
127
|
+
* - Transaction subtypes: category='TRANSACTION', actual type in subtype (TX_ prefix)
|
|
110
128
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @param
|
|
129
|
+
* @param categoryType - The OCF category (STAKEHOLDER, OBJECT, TRANSACTION, etc.)
|
|
130
|
+
* @param subtype - The subtype for OBJECT and TRANSACTION categories
|
|
113
131
|
* @returns The corresponding OcfEntityType, or null if not supported
|
|
114
132
|
*
|
|
115
133
|
* @example
|
|
116
134
|
* ```typescript
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
135
|
+
* mapCategorizedTypeToEntityType('STAKEHOLDER', null); // 'stakeholder'
|
|
136
|
+
* mapCategorizedTypeToEntityType('DOCUMENT', null); // 'document' (direct type)
|
|
137
|
+
* mapCategorizedTypeToEntityType('OBJECT', 'DOCUMENT'); // 'document' (categorized)
|
|
138
|
+
* mapCategorizedTypeToEntityType('TRANSACTION', 'TX_STOCK_ISSUANCE'); // 'stockIssuance'
|
|
120
139
|
* ```
|
|
121
140
|
*/
|
|
122
|
-
function
|
|
141
|
+
function mapCategorizedTypeToEntityType(categoryType, subtype) {
|
|
123
142
|
// Direct mappings
|
|
124
|
-
if (
|
|
125
|
-
return DIRECT_TYPE_MAP[
|
|
143
|
+
if (categoryType in DIRECT_TYPE_MAP) {
|
|
144
|
+
return DIRECT_TYPE_MAP[categoryType];
|
|
126
145
|
}
|
|
127
146
|
// Object subtypes
|
|
128
|
-
if (
|
|
129
|
-
return OBJECT_SUBTYPE_MAP[
|
|
147
|
+
if (categoryType === 'OBJECT' && subtype) {
|
|
148
|
+
return OBJECT_SUBTYPE_MAP[subtype] ?? null;
|
|
130
149
|
}
|
|
131
150
|
// Transaction subtypes
|
|
132
|
-
if (
|
|
133
|
-
return TRANSACTION_SUBTYPE_MAP[
|
|
151
|
+
if (categoryType === 'TRANSACTION' && subtype) {
|
|
152
|
+
return TRANSACTION_SUBTYPE_MAP[subtype] ?? null;
|
|
134
153
|
}
|
|
135
154
|
return null;
|
|
136
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use `mapCategorizedTypeToEntityType` instead. This alias will be removed in a future version.
|
|
158
|
+
*/
|
|
159
|
+
exports.mapDbTypeToEntityType = mapCategorizedTypeToEntityType;
|
|
137
160
|
// ============================================================================
|
|
138
161
|
// Human-Readable Labels
|
|
139
162
|
// ============================================================================
|
|
@@ -232,39 +255,39 @@ function getEntityTypeLabel(type, count) {
|
|
|
232
255
|
return `${count} ${count === 1 ? singular : plural}`;
|
|
233
256
|
}
|
|
234
257
|
/**
|
|
235
|
-
* Compute what needs to be synced
|
|
258
|
+
* Compute what needs to be synced to Canton.
|
|
236
259
|
*
|
|
237
|
-
* Compares a list of
|
|
260
|
+
* Compares a list of source items (desired state) against Canton state (actual state)
|
|
238
261
|
* and returns operations needed to synchronize them.
|
|
239
262
|
*
|
|
240
|
-
* @param
|
|
263
|
+
* @param sourceItems - OCF items from any source (desired state)
|
|
241
264
|
* @param cantonState - Current Canton state from getCapTableState()
|
|
242
265
|
* @param options - Sync options
|
|
243
266
|
* @returns Replication diff with creates, edits, and deletes
|
|
244
267
|
*
|
|
245
268
|
* @example
|
|
246
269
|
* ```typescript
|
|
247
|
-
* const
|
|
270
|
+
* const sourceItems = [
|
|
248
271
|
* { ocfId: 'stakeholder-1', entityType: 'stakeholder', data: {...} },
|
|
249
272
|
* { ocfId: 'stock-class-1', entityType: 'stockClass', data: {...} },
|
|
250
273
|
* ];
|
|
251
274
|
* const cantonState = await getCapTableState(client, issuerPartyId);
|
|
252
|
-
* const diff = computeReplicationDiff(
|
|
253
|
-
* // diff.creates = items in
|
|
254
|
-
* // diff.deletes = items in Canton but not
|
|
275
|
+
* const diff = computeReplicationDiff(sourceItems, cantonState, { syncDeletes: true });
|
|
276
|
+
* // diff.creates = items in source but not Canton
|
|
277
|
+
* // diff.deletes = items in Canton but not source
|
|
255
278
|
* ```
|
|
256
279
|
*/
|
|
257
|
-
function computeReplicationDiff(
|
|
280
|
+
function computeReplicationDiff(sourceItems, cantonState, options = {}) {
|
|
258
281
|
const { syncDeletes = false, alwaysEdit = false } = options;
|
|
259
282
|
const creates = [];
|
|
260
283
|
const edits = [];
|
|
261
284
|
const deletes = [];
|
|
262
|
-
// Track
|
|
263
|
-
const
|
|
285
|
+
// Track source items by type for delete detection
|
|
286
|
+
const sourceIdsByType = new Map();
|
|
264
287
|
// Track seen items to prevent duplicate create/edit operations
|
|
265
288
|
const seenItems = new Set();
|
|
266
|
-
// Process each
|
|
267
|
-
for (const item of
|
|
289
|
+
// Process each source item
|
|
290
|
+
for (const item of sourceItems) {
|
|
268
291
|
// Skip duplicate items (same ocfId + entityType)
|
|
269
292
|
const itemKey = `${item.entityType}:${item.ocfId}`;
|
|
270
293
|
if (seenItems.has(itemKey)) {
|
|
@@ -275,17 +298,17 @@ function computeReplicationDiff(dbItems, cantonState, options = {}) {
|
|
|
275
298
|
// Canton stores planSecurity items under equity_compensation_* fields
|
|
276
299
|
const normalizedType = (0, planSecurityAliases_1.normalizeEntityType)(item.entityType);
|
|
277
300
|
// Track for delete detection (using normalized type to match Canton's storage)
|
|
278
|
-
let typeIds =
|
|
301
|
+
let typeIds = sourceIdsByType.get(normalizedType);
|
|
279
302
|
if (!typeIds) {
|
|
280
303
|
typeIds = new Set();
|
|
281
|
-
|
|
304
|
+
sourceIdsByType.set(normalizedType, typeIds);
|
|
282
305
|
}
|
|
283
306
|
typeIds.add(item.ocfId);
|
|
284
307
|
// Check if exists in Canton (using normalized type)
|
|
285
308
|
const cantonIds = cantonState.entities.get(normalizedType) ?? new Set();
|
|
286
309
|
const existsInCanton = cantonIds.has(item.ocfId);
|
|
287
310
|
if (!existsInCanton) {
|
|
288
|
-
// Item in
|
|
311
|
+
// Item in source but not Canton → CREATE
|
|
289
312
|
creates.push({
|
|
290
313
|
ocfId: item.ocfId,
|
|
291
314
|
entityType: item.entityType,
|
|
@@ -304,13 +327,13 @@ function computeReplicationDiff(dbItems, cantonState, options = {}) {
|
|
|
304
327
|
}
|
|
305
328
|
// If not alwaysEdit and exists in Canton, skip (already synced)
|
|
306
329
|
}
|
|
307
|
-
// Detect deletes (in Canton but not in
|
|
330
|
+
// Detect deletes (in Canton but not in source)
|
|
308
331
|
if (syncDeletes) {
|
|
309
332
|
for (const [entityType, cantonIds] of cantonState.entities) {
|
|
310
|
-
const
|
|
333
|
+
const sourceIds = sourceIdsByType.get(entityType) ?? new Set();
|
|
311
334
|
for (const cantonId of cantonIds) {
|
|
312
|
-
if (!
|
|
313
|
-
// Item in Canton but not
|
|
335
|
+
if (!sourceIds.has(cantonId)) {
|
|
336
|
+
// Item in Canton but not source → DELETE
|
|
314
337
|
deletes.push({
|
|
315
338
|
ocfId: cantonId,
|
|
316
339
|
entityType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicationHelpers.js","sourceRoot":"","sources":["../../src/utils/replicationHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG
|
|
1
|
+
{"version":3,"file":"replicationHelpers.js","sourceRoot":"","sources":["../../src/utils/replicationHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA8IH,wEAiBC;AA8GD,gDAIC;AA4ED,wDAqFC;AA9aD,+DAA4D;AAE5D,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;;;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/canton",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.196",
|
|
4
4
|
"description": "A TypeScript SDK for interacting with the Open CapTable Protocol (OCP) Factory contract on Canton blockchain",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|