@layerzerolabs/common-canton 0.2.110 → 0.2.111
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/.turbo/turbo-build.log +831 -815
- package/.turbo/turbo-test.log +22 -19
- package/dist/{PVONQCBG.js → 2UKHG3HM.js} +3 -3
- package/dist/{PVONQCBG.js.map → 2UKHG3HM.js.map} +1 -1
- package/dist/{GMQEAD3I.js → 34I4OGQK.js} +3 -3
- package/dist/{GMQEAD3I.js.map → 34I4OGQK.js.map} +1 -1
- package/dist/{NLMU226B.js → 45YQNHS2.js} +3 -3
- package/dist/{NLMU226B.js.map → 45YQNHS2.js.map} +1 -1
- package/dist/{KK2NBQSG.js → 4GYCD3G4.js} +3 -3
- package/dist/{KK2NBQSG.js.map → 4GYCD3G4.js.map} +1 -1
- package/dist/{EIXIZULE.js → 5HH7PZW3.js} +37 -37
- package/dist/{EIXIZULE.js.map → 5HH7PZW3.js.map} +1 -1
- package/dist/{OQ2FVATH.js → 5OA7RJHH.js} +3 -3
- package/dist/{OQ2FVATH.js.map → 5OA7RJHH.js.map} +1 -1
- package/dist/{QYQCAXCB.js → 73I7CBP3.js} +3 -3
- package/dist/{QYQCAXCB.js.map → 73I7CBP3.js.map} +1 -1
- package/dist/{MDEOBKC3.js → 7GI6QGS6.js} +3 -3
- package/dist/{MDEOBKC3.js.map → 7GI6QGS6.js.map} +1 -1
- package/dist/{IOTRKLGP.js → 7STDATVZ.js} +3 -3
- package/dist/{IOTRKLGP.js.map → 7STDATVZ.js.map} +1 -1
- package/dist/{T4AL4FJH.js → ALC4M7WK.js} +3 -3
- package/dist/{T4AL4FJH.js.map → ALC4M7WK.js.map} +1 -1
- package/dist/{TWUSN2QY.js → AMLJTQWB.js} +3 -3
- package/dist/{TWUSN2QY.js.map → AMLJTQWB.js.map} +1 -1
- package/dist/{YCNGW63C.js → BL22CZFA.js} +3 -3
- package/dist/{YCNGW63C.js.map → BL22CZFA.js.map} +1 -1
- package/dist/{ZN2CNFMH.js → BLWJ63ZZ.js} +3 -3
- package/dist/{ZN2CNFMH.js.map → BLWJ63ZZ.js.map} +1 -1
- package/dist/CJ2WHLYC.js +116 -0
- package/dist/CJ2WHLYC.js.map +1 -0
- package/dist/{4AKFOZFY.js → CLAE73FR.js} +3 -3
- package/dist/{4AKFOZFY.js.map → CLAE73FR.js.map} +1 -1
- package/dist/CMDFOA7C.js +47 -0
- package/dist/CMDFOA7C.js.map +1 -0
- package/dist/CXTOAS7N.js +18 -0
- package/dist/CXTOAS7N.js.map +1 -0
- package/dist/{NX67V54F.js → DAP5XJGH.js} +3 -3
- package/dist/{NX67V54F.js.map → DAP5XJGH.js.map} +1 -1
- package/dist/{PSB6BQFH.js → EYLCZMM4.js} +5 -4
- package/dist/EYLCZMM4.js.map +1 -0
- package/dist/FPRRDKT5.js +52 -0
- package/dist/FPRRDKT5.js.map +1 -0
- package/dist/{KJRFPBY4.js → FXR2Z54G.js} +3 -3
- package/dist/{KJRFPBY4.js.map → FXR2Z54G.js.map} +1 -1
- package/dist/{HNZRSDTR.js → GOPXFEBJ.js} +11 -46
- package/dist/GOPXFEBJ.js.map +1 -0
- package/dist/{MJCI4XZ2.js → HLWLB4AY.js} +3 -3
- package/dist/{MJCI4XZ2.js.map → HLWLB4AY.js.map} +1 -1
- package/dist/{XSEEW6TB.js → HRZTWWO4.js} +3 -3
- package/dist/{XSEEW6TB.js.map → HRZTWWO4.js.map} +1 -1
- package/dist/{QHEXOE3Y.js → JI3XNGXO.js} +3 -27
- package/dist/JI3XNGXO.js.map +1 -0
- package/dist/{EPHLTMJZ.js → JSG7MGHH.js} +3 -3
- package/dist/{EPHLTMJZ.js.map → JSG7MGHH.js.map} +1 -1
- package/dist/{JH2I4JGJ.js → JXKVPYCE.js} +3 -3
- package/dist/{JH2I4JGJ.js.map → JXKVPYCE.js.map} +1 -1
- package/dist/{4VLNRPYZ.js → K2SFNQJC.js} +5 -5
- package/dist/{4VLNRPYZ.js.map → K2SFNQJC.js.map} +1 -1
- package/dist/{H7FW24YI.js → KBZ6YXX4.js} +3 -3
- package/dist/{H7FW24YI.js.map → KBZ6YXX4.js.map} +1 -1
- package/dist/{ZF6ASBPX.js → KH7RP6Q4.js} +3 -3
- package/dist/{ZF6ASBPX.js.map → KH7RP6Q4.js.map} +1 -1
- package/dist/{AV2FN74T.js → KTNEUXUI.js} +4 -4
- package/dist/{AV2FN74T.js.map → KTNEUXUI.js.map} +1 -1
- package/dist/{D3AV6J7R.js → LL7Z56UN.js} +3 -3
- package/dist/{D3AV6J7R.js.map → LL7Z56UN.js.map} +1 -1
- package/dist/{AYAFFPBV.js → MFVQ6EHM.js} +3 -3
- package/dist/{AYAFFPBV.js.map → MFVQ6EHM.js.map} +1 -1
- package/dist/{U7ISOK6B.js → NKXEPWZV.js} +3 -3
- package/dist/{U7ISOK6B.js.map → NKXEPWZV.js.map} +1 -1
- package/dist/{P3A2XIFY.js → NS763D57.js} +3 -3
- package/dist/{P3A2XIFY.js.map → NS763D57.js.map} +1 -1
- package/dist/{3UD2GTXW.js → PGQCNYFD.js} +3 -3
- package/dist/{3UD2GTXW.js.map → PGQCNYFD.js.map} +1 -1
- package/dist/{2UWZKS5E.js → Q3RL6UXD.js} +4 -4
- package/dist/{2UWZKS5E.js.map → Q3RL6UXD.js.map} +1 -1
- package/dist/{5KFMHJZB.js → QYQWHMQM.js} +3 -3
- package/dist/{5KFMHJZB.js.map → QYQWHMQM.js.map} +1 -1
- package/dist/{BJXKGZ5Y.js → QZJONP6W.js} +3 -3
- package/dist/{BJXKGZ5Y.js.map → QZJONP6W.js.map} +1 -1
- package/dist/{X66QZBHT.js → SLTAV2JF.js} +9 -2
- package/dist/SLTAV2JF.js.map +1 -0
- package/dist/{JV2DWUBW.js → SMLSAWCA.js} +48 -4
- package/dist/SMLSAWCA.js.map +1 -0
- package/dist/{RQXQCK22.js → UBHUOSK3.js} +3 -3
- package/dist/{RQXQCK22.js.map → UBHUOSK3.js.map} +1 -1
- package/dist/{OMRF3GH2.js → UO7AO4TN.js} +3 -3
- package/dist/{OMRF3GH2.js.map → UO7AO4TN.js.map} +1 -1
- package/dist/{R26MH4UH.js → UQMKPY2S.js} +3 -3
- package/dist/{R26MH4UH.js.map → UQMKPY2S.js.map} +1 -1
- package/dist/{HU7X7G5L.js → WSLU3JGO.js} +3 -3
- package/dist/{HU7X7G5L.js.map → WSLU3JGO.js.map} +1 -1
- package/dist/{WIQFSNER.js → XINHRIWA.js} +3 -3
- package/dist/{WIQFSNER.js.map → XINHRIWA.js.map} +1 -1
- package/dist/{PHVMGN7T.js → ZGWBZC76.js} +3 -3
- package/dist/{PHVMGN7T.js.map → ZGWBZC76.js.map} +1 -1
- package/dist/{AE56UC5I.js → ZPOY5WJ2.js} +3 -3
- package/dist/{AE56UC5I.js.map → ZPOY5WJ2.js.map} +1 -1
- package/dist/amulet.d.ts +7 -0
- package/dist/amulet.d.ts.map +1 -0
- package/dist/amulet.js +4 -0
- package/dist/amulet.js.map +1 -0
- package/dist/auth/index.js +1 -1
- package/dist/client/canton-client.d.ts +12 -0
- package/dist/client/canton-client.d.ts.map +1 -1
- package/dist/client/canton-client.js +138 -138
- package/dist/client/index.js +140 -139
- package/dist/client/interface.d.ts +12 -0
- package/dist/client/interface.d.ts.map +1 -1
- package/dist/client/utils.d.ts.map +1 -1
- package/dist/client/utils.js +2 -1
- package/dist/crypto.d.ts +23 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +4 -0
- package/dist/crypto.js.map +1 -0
- package/dist/daml-serde.d.ts +73 -0
- package/dist/daml-serde.d.ts.map +1 -0
- package/dist/daml-serde.js +4 -0
- package/dist/daml-serde.js.map +1 -0
- package/dist/events.d.ts +9 -36
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +150 -147
- package/dist/open-api/apis/DefaultApi.js +137 -137
- package/dist/open-api/apis/index.js +137 -137
- package/dist/open-api/index.js +137 -137
- package/dist/open-api/models/Command.js +3 -3
- package/dist/open-api/models/Command1.js +2 -2
- package/dist/open-api/models/Completion.js +3 -3
- package/dist/open-api/models/Completion1.js +3 -3
- package/dist/open-api/models/CompletionResponse.js +7 -7
- package/dist/open-api/models/CompletionResponseOneOf.js +3 -3
- package/dist/open-api/models/CompletionStreamResponse.js +7 -7
- package/dist/open-api/models/CreateUserRequest.js +10 -10
- package/dist/open-api/models/CumulativeFilter.js +2 -2
- package/dist/open-api/models/DeduplicationPeriod.js +1 -1
- package/dist/open-api/models/DeduplicationPeriod1.js +1 -1
- package/dist/open-api/models/DeduplicationPeriod2.js +3 -3
- package/dist/open-api/models/EventFormat.js +2 -2
- package/dist/open-api/models/FeaturesDescriptor.js +2 -2
- package/dist/open-api/models/Filters.js +2 -2
- package/dist/open-api/models/GetActiveContractsRequest.js +2 -2
- package/dist/open-api/models/GetEventsByContractIdRequest.js +2 -2
- package/dist/open-api/models/GetLedgerApiVersionResponse.js +3 -3
- package/dist/open-api/models/GetTransactionByIdRequest.js +2 -2
- package/dist/open-api/models/GetTransactionByOffsetRequest.js +2 -2
- package/dist/open-api/models/GetUpdateByIdRequest.js +2 -2
- package/dist/open-api/models/GetUpdateByOffsetRequest.js +2 -2
- package/dist/open-api/models/GetUpdatesRequest.js +2 -2
- package/dist/open-api/models/GrantUserRightsRequest.js +10 -10
- package/dist/open-api/models/GrantUserRightsResponse.js +10 -10
- package/dist/open-api/models/IdentifierFilter.js +2 -2
- package/dist/open-api/models/JsCommands.js +5 -5
- package/dist/open-api/models/JsContractEntry.js +3 -3
- package/dist/open-api/models/JsExecuteSubmissionAndWaitForTransactionRequest.js +7 -7
- package/dist/open-api/models/JsExecuteSubmissionAndWaitRequest.js +5 -5
- package/dist/open-api/models/JsExecuteSubmissionRequest.js +5 -5
- package/dist/open-api/models/JsGetActiveContractsResponse.js +4 -4
- package/dist/open-api/models/JsGetUpdateResponse.js +13 -13
- package/dist/open-api/models/JsGetUpdateTreesResponse.js +5 -5
- package/dist/open-api/models/JsGetUpdatesResponse.js +13 -13
- package/dist/open-api/models/JsPrepareSubmissionRequest.js +5 -5
- package/dist/open-api/models/JsReassignment.js +1 -1
- package/dist/open-api/models/JsReassignmentEvent.js +1 -1
- package/dist/open-api/models/JsSubmitAndWaitForReassignmentResponse.js +1 -1
- package/dist/open-api/models/JsSubmitAndWaitForTransactionRequest.js +9 -9
- package/dist/open-api/models/JsTopologyTransaction.js +6 -6
- package/dist/open-api/models/Kind.js +8 -8
- package/dist/open-api/models/ListUserRightsResponse.js +10 -10
- package/dist/open-api/models/Operation.js +4 -4
- package/dist/open-api/models/Reassignment.js +1 -1
- package/dist/open-api/models/Reassignment1.js +1 -1
- package/dist/open-api/models/ReassignmentCommand.js +3 -3
- package/dist/open-api/models/ReassignmentCommands.js +4 -4
- package/dist/open-api/models/RevokeUserRightsRequest.js +10 -10
- package/dist/open-api/models/RevokeUserRightsResponse.js +10 -10
- package/dist/open-api/models/Right.js +9 -9
- package/dist/open-api/models/SubmitAndWaitForReassignmentRequest.js +7 -7
- package/dist/open-api/models/SubmitReassignmentRequest.js +5 -5
- package/dist/open-api/models/TopologyEvent.js +5 -5
- package/dist/open-api/models/TopologyEventEvent.js +4 -4
- package/dist/open-api/models/TopologyTransaction.js +7 -7
- package/dist/open-api/models/TransactionFilter.js +2 -2
- package/dist/open-api/models/TransactionFormat.js +2 -2
- package/dist/open-api/models/Update.js +12 -12
- package/dist/open-api/models/Update1.js +4 -4
- package/dist/open-api/models/Update1OneOf1.js +1 -1
- package/dist/open-api/models/UpdateFormat.js +2 -2
- package/dist/open-api/models/UpdateOneOf1.js +1 -1
- package/dist/open-api/models/UpdateOneOf2.js +8 -8
- package/dist/open-api/models/UpdateVettedPackagesRequest.js +6 -6
- package/dist/open-api/models/VettedPackagesChange.js +5 -5
- package/dist/open-api/models/index.js +136 -136
- package/dist/provider.d.ts +9 -27
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +140 -140
- package/dist/sdk/canton-sdk.d.ts +7 -0
- package/dist/sdk/canton-sdk.d.ts.map +1 -1
- package/dist/sdk/canton-sdk.js +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/transaction.d.ts +64 -6
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +1 -1
- package/package.json +13 -10
- package/src/amulet.ts +28 -0
- package/src/client/canton-client.ts +60 -1
- package/src/client/interface.ts +16 -0
- package/src/client/utils.ts +1 -6
- package/src/crypto.ts +42 -0
- package/src/daml-serde.ts +182 -0
- package/src/events.ts +31 -155
- package/src/index.ts +3 -0
- package/src/provider.ts +12 -82
- package/src/sdk/canton-sdk.ts +13 -0
- package/src/transaction.ts +4 -0
- package/test/crypto.test.ts +52 -0
- package/test/daml-serde.test.ts +140 -0
- package/test/mocks/scripts/capture-disclosure.ts +5 -2
- package/test/mocks/scripts/capture-external-requests.ts +5 -2
- package/test/mocks/scripts/capture-unhappy-paths.ts +5 -2
- package/test/provider.test.ts +47 -36
- package/dist/GXJEEYPP.js +0 -104
- package/dist/GXJEEYPP.js.map +0 -1
- package/dist/HNZRSDTR.js.map +0 -1
- package/dist/JV2DWUBW.js.map +0 -1
- package/dist/PSB6BQFH.js.map +0 -1
- package/dist/QHEXOE3Y.js.map +0 -1
- package/dist/X66QZBHT.js.map +0 -1
package/dist/transaction.d.ts
CHANGED
|
@@ -86,12 +86,66 @@ export declare const cantonTransactionSchema: z.ZodObject<{
|
|
|
86
86
|
partyToSenderEntity: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
87
87
|
}, z.core.$strip>;
|
|
88
88
|
}, z.core.$strip>;
|
|
89
|
+
export declare const cantonTransactionWithResultSchema: z.ZodObject<{
|
|
90
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
91
|
+
chainName: z.ZodString;
|
|
92
|
+
timestamps: z.ZodObject<{
|
|
93
|
+
created: z.ZodNumber;
|
|
94
|
+
nonceAcquired: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
signed: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
sent: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
confirmed: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
type: z.ZodOptional<z.ZodString>;
|
|
100
|
+
parallelizingKey: z.ZodOptional<z.ZodString>;
|
|
101
|
+
populatedTransaction: z.ZodObject<{
|
|
102
|
+
unresolvedCommands: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
103
|
+
createCommand: z.ZodObject<{
|
|
104
|
+
templateId: z.ZodString;
|
|
105
|
+
createArguments: z.ZodAny;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
108
|
+
exerciseCommand: z.ZodObject<{
|
|
109
|
+
templateId: z.ZodString;
|
|
110
|
+
contractId: z.ZodString;
|
|
111
|
+
choice: z.ZodString;
|
|
112
|
+
choiceArgument: z.ZodAny;
|
|
113
|
+
}, z.core.$strip>;
|
|
114
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
115
|
+
createAndExerciseCommand: z.ZodObject<{
|
|
116
|
+
templateId: z.ZodString;
|
|
117
|
+
createArguments: z.ZodAny;
|
|
118
|
+
choice: z.ZodString;
|
|
119
|
+
choiceArgument: z.ZodAny;
|
|
120
|
+
}, z.core.$strip>;
|
|
121
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
122
|
+
exerciseByKeyCommand: z.ZodObject<{
|
|
123
|
+
templateId: z.ZodString;
|
|
124
|
+
contractKey: z.ZodAny;
|
|
125
|
+
choice: z.ZodString;
|
|
126
|
+
choiceArgument: z.ZodAny;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
}, z.core.$strip>]>>;
|
|
129
|
+
unresolvedDisclosedContracts: z.ZodArray<z.ZodObject<{
|
|
130
|
+
templateId: z.ZodOptional<z.ZodString>;
|
|
131
|
+
contractId: z.ZodString;
|
|
132
|
+
createdEventBlob: z.ZodString;
|
|
133
|
+
synchronizerId: z.ZodString;
|
|
134
|
+
}, z.core.$strip>>;
|
|
135
|
+
actAs: z.ZodArray<z.ZodString>;
|
|
136
|
+
partyToSenderEntity: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
} & {
|
|
139
|
+
result: typeof import("@layerzerolabs/common-chain-model").transactionResultSchema;
|
|
140
|
+
}, z.core.$strip>;
|
|
89
141
|
/**
|
|
90
142
|
* Assigned transaction includes the inflight transaction data.
|
|
91
143
|
*/
|
|
92
144
|
export declare const cantonAssignedTransactionSchema: z.ZodObject<{
|
|
93
145
|
senderEntityName: z.ZodString;
|
|
94
|
-
nonce: z.ZodNumber
|
|
146
|
+
nonce: z.ZodNumber /**
|
|
147
|
+
* Canton transaction schema for Daml Ledger API commands.
|
|
148
|
+
*/;
|
|
95
149
|
inflightTransaction: z.ZodOptional<z.ZodObject<{
|
|
96
150
|
preparedTransaction: z.ZodString;
|
|
97
151
|
preparedTransactionHash: z.ZodString;
|
|
@@ -200,7 +254,9 @@ export declare const cantonSignedTransactionSchema: z.ZodObject<{
|
|
|
200
254
|
}, z.core.$strip>>;
|
|
201
255
|
}, z.core.$strip>;
|
|
202
256
|
senderEntityName: z.ZodString;
|
|
203
|
-
nonce: z.ZodNumber
|
|
257
|
+
nonce: z.ZodNumber /**
|
|
258
|
+
* Canton transaction schema for Daml Ledger API commands.
|
|
259
|
+
*/;
|
|
204
260
|
inflightTransaction: z.ZodOptional<z.ZodObject<{
|
|
205
261
|
preparedTransaction: z.ZodString;
|
|
206
262
|
preparedTransactionHash: z.ZodString;
|
|
@@ -264,16 +320,16 @@ export declare const cantonSignedTransactionSchema: z.ZodObject<{
|
|
|
264
320
|
* Mined transaction with confirmation result.
|
|
265
321
|
*/
|
|
266
322
|
export declare const cantonMinedTransactionSchema: z.ZodObject<{
|
|
267
|
-
result: z.ZodDiscriminatedUnion
|
|
323
|
+
result: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
268
324
|
type: z.ZodLiteral<"success">;
|
|
269
325
|
minedTxHash: z.ZodString;
|
|
270
326
|
}, z.core.$strip>, z.ZodObject<{
|
|
271
|
-
type: z.ZodLiteral
|
|
327
|
+
type: z.ZodLiteral /** Hashing scheme version used */<"error">;
|
|
272
328
|
error: z.ZodString;
|
|
273
329
|
}, z.core.$strip>, z.ZodObject<{
|
|
274
330
|
type: z.ZodLiteral<"indeterminate">;
|
|
275
331
|
meta: z.ZodAny;
|
|
276
|
-
}, z.core.$strip
|
|
332
|
+
}, z.core.$strip /** Command ID for tracking */>], "type">;
|
|
277
333
|
inflightTransaction: z.ZodObject<{
|
|
278
334
|
preparedTransaction: z.ZodString;
|
|
279
335
|
preparedTransactionHash: z.ZodString;
|
|
@@ -329,7 +385,9 @@ export declare const cantonMinedTransactionSchema: z.ZodObject<{
|
|
|
329
385
|
}, z.core.$strip>>;
|
|
330
386
|
}, z.core.$strip>;
|
|
331
387
|
senderEntityName: z.ZodString;
|
|
332
|
-
nonce: z.ZodNumber
|
|
388
|
+
nonce: z.ZodNumber /**
|
|
389
|
+
* Canton transaction schema for Daml Ledger API commands.
|
|
390
|
+
*/;
|
|
333
391
|
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
334
392
|
chainName: z.ZodString;
|
|
335
393
|
timestamps: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildCantonTransaction, cantonAssignedTransactionSchema, cantonCommandSchema, cantonDisclosedContractSchema, cantonMinedTransactionSchema, cantonSignedTransactionSchema, cantonTransactionSchema } from './
|
|
1
|
+
export { buildCantonTransaction, cantonAssignedTransactionSchema, cantonCommandSchema, cantonDisclosedContractSchema, cantonMinedTransactionSchema, cantonSignedTransactionSchema, cantonTransactionSchema, cantonTransactionWithResultSchema } from './EYLCZMM4.js';
|
|
2
2
|
import './VUOMXK5T.js';
|
|
3
3
|
//# sourceMappingURL=transaction.js.map
|
|
4
4
|
//# sourceMappingURL=transaction.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/common-canton",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.111",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Canton VM client and utilities",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
"@daml/types": "3.4.8",
|
|
19
19
|
"@grpc/grpc-js": "^1.12.0",
|
|
20
20
|
"@mojotech/json-type-validation": "^3.1.0",
|
|
21
|
+
"@noble/hashes": "^1.8.0",
|
|
22
|
+
"@noble/secp256k1": "1.7.1",
|
|
21
23
|
"@protobuf-ts/grpc-transport": "^2.9.4",
|
|
22
24
|
"es-toolkit": "^1.39.10",
|
|
23
25
|
"zod": "4.3.5",
|
|
24
|
-
"@layerzerolabs/common-
|
|
25
|
-
"@layerzerolabs/common-
|
|
26
|
-
"@layerzerolabs/
|
|
26
|
+
"@layerzerolabs/common-chain-model": "0.2.111",
|
|
27
|
+
"@layerzerolabs/common-error-utils": "0.2.111",
|
|
28
|
+
"@layerzerolabs/common-encoding-utils": "0.2.111",
|
|
29
|
+
"@layerzerolabs/typescript-utils": "0.2.111"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"@types/node": "^22.18.6",
|
|
@@ -32,12 +35,12 @@
|
|
|
32
35
|
"tsup": "^8.4.0",
|
|
33
36
|
"typescript": "^5.8.2",
|
|
34
37
|
"vitest": "^3.2.6",
|
|
35
|
-
"@layerzerolabs/eslint-configuration": "^0.2.
|
|
36
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
37
|
-
"@layerzerolabs/typescript-configuration": "0.2.
|
|
38
|
-
"@layerzerolabs/
|
|
39
|
-
"@layerzerolabs/
|
|
40
|
-
"@layerzerolabs/
|
|
38
|
+
"@layerzerolabs/eslint-configuration": "^0.2.111",
|
|
39
|
+
"@layerzerolabs/tsup-configuration": "0.2.111",
|
|
40
|
+
"@layerzerolabs/typescript-configuration": "0.2.111",
|
|
41
|
+
"@layerzerolabs/ver-signer-adapter": "0.2.111",
|
|
42
|
+
"@layerzerolabs/vitest-configuration": "0.2.111",
|
|
43
|
+
"@layerzerolabs/vm-tooling-canton": "0.2.111"
|
|
41
44
|
},
|
|
42
45
|
"publishConfig": {
|
|
43
46
|
"access": "restricted",
|
package/src/amulet.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const AMULET_DECIMAL_PLACES = 10n;
|
|
4
|
+
|
|
5
|
+
const amuletPayloadSchema = z.object({
|
|
6
|
+
amount: z.object({ initialAmount: z.string() }),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parses a DAML Decimal string (e.g. `"42.5000000000"`, `"-1.5"`) into a bigint
|
|
11
|
+
* scaled by 10^10. Fractional digits beyond ten places are truncated towards zero.
|
|
12
|
+
*/
|
|
13
|
+
export const parseAmuletDecimal = (value: string): bigint => {
|
|
14
|
+
const [integer, fraction = ''] = value.replace(/^-/, '').split('.');
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
(value.startsWith('-') ? -1n : 1n) *
|
|
18
|
+
(BigInt(integer || '0') * 10n ** AMULET_DECIMAL_PLACES +
|
|
19
|
+
BigInt(
|
|
20
|
+
fraction
|
|
21
|
+
.slice(0, Number(AMULET_DECIMAL_PLACES))
|
|
22
|
+
.padEnd(Number(AMULET_DECIMAL_PLACES), '0'),
|
|
23
|
+
))
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const parseAmuletAmount = (createArgument: unknown): bigint =>
|
|
28
|
+
parseAmuletDecimal(amuletPayloadSchema.parse(createArgument).amount.initialAmount);
|
|
@@ -892,7 +892,43 @@ export class CantonClient implements ICantonClient {
|
|
|
892
892
|
templateIds: string[],
|
|
893
893
|
opts?: { limit?: number },
|
|
894
894
|
): Promise<JsActiveContract[]> {
|
|
895
|
-
|
|
895
|
+
return this.#fetchActiveContracts(
|
|
896
|
+
parties,
|
|
897
|
+
offset,
|
|
898
|
+
this.#buildCumulativeFilters(templateIds),
|
|
899
|
+
opts,
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Query active contracts visible to any of the given parties that implement
|
|
905
|
+
* the given interfaces.
|
|
906
|
+
*
|
|
907
|
+
* @param parties - Parties to query as (for visibility)
|
|
908
|
+
* @param offset - Ledger offset for the snapshot
|
|
909
|
+
* @param interfaceIds - Interface IDs to filter by (e.g. "#package:Module:Interface")
|
|
910
|
+
* @param opts.limit - Maximum number of contracts to return
|
|
911
|
+
*/
|
|
912
|
+
async queryActiveContractsByInterface(
|
|
913
|
+
parties: string[],
|
|
914
|
+
offset: number,
|
|
915
|
+
interfaceIds: string[],
|
|
916
|
+
opts?: { limit?: number },
|
|
917
|
+
): Promise<JsActiveContract[]> {
|
|
918
|
+
return this.#fetchActiveContracts(
|
|
919
|
+
parties,
|
|
920
|
+
offset,
|
|
921
|
+
this.#buildInterfaceCumulativeFilters(interfaceIds),
|
|
922
|
+
opts,
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
async #fetchActiveContracts(
|
|
927
|
+
parties: string[],
|
|
928
|
+
offset: number,
|
|
929
|
+
cumulativeFilter: CumulativeFilter[],
|
|
930
|
+
opts?: { limit?: number },
|
|
931
|
+
): Promise<JsActiveContract[]> {
|
|
896
932
|
const filtersByParty = Object.fromEntries(
|
|
897
933
|
parties.map((party) => [party, { cumulative: cumulativeFilter }]),
|
|
898
934
|
);
|
|
@@ -982,6 +1018,29 @@ export class CantonClient implements ICantonClient {
|
|
|
982
1018
|
];
|
|
983
1019
|
}
|
|
984
1020
|
|
|
1021
|
+
/**
|
|
1022
|
+
* Build cumulative filters for interface-based ACS queries.
|
|
1023
|
+
* If interfaceIds provided, filters by those interfaces; otherwise uses wildcard.
|
|
1024
|
+
*/
|
|
1025
|
+
#buildInterfaceCumulativeFilters(interfaceIds?: string[]): CumulativeFilter[] {
|
|
1026
|
+
if (interfaceIds?.length) {
|
|
1027
|
+
return interfaceIds.map((interfaceId) => ({
|
|
1028
|
+
identifierFilter: {
|
|
1029
|
+
interfaceFilter: {
|
|
1030
|
+
value: {
|
|
1031
|
+
interfaceId,
|
|
1032
|
+
includeInterfaceView: true,
|
|
1033
|
+
includeCreatedEventBlob: false,
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
},
|
|
1037
|
+
}));
|
|
1038
|
+
}
|
|
1039
|
+
return [
|
|
1040
|
+
{ identifierFilter: { wildcardFilter: { value: { includeCreatedEventBlob: false } } } },
|
|
1041
|
+
];
|
|
1042
|
+
}
|
|
1043
|
+
|
|
985
1044
|
/**
|
|
986
1045
|
* Build the standard update format for fetching transactions.
|
|
987
1046
|
*/
|
package/src/client/interface.ts
CHANGED
|
@@ -269,6 +269,22 @@ export interface ICantonClient {
|
|
|
269
269
|
opts?: { limit?: number },
|
|
270
270
|
): Promise<JsActiveContract[]>;
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Query active contracts visible to any of the given parties that implement
|
|
274
|
+
* the given interfaces.
|
|
275
|
+
*
|
|
276
|
+
* @param parties - Parties to query as (for visibility)
|
|
277
|
+
* @param offset - Ledger offset to query at
|
|
278
|
+
* @param interfaceIds - Interface IDs to filter by (e.g., "#package:Module:Interface")
|
|
279
|
+
* @param opts.limit - Maximum number of contracts to return
|
|
280
|
+
*/
|
|
281
|
+
queryActiveContractsByInterface(
|
|
282
|
+
parties: string[],
|
|
283
|
+
offset: number,
|
|
284
|
+
interfaceIds: string[],
|
|
285
|
+
opts?: { limit?: number },
|
|
286
|
+
): Promise<JsActiveContract[]>;
|
|
287
|
+
|
|
272
288
|
/**
|
|
273
289
|
* Stream updates from a given offset.
|
|
274
290
|
*
|
package/src/client/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
|
|
3
|
+
import { SECP256K1_SPKI_DER_HEADER } from '../crypto';
|
|
3
4
|
import type { CantonTransaction, CantonUpdate } from './interface';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -10,12 +11,6 @@ export function extractTransactions(updates: CantonUpdate[]): CantonTransaction[
|
|
|
10
11
|
return updates.flatMap((update) => ('Transaction' in update ? [update.Transaction.value] : []));
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
// DER header for secp256k1 SubjectPublicKeyInfo (23 bytes).
|
|
14
|
-
const SECP256K1_SPKI_DER_HEADER = new Uint8Array([
|
|
15
|
-
0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b,
|
|
16
|
-
0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00,
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
14
|
const HASH_PURPOSE_PUBLIC_KEY_FINGERPRINT = 12;
|
|
20
15
|
const MULTIHASH_SHA256_PREFIX = new Uint8Array([0x12, 0x20]);
|
|
21
16
|
|
package/src/crypto.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-free secp256k1 / DER helpers shared across Canton packages. Kept in a
|
|
3
|
+
* dependency-light module (no ledger client, no ethers) so pure encoding/signing
|
|
4
|
+
* SDKs can reuse it without pulling the gRPC client graph.
|
|
5
|
+
*
|
|
6
|
+
* DER signature encoding reuses `@noble/secp256k1` rather than hand-rolling ASN.1.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as secp256k1 from '@noble/secp256k1';
|
|
10
|
+
|
|
11
|
+
import { trim0x } from '@layerzerolabs/common-encoding-utils';
|
|
12
|
+
|
|
13
|
+
/** DER header for secp256k1 SubjectPublicKeyInfo (23 bytes), up to the `00` bit-string pad. */
|
|
14
|
+
export const SECP256K1_SPKI_DER_HEADER = new Uint8Array([
|
|
15
|
+
0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b,
|
|
16
|
+
0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00,
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
/** Hex form of {@link SECP256K1_SPKI_DER_HEADER} (lowercase, no `0x`). */
|
|
20
|
+
export const SECP256K1_SPKI_DER_HEADER_HEX = Buffer.from(SECP256K1_SPKI_DER_HEADER).toString('hex');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Wrap an uncompressed `0x04‖X‖Y` secp256k1 public key as hex-encoded SPKI-DER
|
|
24
|
+
* (the form the Canton ledger's `MultiSig.SignerSignature` carries).
|
|
25
|
+
*/
|
|
26
|
+
export function publicKeyToSpkiDer(uncompressedPublicKey: string): string {
|
|
27
|
+
const body = trim0x(uncompressedPublicKey).toLowerCase();
|
|
28
|
+
if (body.length !== 130 || !body.startsWith('04')) {
|
|
29
|
+
throw new Error('Expected an uncompressed (65-byte, 0x04…) secp256k1 public key');
|
|
30
|
+
}
|
|
31
|
+
return SECP256K1_SPKI_DER_HEADER_HEX + body;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* DER-encode an ECDSA `(r, s)` signature as `SEQUENCE { INTEGER r, INTEGER s }`
|
|
36
|
+
* (lowercase hex), via `@noble/secp256k1` so the ASN.1 encoding is not hand-rolled.
|
|
37
|
+
* `r` / `s` are accepted as hex (with or without `0x`) and zero-padded to 32 bytes.
|
|
38
|
+
*/
|
|
39
|
+
export function derEncodeSignature(r: string, s: string): string {
|
|
40
|
+
const compact = trim0x(r).padStart(64, '0') + trim0x(s).padStart(64, '0');
|
|
41
|
+
return secp256k1.Signature.fromCompact(compact).toDERHex();
|
|
42
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level serialization helpers that are byte-for-byte mirrors of the DAML
|
|
3
|
+
* `Serde.Serde` module and the relevant `show` instances. Everything here operates
|
|
4
|
+
* on **hex-encoded byte strings** (lowercase, no `0x` prefix) or DAML primitive
|
|
5
|
+
* renderings, so an off-chain encoder produces the exact bytes the ledger verifies.
|
|
6
|
+
*
|
|
7
|
+
* Kept dependency-light (no ledger client) so encoding/signing SDKs can reuse it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
import { bigIntToHex, bytesToHex, hexToBytes, trim0x } from '@layerzerolabs/common-encoding-utils';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A 64-bit integer field (oneSigId / nonce / threshold / count / signed `Int`).
|
|
17
|
+
* A `number` must be a safe integer — larger values have already lost precision as
|
|
18
|
+
* a float, so a bigint is required (mirrors the {@link toBigInt} runtime guard).
|
|
19
|
+
*/
|
|
20
|
+
export const IntLikeSchema = z
|
|
21
|
+
.union([z.bigint(), z.number()])
|
|
22
|
+
.refine((value) => typeof value === 'bigint' || Number.isSafeInteger(value), {
|
|
23
|
+
message: 'number must be a safe integer; pass a bigint for values beyond MAX_SAFE_INTEGER',
|
|
24
|
+
});
|
|
25
|
+
export type IntLike = z.infer<typeof IntLikeSchema>;
|
|
26
|
+
|
|
27
|
+
const HEX_DIGITS = /^[0-9a-fA-F]*$/;
|
|
28
|
+
|
|
29
|
+
/** Convert an {@link IntLike} to a `bigint`, rejecting unsafe-integer `number`s. */
|
|
30
|
+
export function toBigInt(value: IntLike, label = 'value'): bigint {
|
|
31
|
+
if (typeof value === 'bigint') return value;
|
|
32
|
+
// `number` only represents integers exactly up to MAX_SAFE_INTEGER; a larger
|
|
33
|
+
// value has already lost precision as a float, so reject it and require a
|
|
34
|
+
// bigint rather than encoding a silently-rounded oneSigId / nonce / Int.
|
|
35
|
+
if (!Number.isSafeInteger(value)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`${label} must be a safe integer; pass a bigint for values beyond Number.MAX_SAFE_INTEGER, got ${value}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return BigInt(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unicode code-point count of a string — the measure DAML's `T.length` uses for
|
|
45
|
+
* `lengthPrefix`. For the ASCII values encoded here this equals the byte count,
|
|
46
|
+
* but we count code points (not UTF-16 units) so astral characters are measured
|
|
47
|
+
* the same way DAML measures them.
|
|
48
|
+
*/
|
|
49
|
+
export function codePointLength(value: string): number {
|
|
50
|
+
let count = 0;
|
|
51
|
+
for (const _ of value) count++;
|
|
52
|
+
return count;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** DAML `show` of an `Int`: a base-10 string, negatives prefixed with `-`. */
|
|
56
|
+
export function showInt(value: IntLike): string {
|
|
57
|
+
return toBigInt(value, 'int').toString(10);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** DAML `show` of a `Bool`: `True` / `False` (capitalized). */
|
|
61
|
+
export function showBool(value: boolean): string {
|
|
62
|
+
return value ? 'True' : 'False';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* DAML `show` of a `Decimal` (Numeric 10): a fixed-point decimal with trailing
|
|
67
|
+
* zeros stripped but always at least one fractional digit (`1.0`, `2.5`, `100.0`).
|
|
68
|
+
* Accepts a string (recommended, exact) or a JS number. Rejects scientific
|
|
69
|
+
* notation and more than 10 fractional digits (DAML Decimal scale).
|
|
70
|
+
*/
|
|
71
|
+
export function formatDamlDecimal(value: string | number): string {
|
|
72
|
+
const raw = (typeof value === 'number' ? numberToPlainString(value) : value).trim();
|
|
73
|
+
|
|
74
|
+
let negative = false;
|
|
75
|
+
let body = raw;
|
|
76
|
+
if (body.startsWith('-')) {
|
|
77
|
+
negative = true;
|
|
78
|
+
body = body.slice(1);
|
|
79
|
+
} else if (body.startsWith('+')) {
|
|
80
|
+
body = body.slice(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const [intPartRaw, fracPartRaw = '', ...rest] = body.split('.');
|
|
84
|
+
if (rest.length > 0 || !/^\d*$/.test(intPartRaw) || !/^\d*$/.test(fracPartRaw)) {
|
|
85
|
+
throw new Error(`Invalid decimal: ${raw}`);
|
|
86
|
+
}
|
|
87
|
+
if (fracPartRaw.length > 10) {
|
|
88
|
+
throw new Error(`Decimal exceeds 10 fractional digits (DAML Decimal scale): ${raw}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const intPart = intPartRaw.replace(/^0+(?=\d)/, '') || '0';
|
|
92
|
+
const fracPart = fracPartRaw.replace(/0+$/, '') || '0';
|
|
93
|
+
const isZero = intPart === '0' && fracPart === '0';
|
|
94
|
+
return `${negative && !isZero ? '-' : ''}${intPart}.${fracPart}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function numberToPlainString(value: number): string {
|
|
98
|
+
if (!Number.isFinite(value)) throw new Error(`Decimal must be finite, got ${value}`);
|
|
99
|
+
// Reject exponential notation rather than guessing the intended scale.
|
|
100
|
+
const asString = value.toString();
|
|
101
|
+
if (/e/i.test(asString)) {
|
|
102
|
+
throw new Error(`Pass decimals with many digits as strings, not numbers: ${asString}`);
|
|
103
|
+
}
|
|
104
|
+
return asString;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Hex-encode strict-ASCII text, two lowercase hex digits per character. Rejects
|
|
109
|
+
* code points >= 128: DAML encodes them as one byte while UTF-8 uses two, which
|
|
110
|
+
* would produce different hashes, so non-ASCII is rejected rather than encoded
|
|
111
|
+
* ambiguously (mirrors DAML `textToHex`).
|
|
112
|
+
*/
|
|
113
|
+
export function textToHex(value: string): string {
|
|
114
|
+
let out = '';
|
|
115
|
+
for (const char of value) {
|
|
116
|
+
const cp = char.codePointAt(0)!;
|
|
117
|
+
if (cp >= 128) {
|
|
118
|
+
throw new Error(`Non-ASCII character (code point ${cp}) cannot be encoded`);
|
|
119
|
+
}
|
|
120
|
+
out += cp.toString(16).padStart(2, '0');
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Minimal (unpadded) lowercase hex of a non-negative integer: `0` for zero, no
|
|
127
|
+
* leading zeros otherwise. Use `padLeft` on top when a fixed width is needed
|
|
128
|
+
* (mirrors DAML `intToHex`).
|
|
129
|
+
*/
|
|
130
|
+
export function intToHex(value: IntLike): string {
|
|
131
|
+
// `bigIntToHex` yields minimal `0x`-hex and rejects negatives; drop the prefix.
|
|
132
|
+
return trim0x(bigIntToHex(toBigInt(value, 'intToHex')));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Left-pad a hex string with `0` to `targetLen` characters (right-aligned, e.g.
|
|
137
|
+
* uint256). Throws if `value` is already longer than `targetLen`: an oversize
|
|
138
|
+
* value must be rejected, never silently kept full-length, so fixed-width fields
|
|
139
|
+
* stay positionally unambiguous (mirrors DAML `padLeft`).
|
|
140
|
+
*/
|
|
141
|
+
export function padLeft(targetLen: number, value: string): string {
|
|
142
|
+
if (value.length > targetLen) {
|
|
143
|
+
throw new Error(`Value of length ${value.length} exceeds pad width ${targetLen}`);
|
|
144
|
+
}
|
|
145
|
+
return value.padStart(targetLen, '0');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Assert that `value` is valid hex of exactly `expectedLen` characters (after
|
|
150
|
+
* stripping an optional `0x`), returning the stripped lowercase hex. Unlike
|
|
151
|
+
* padding, an off-length value is rejected rather than reshaped (mirrors DAML
|
|
152
|
+
* `assertHexLength`).
|
|
153
|
+
*/
|
|
154
|
+
export function assertHexLength(expectedLen: number, value: string): string {
|
|
155
|
+
const stripped = trim0x(value);
|
|
156
|
+
if (stripped.length % 2 !== 0 || stripped.length === 0 || !HEX_DIGITS.test(stripped)) {
|
|
157
|
+
throw new Error(`Invalid hex string: ${value}`);
|
|
158
|
+
}
|
|
159
|
+
if (stripped.length !== expectedLen) {
|
|
160
|
+
throw new Error(`Expected ${expectedLen} hex chars, got ${stripped.length}`);
|
|
161
|
+
}
|
|
162
|
+
return stripped.toLowerCase();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Whole seconds since the unix epoch for a `Date` (DAML `Time` → uint256 expiry). */
|
|
166
|
+
export function timeToUnixSeconds(time: Date): bigint {
|
|
167
|
+
return BigInt(Math.floor(time.getTime() / 1000));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* keccak256 of the bytes denoted by hex string `h`, returned as 64 lowercase hex
|
|
172
|
+
* chars (no `0x`). `h` must be a valid hex byte string (even length, `[0-9a-fA-F]`):
|
|
173
|
+
* a malformed input is rejected, never hashed as raw text, matching DAML's
|
|
174
|
+
* `keccak256 : BytesHex -> BytesHex` (which aborts on a malformed encoding).
|
|
175
|
+
*/
|
|
176
|
+
export function keccak256Hex(h: string): string {
|
|
177
|
+
const stripped = trim0x(h);
|
|
178
|
+
if (stripped.length % 2 !== 0 || !HEX_DIGITS.test(stripped)) {
|
|
179
|
+
throw new Error(`keccak256 input is not a valid hex byte string: ${h}`);
|
|
180
|
+
}
|
|
181
|
+
return bytesToHex(keccak_256(hexToBytes(stripped)));
|
|
182
|
+
}
|