@distrohelena/canton-typescript-sdk 0.1.2 → 0.1.4

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.
@@ -1,8 +1,9 @@
1
+ import { ExternalPartyCryptoKeyFormat } from "../core/types/external-party/external-party-crypto-key-format.js";
1
2
  export declare class CantonHashingClient {
2
3
  /** Computes a Canton multihash for the provided content and hash purpose. */
3
4
  computeHash(content: Uint8Array, purpose: number): Uint8Array;
4
5
  /** Computes a Canton multihash as lowercase hexadecimal for the provided content and hash purpose. */
5
6
  computeHashHex(content: Uint8Array, purpose: number): string;
6
7
  /** Computes the canonical Canton public-key fingerprint from serialized public key bytes. */
7
- computePublicKeyFingerprint(publicKey: Uint8Array): string;
8
+ computePublicKeyFingerprint(publicKey: Uint8Array, format?: ExternalPartyCryptoKeyFormat): string;
8
9
  }
@@ -1,5 +1,4 @@
1
- import { computeCantonHash, computeCantonHashHex, } from "../core/hashing/canton-hash.js";
2
- import { CantonHashPurpose } from "../core/types/canton-hash-purpose.js";
1
+ import { computeCantonHash, computeCantonHashHex, computeCantonPublicKeyFingerprint, } from "../core/hashing/canton-hash.js";
3
2
  export class CantonHashingClient {
4
3
  /** Computes a Canton multihash for the provided content and hash purpose. */
5
4
  computeHash(content, purpose) {
@@ -10,7 +9,7 @@ export class CantonHashingClient {
10
9
  return computeCantonHashHex(content, purpose);
11
10
  }
12
11
  /** Computes the canonical Canton public-key fingerprint from serialized public key bytes. */
13
- computePublicKeyFingerprint(publicKey) {
14
- return computeCantonHashHex(publicKey, CantonHashPurpose.publicKeyFingerprint);
12
+ computePublicKeyFingerprint(publicKey, format) {
13
+ return computeCantonPublicKeyFingerprint(publicKey, format) ?? "";
15
14
  }
16
15
  }
@@ -1,3 +1,3 @@
1
1
  export declare function computeCantonHash(content: Uint8Array, purpose: number): Uint8Array;
2
2
  export declare function computeCantonHashHex(content: Uint8Array, purpose: number): string;
3
- export declare function computeCantonPublicKeyFingerprint(publicKey: Uint8Array | undefined): string | undefined;
3
+ export declare function computeCantonPublicKeyFingerprint(publicKey: Uint8Array | undefined, format?: string): string | undefined;
@@ -1,6 +1,11 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { CantonHashPurpose } from "../types/canton-hash-purpose.js";
3
3
  const sha256MultihashPrefix = new Uint8Array([0x12, 0x20]);
4
+ const asn1SequenceTag = 0x30;
5
+ const asn1ObjectIdentifierTag = 0x06;
6
+ const asn1BitStringTag = 0x03;
7
+ const ed25519ObjectIdentifier = new Uint8Array([0x2b, 0x65, 0x70]);
8
+ const derX509SubjectPublicKeyInfoFormat = "derX509SubjectPublicKeyInfo";
4
9
  export function computeCantonHash(content, purpose) {
5
10
  const purposePrefix = Buffer.alloc(4);
6
11
  purposePrefix.writeUInt32BE(purpose, 0);
@@ -16,9 +21,99 @@ export function computeCantonHash(content, purpose) {
16
21
  export function computeCantonHashHex(content, purpose) {
17
22
  return Buffer.from(computeCantonHash(content, purpose)).toString("hex");
18
23
  }
19
- export function computeCantonPublicKeyFingerprint(publicKey) {
24
+ export function computeCantonPublicKeyFingerprint(publicKey, format) {
20
25
  if (publicKey === undefined || publicKey.length === 0) {
21
26
  return undefined;
22
27
  }
23
- return computeCantonHashHex(publicKey, CantonHashPurpose.publicKeyFingerprint);
28
+ return computeCantonHashHex(normalizePublicKeyForFingerprint(publicKey, format), CantonHashPurpose.publicKeyFingerprint);
29
+ }
30
+ function normalizePublicKeyForFingerprint(publicKey, format) {
31
+ if (format !== derX509SubjectPublicKeyInfoFormat) {
32
+ return publicKey;
33
+ }
34
+ return tryExtractEd25519PublicKeyFromSpki(publicKey) ?? publicKey;
35
+ }
36
+ function tryExtractEd25519PublicKeyFromSpki(spki) {
37
+ try {
38
+ const outer = readAsn1Element(spki, 0);
39
+ if (outer.tag !== asn1SequenceTag) {
40
+ return undefined;
41
+ }
42
+ const algorithm = readAsn1Element(spki, outer.contentOffset);
43
+ if (algorithm.tag !== asn1SequenceTag) {
44
+ return undefined;
45
+ }
46
+ const algorithmIdentifier = readAsn1Element(spki, algorithm.contentOffset);
47
+ if (algorithmIdentifier.tag !== asn1ObjectIdentifierTag
48
+ || !bytesEqual(spki.subarray(algorithmIdentifier.contentOffset, algorithmIdentifier.endOffset), ed25519ObjectIdentifier)) {
49
+ return undefined;
50
+ }
51
+ const subjectPublicKey = readAsn1Element(spki, algorithm.endOffset);
52
+ if (subjectPublicKey.tag !== asn1BitStringTag) {
53
+ return undefined;
54
+ }
55
+ const bitString = spki.subarray(subjectPublicKey.contentOffset, subjectPublicKey.endOffset);
56
+ if (bitString.length !== 33 || bitString[0] !== 0) {
57
+ return undefined;
58
+ }
59
+ return bitString.subarray(1);
60
+ }
61
+ catch {
62
+ return undefined;
63
+ }
64
+ }
65
+ function readAsn1Element(bytes, offset) {
66
+ if (offset + 2 > bytes.length) {
67
+ throw new Error("ASN.1 element header is truncated.");
68
+ }
69
+ const tag = bytes[offset];
70
+ const lengthResult = readAsn1Length(bytes, offset + 1);
71
+ const contentOffset = lengthResult.nextOffset;
72
+ const endOffset = contentOffset + lengthResult.length;
73
+ if (endOffset > bytes.length) {
74
+ throw new Error("ASN.1 element content is truncated.");
75
+ }
76
+ return {
77
+ tag,
78
+ contentOffset,
79
+ endOffset,
80
+ };
81
+ }
82
+ function readAsn1Length(bytes, offset) {
83
+ if (offset >= bytes.length) {
84
+ throw new Error("ASN.1 length is truncated.");
85
+ }
86
+ const firstByte = bytes[offset];
87
+ if ((firstByte & 0x80) === 0) {
88
+ return {
89
+ length: firstByte,
90
+ nextOffset: offset + 1,
91
+ };
92
+ }
93
+ const lengthByteCount = firstByte & 0x7f;
94
+ if (lengthByteCount === 0 || lengthByteCount > 4) {
95
+ throw new Error("ASN.1 length encoding is unsupported.");
96
+ }
97
+ if (offset + 1 + lengthByteCount > bytes.length) {
98
+ throw new Error("ASN.1 long-form length is truncated.");
99
+ }
100
+ let length = 0;
101
+ for (let index = 0; index < lengthByteCount; index += 1) {
102
+ length = (length << 8) | bytes[offset + 1 + index];
103
+ }
104
+ return {
105
+ length,
106
+ nextOffset: offset + 1 + lengthByteCount,
107
+ };
108
+ }
109
+ function bytesEqual(left, right) {
110
+ if (left.length !== right.length) {
111
+ return false;
112
+ }
113
+ for (let index = 0; index < left.length; index += 1) {
114
+ if (left[index] !== right[index]) {
115
+ return false;
116
+ }
117
+ }
118
+ return true;
24
119
  }
@@ -0,0 +1,12 @@
1
+ export declare class CreateAndExerciseCommand {
2
+ readonly templateId: string;
3
+ readonly payload: Record<string, unknown>;
4
+ readonly choice: string;
5
+ readonly argument: unknown;
6
+ constructor(init: {
7
+ templateId: string;
8
+ payload: Record<string, unknown>;
9
+ choice: string;
10
+ argument: unknown;
11
+ });
12
+ }
@@ -0,0 +1,19 @@
1
+ import { ValidationError } from "../../errors/validation-error.js";
2
+ export class CreateAndExerciseCommand {
3
+ templateId;
4
+ payload;
5
+ choice;
6
+ argument;
7
+ constructor(init) {
8
+ if (!init.templateId) {
9
+ throw new ValidationError("create-and-exercise commands require a templateId");
10
+ }
11
+ if (!init.choice) {
12
+ throw new ValidationError("create-and-exercise commands require a choice");
13
+ }
14
+ this.templateId = init.templateId;
15
+ this.payload = init.payload;
16
+ this.choice = init.choice;
17
+ this.argument = init.argument;
18
+ }
19
+ }
@@ -1,7 +1,11 @@
1
+ import { ValidationError } from "../../errors/validation-error.js";
1
2
  export class CreateCommand {
2
3
  templateId;
3
4
  payload;
4
5
  constructor(init) {
6
+ if (!init.templateId) {
7
+ throw new ValidationError("create commands require a templateId");
8
+ }
5
9
  this.templateId = init.templateId;
6
10
  this.payload = init.payload;
7
11
  }
@@ -0,0 +1,12 @@
1
+ export declare class ExerciseByKeyCommand {
2
+ readonly templateId: string;
3
+ readonly contractKey: unknown;
4
+ readonly choice: string;
5
+ readonly argument: unknown;
6
+ constructor(init: {
7
+ templateId: string;
8
+ contractKey: unknown;
9
+ choice: string;
10
+ argument: unknown;
11
+ });
12
+ }
@@ -0,0 +1,22 @@
1
+ import { ValidationError } from "../../errors/validation-error.js";
2
+ export class ExerciseByKeyCommand {
3
+ templateId;
4
+ contractKey;
5
+ choice;
6
+ argument;
7
+ constructor(init) {
8
+ if (!init.templateId) {
9
+ throw new ValidationError("exercise-by-key commands require a templateId");
10
+ }
11
+ if (init.contractKey === undefined) {
12
+ throw new ValidationError("exercise-by-key commands require a contractKey");
13
+ }
14
+ if (!init.choice) {
15
+ throw new ValidationError("exercise-by-key commands require a choice");
16
+ }
17
+ this.templateId = init.templateId;
18
+ this.contractKey = init.contractKey;
19
+ this.choice = init.choice;
20
+ this.argument = init.argument;
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ export declare class ExerciseCommand {
2
+ readonly templateId: string;
3
+ readonly contractId: string;
4
+ readonly choice: string;
5
+ readonly argument: unknown;
6
+ constructor(init: {
7
+ templateId: string;
8
+ contractId: string;
9
+ choice: string;
10
+ argument: unknown;
11
+ });
12
+ }
@@ -0,0 +1,22 @@
1
+ import { ValidationError } from "../../errors/validation-error.js";
2
+ export class ExerciseCommand {
3
+ templateId;
4
+ contractId;
5
+ choice;
6
+ argument;
7
+ constructor(init) {
8
+ if (!init.templateId) {
9
+ throw new ValidationError("exercise commands require a templateId");
10
+ }
11
+ if (!init.contractId) {
12
+ throw new ValidationError("exercise commands require a contractId");
13
+ }
14
+ if (!init.choice) {
15
+ throw new ValidationError("exercise commands require a choice");
16
+ }
17
+ this.templateId = init.templateId;
18
+ this.contractId = init.contractId;
19
+ this.choice = init.choice;
20
+ this.argument = init.argument;
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ import { CreateAndExerciseCommand } from "./create-and-exercise-command.js";
2
+ import { CreateCommand } from "./create-command.js";
3
+ import { ExerciseByKeyCommand } from "./exercise-by-key-command.js";
4
+ import { ExerciseCommand } from "./exercise-command.js";
5
+ export type LedgerCommand = CreateCommand | ExerciseCommand | ExerciseByKeyCommand | CreateAndExerciseCommand;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,13 @@
1
- import { CreateCommand } from "../commands/create-command.js";
1
+ import { LedgerCommand } from "../commands/ledger-command.js";
2
2
  export declare class SubmitCommandRequest {
3
3
  readonly applicationId: string;
4
4
  readonly actAs: readonly string[];
5
5
  readonly readAs: readonly string[];
6
- readonly command: CreateCommand;
6
+ readonly command: LedgerCommand;
7
7
  constructor(init: {
8
8
  applicationId: string;
9
9
  actAs: readonly string[];
10
10
  readAs?: readonly string[];
11
- command: CreateCommand;
11
+ command: LedgerCommand;
12
12
  });
13
13
  }
package/dist/index.d.ts CHANGED
@@ -180,7 +180,11 @@ export { VettedPackage } from "./core/types/vetted-package.js";
180
180
  export { VettedPackages } from "./core/types/vetted-packages.js";
181
181
  export { PreparedTopologyTransaction } from "./core/types/topology/prepared-topology-transaction.js";
182
182
  export { SignedTopologyTransaction } from "./core/types/topology/signed-topology-transaction.js";
183
+ export { CreateAndExerciseCommand } from "./core/types/commands/create-and-exercise-command.js";
183
184
  export { CreateCommand } from "./core/types/commands/create-command.js";
185
+ export { ExerciseByKeyCommand } from "./core/types/commands/exercise-by-key-command.js";
186
+ export { ExerciseCommand } from "./core/types/commands/exercise-command.js";
187
+ export type { LedgerCommand } from "./core/types/commands/ledger-command.js";
184
188
  export { AddTopologyTransactionsRequest } from "./core/types/requests/add-topology-transactions-request.js";
185
189
  export { AllocateExternalPartyRequest } from "./core/types/requests/allocate-external-party-request.js";
186
190
  export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
package/dist/index.js CHANGED
@@ -175,7 +175,10 @@ export { VettedPackage } from "./core/types/vetted-package.js";
175
175
  export { VettedPackages } from "./core/types/vetted-packages.js";
176
176
  export { PreparedTopologyTransaction } from "./core/types/topology/prepared-topology-transaction.js";
177
177
  export { SignedTopologyTransaction } from "./core/types/topology/signed-topology-transaction.js";
178
+ export { CreateAndExerciseCommand } from "./core/types/commands/create-and-exercise-command.js";
178
179
  export { CreateCommand } from "./core/types/commands/create-command.js";
180
+ export { ExerciseByKeyCommand } from "./core/types/commands/exercise-by-key-command.js";
181
+ export { ExerciseCommand } from "./core/types/commands/exercise-command.js";
179
182
  export { AddTopologyTransactionsRequest } from "./core/types/requests/add-topology-transactions-request.js";
180
183
  export { AllocateExternalPartyRequest } from "./core/types/requests/allocate-external-party-request.js";
181
184
  export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
@@ -1,11 +1,49 @@
1
+ import { CreateAndExerciseCommand } from "../../core/types/commands/create-and-exercise-command.js";
2
+ import { CreateCommand } from "../../core/types/commands/create-command.js";
3
+ import { ExerciseByKeyCommand } from "../../core/types/commands/exercise-by-key-command.js";
4
+ import { ExerciseCommand } from "../../core/types/commands/exercise-command.js";
1
5
  export function buildCanonicalCommandPayload(request) {
2
6
  return new TextEncoder().encode(JSON.stringify({
3
7
  applicationId: request.applicationId,
4
8
  actAs: request.actAs,
5
9
  readAs: request.readAs,
6
- command: {
7
- templateId: request.command.templateId,
8
- payload: request.command.payload,
9
- },
10
+ command: mapCanonicalCommand(request.command),
10
11
  }));
11
12
  }
13
+ function mapCanonicalCommand(command) {
14
+ if (command instanceof CreateCommand) {
15
+ return {
16
+ kind: "create",
17
+ templateId: command.templateId,
18
+ payload: command.payload,
19
+ };
20
+ }
21
+ if (command instanceof ExerciseCommand) {
22
+ return {
23
+ kind: "exercise",
24
+ templateId: command.templateId,
25
+ contractId: command.contractId,
26
+ choice: command.choice,
27
+ argument: command.argument,
28
+ };
29
+ }
30
+ if (command instanceof ExerciseByKeyCommand) {
31
+ return {
32
+ kind: "exerciseByKey",
33
+ templateId: command.templateId,
34
+ contractKey: command.contractKey,
35
+ choice: command.choice,
36
+ argument: command.argument,
37
+ };
38
+ }
39
+ if (command instanceof CreateAndExerciseCommand) {
40
+ return {
41
+ kind: "createAndExercise",
42
+ templateId: command.templateId,
43
+ payload: command.payload,
44
+ choice: command.choice,
45
+ argument: command.argument,
46
+ };
47
+ }
48
+ return {};
49
+ }
@@ -1,5 +1,9 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { ValidationError } from "../../../core/errors/validation-error.js";
3
+ import { CreateAndExerciseCommand } from "../../../core/types/commands/create-and-exercise-command.js";
4
+ import { CreateCommand } from "../../../core/types/commands/create-command.js";
5
+ import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
6
+ import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
3
7
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
4
8
  export function mapGrpcSubmitCommandRequest(request, _signed) {
5
9
  return {
@@ -7,7 +11,7 @@ export function mapGrpcSubmitCommandRequest(request, _signed) {
7
11
  workflowId: "",
8
12
  userId: "",
9
13
  commandId: randomUUID(),
10
- commands: [mapCreateCommand(request)],
14
+ commands: [mapCommand(request.command)],
11
15
  deduplicationPeriod: {
12
16
  oneofKind: undefined,
13
17
  },
@@ -29,13 +33,58 @@ export function mapGrpcSubmitCommand(payload) {
29
33
  : payload.updateId,
30
34
  });
31
35
  }
32
- function mapCreateCommand(request) {
36
+ function mapCommand(command) {
37
+ if (command instanceof CreateCommand) {
38
+ return mapCreateCommand(command);
39
+ }
40
+ if (command instanceof ExerciseCommand) {
41
+ return {
42
+ command: {
43
+ oneofKind: "exercise",
44
+ exercise: {
45
+ templateId: parseTemplateIdentifier(command.templateId),
46
+ contractId: command.contractId,
47
+ choice: command.choice,
48
+ choiceArgument: mapValue(command.argument),
49
+ },
50
+ },
51
+ };
52
+ }
53
+ if (command instanceof ExerciseByKeyCommand) {
54
+ return {
55
+ command: {
56
+ oneofKind: "exerciseByKey",
57
+ exerciseByKey: {
58
+ templateId: parseTemplateIdentifier(command.templateId),
59
+ contractKey: mapValue(command.contractKey),
60
+ choice: command.choice,
61
+ choiceArgument: mapValue(command.argument),
62
+ },
63
+ },
64
+ };
65
+ }
66
+ if (command instanceof CreateAndExerciseCommand) {
67
+ return {
68
+ command: {
69
+ oneofKind: "createAndExercise",
70
+ createAndExercise: {
71
+ templateId: parseTemplateIdentifier(command.templateId),
72
+ createArguments: mapRecord(command.payload),
73
+ choice: command.choice,
74
+ choiceArgument: mapValue(command.argument),
75
+ },
76
+ },
77
+ };
78
+ }
79
+ throw new ValidationError("unsupported submit command type");
80
+ }
81
+ function mapCreateCommand(command) {
33
82
  return {
34
83
  command: {
35
84
  oneofKind: "create",
36
85
  create: {
37
- templateId: parseTemplateIdentifier(request.command.templateId),
38
- createArguments: mapRecord(request.command.payload),
86
+ templateId: parseTemplateIdentifier(command.templateId),
87
+ createArguments: mapRecord(command.payload),
39
88
  },
40
89
  },
41
90
  };
@@ -342,9 +342,10 @@ export function mapSdkDuration(value) {
342
342
  });
343
343
  }
344
344
  export function mapSdkSigningPublicKey(value) {
345
+ const format = mapSdkCryptoKeyFormat(value?.format);
345
346
  return new TopologySigningPublicKey({
346
- fingerprint: computeCantonPublicKeyFingerprint(value?.publicKey),
347
- format: mapSdkCryptoKeyFormat(value?.format),
347
+ fingerprint: computeCantonPublicKeyFingerprint(value?.publicKey, format),
348
+ format,
348
349
  publicKey: value?.publicKey,
349
350
  scheme: undefined,
350
351
  usage: (value?.usage ?? []).map(mapSdkSigningKeyUsage),
@@ -352,9 +353,10 @@ export function mapSdkSigningPublicKey(value) {
352
353
  });
353
354
  }
354
355
  export function mapSdkEncryptionPublicKey(value) {
356
+ const format = mapSdkCryptoKeyFormat(value?.format);
355
357
  return new TopologyEncryptionPublicKey({
356
- fingerprint: computeCantonPublicKeyFingerprint(value?.publicKey),
357
- format: mapSdkCryptoKeyFormat(value?.format),
358
+ fingerprint: computeCantonPublicKeyFingerprint(value?.publicKey, format),
359
+ format,
358
360
  publicKey: value?.publicKey,
359
361
  scheme: undefined,
360
362
  keySpec: mapSdkEncryptionKeySpec(value?.keySpec),
@@ -5,7 +5,7 @@ import { ListKnownPartiesResponse } from "../../core/types/responses/list-known-
5
5
  import { UploadDarFileResponse } from "../../core/types/responses/upload-dar-file-response.js";
6
6
  import { NotSupportedError } from "../../core/errors/not-supported-error.js";
7
7
  import { ObjectDisposedError } from "../../core/errors/object-disposed-error.js";
8
- import { mapJsonSubmitCommand } from "./mappers/commands-mapper.js";
8
+ import { mapJsonSubmitCommand, mapJsonSubmitCommandRequest, } from "./mappers/commands-mapper.js";
9
9
  import { mapJsonUploadPackage } from "./mappers/packages-mapper.js";
10
10
  import { mapJsonAllocatePartyRequest, mapJsonCreateParty, mapJsonListParties, } from "./mappers/parties-mapper.js";
11
11
  import { mapJsonQueryContracts } from "./mappers/contracts-mapper.js";
@@ -458,13 +458,7 @@ export class JsonTransport {
458
458
  if (signed) {
459
459
  throw new NotSupportedError("command signing is not supported by json transport");
460
460
  }
461
- const payload = await this.httpClient.postAsync("/v1/create", {
462
- templateId: request.command.templateId,
463
- payload: request.command.payload,
464
- applicationId: request.applicationId,
465
- actAs: request.actAs,
466
- readAs: request.readAs,
467
- }, options);
461
+ const payload = await this.httpClient.postAsync("/v2/commands/submit-and-wait", mapJsonSubmitCommandRequest(request), options);
468
462
  return mapJsonSubmitCommand(payload);
469
463
  }
470
464
  throwIfDisposed() {
@@ -1,9 +1,20 @@
1
+ import { SubmitCommandRequest } from "../../../core/types/requests/submit-command-request.js";
1
2
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
3
+ export declare function mapJsonSubmitCommandRequest(request: SubmitCommandRequest): {
4
+ commandId: string;
5
+ actAs: readonly string[];
6
+ readAs: readonly string[];
7
+ commands: unknown[];
8
+ applicationId?: string;
9
+ };
2
10
  export declare function mapJsonSubmitCommand(payload: {
3
11
  result?: {
4
12
  commandId?: string;
5
13
  transactionId?: string;
14
+ updateId?: string;
6
15
  };
7
16
  commandId?: string;
8
17
  transactionId?: string;
18
+ updateId?: string;
19
+ completionOffset?: string;
9
20
  }): SubmitCommandResponse;
@@ -1,7 +1,66 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { ValidationError } from "../../../core/errors/validation-error.js";
3
+ import { CreateAndExerciseCommand } from "../../../core/types/commands/create-and-exercise-command.js";
4
+ import { CreateCommand } from "../../../core/types/commands/create-command.js";
5
+ import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
6
+ import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
1
7
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
8
+ export function mapJsonSubmitCommandRequest(request) {
9
+ return {
10
+ commandId: randomUUID(),
11
+ actAs: request.actAs,
12
+ readAs: request.readAs,
13
+ commands: [mapJsonCommand(request.command)],
14
+ applicationId: request.applicationId || undefined,
15
+ };
16
+ }
2
17
  export function mapJsonSubmitCommand(payload) {
3
18
  return new SubmitCommandResponse({
4
19
  commandId: payload.result?.commandId ?? payload.commandId,
5
- transactionId: payload.result?.transactionId ?? payload.transactionId,
20
+ transactionId: payload.result?.transactionId
21
+ ?? payload.result?.updateId
22
+ ?? payload.transactionId
23
+ ?? payload.updateId,
6
24
  });
7
25
  }
26
+ function mapJsonCommand(command) {
27
+ if (command instanceof CreateCommand) {
28
+ return {
29
+ CreateCommand: {
30
+ templateId: command.templateId,
31
+ createArguments: command.payload,
32
+ },
33
+ };
34
+ }
35
+ if (command instanceof ExerciseCommand) {
36
+ return {
37
+ ExerciseCommand: {
38
+ templateId: command.templateId,
39
+ contractId: command.contractId,
40
+ choice: command.choice,
41
+ choiceArgument: command.argument,
42
+ },
43
+ };
44
+ }
45
+ if (command instanceof ExerciseByKeyCommand) {
46
+ return {
47
+ ExerciseByKeyCommand: {
48
+ templateId: command.templateId,
49
+ contractKey: command.contractKey,
50
+ choice: command.choice,
51
+ choiceArgument: command.argument,
52
+ },
53
+ };
54
+ }
55
+ if (command instanceof CreateAndExerciseCommand) {
56
+ return {
57
+ CreateAndExerciseCommand: {
58
+ templateId: command.templateId,
59
+ createArguments: command.payload,
60
+ choice: command.choice,
61
+ choiceArgument: command.argument,
62
+ },
63
+ };
64
+ }
65
+ throw new ValidationError("unsupported submit command type");
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",