@distrohelena/canton-typescript-sdk 0.1.5 → 0.1.7
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/README.md +333 -1
- package/dist/client/canton-client-options.d.ts +3 -0
- package/dist/client/canton-client-options.js +2 -0
- package/dist/client/service-registry.js +3 -2
- package/dist/core/errors/grpc-transport-error.d.ts +14 -0
- package/dist/core/errors/grpc-transport-error.js +76 -0
- package/dist/core/signing/command-signer.interface.d.ts +2 -0
- package/dist/core/transports/transport.interface.d.ts +2 -2
- package/dist/core/types/canton-hash-purpose.d.ts +2 -1
- package/dist/core/types/canton-hash-purpose.js +1 -0
- package/dist/core/types/daml-numeric.d.ts +6 -0
- package/dist/core/types/daml-numeric.js +14 -0
- package/dist/core/types/daml-party.d.ts +6 -0
- package/dist/core/types/daml-party.js +14 -0
- package/dist/core/types/disclosed-contract.d.ts +13 -0
- package/dist/core/types/disclosed-contract.js +15 -0
- package/dist/core/types/requests/create-decentralized-party-request.d.ts +41 -0
- package/dist/core/types/requests/create-decentralized-party-request.js +82 -0
- package/dist/core/types/requests/create-external-party-request.d.ts +42 -0
- package/dist/core/types/requests/create-external-party-request.js +47 -0
- package/dist/core/types/requests/finalize-decentralized-party-request.d.ts +39 -0
- package/dist/core/types/requests/finalize-decentralized-party-request.js +42 -0
- package/dist/core/types/requests/get-active-contracts-page-request.d.ts +15 -2
- package/dist/core/types/requests/get-active-contracts-page-request.js +4 -0
- package/dist/core/types/requests/submit-command-request.d.ts +5 -0
- package/dist/core/types/requests/submit-command-request.js +4 -0
- package/dist/core/types/topology/topology-signature-format.d.ts +2 -1
- package/dist/core/types/topology/topology-signature-format.js +1 -0
- package/dist/daml-lf/container/dar-archive-entry.d.ts +8 -0
- package/dist/daml-lf/container/dar-archive-entry.js +8 -0
- package/dist/daml-lf/container/dar-archive-loader.js +14 -0
- package/dist/daml-lf/container/dar-archive.d.ts +6 -0
- package/dist/daml-lf/container/dar-archive.js +4 -0
- package/dist/daml-lf/container/dar-source-bundle-loader.d.ts +5 -0
- package/dist/daml-lf/container/dar-source-bundle-loader.js +33 -0
- package/dist/daml-lf/container/dar-source-bundle.d.ts +45 -0
- package/dist/daml-lf/container/dar-source-bundle.js +11 -0
- package/dist/daml-lf/container/dar-source-file-entry.d.ts +8 -0
- package/dist/daml-lf/container/dar-source-file-entry.js +8 -0
- package/dist/daml-lf/daml-lf-compilation.d.ts +12 -0
- package/dist/daml-lf/daml-lf-compilation.js +35 -0
- package/dist/daml-lf/index.d.ts +11 -0
- package/dist/daml-lf/index.js +10 -0
- package/dist/daml-lf/interpreter/daml-lf-builtin-dispatch.d.ts +43 -0
- package/dist/daml-lf/interpreter/daml-lf-builtin-dispatch.js +933 -0
- package/dist/daml-lf/interpreter/daml-lf-evaluator.d.ts +95 -0
- package/dist/daml-lf/interpreter/daml-lf-evaluator.js +1131 -0
- package/dist/daml-lf/interpreter/daml-lf-interpreter-scaffold.d.ts +3 -0
- package/dist/daml-lf/interpreter/daml-lf-interpreter-scaffold.js +6 -1
- package/dist/daml-lf/interpreter/daml-lf-lexical-scope.d.ts +13 -0
- package/dist/daml-lf/interpreter/daml-lf-lexical-scope.js +46 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-frame.d.ts +16 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-frame.js +15 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-value.d.ts +21 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-value.js +4 -1
- package/dist/daml-lf/interpreter/daml-lf-step-kind.d.ts +7 -0
- package/dist/daml-lf/interpreter/daml-lf-step-kind.js +8 -0
- package/dist/daml-lf/interpreter/daml-lf-trace-sink.interface.d.ts +30 -0
- package/dist/daml-lf/interpreter/daml-lf-trace-sink.interface.js +1 -0
- package/dist/daml-lf/model/daml-lf-builtin-type.d.ts +3 -0
- package/dist/daml-lf/model/daml-lf-builtin-type.js +3 -0
- package/dist/daml-lf/model/daml-lf-choice.d.ts +5 -0
- package/dist/daml-lf/model/daml-lf-choice.js +4 -0
- package/dist/daml-lf/model/daml-lf-expression-path.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-expression-path.js +81 -0
- package/dist/daml-lf/model/daml-lf-expression.d.ts +146 -0
- package/dist/daml-lf/model/daml-lf-expression.js +71 -0
- package/dist/daml-lf/model/daml-lf-template.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-template.js +2 -0
- package/dist/daml-lf/model/daml-lf-type.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-type.js +4 -0
- package/dist/daml-lf/model/lf-2-model-mapper.d.ts +5 -0
- package/dist/daml-lf/model/lf-2-model-mapper.js +445 -12
- package/dist/debugger/errors/replay-determinism.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-determinism.exception.js +3 -0
- package/dist/debugger/errors/replay-missing-package.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-missing-package.exception.js +3 -0
- package/dist/debugger/errors/replay-missing-source.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-missing-source.exception.js +3 -0
- package/dist/debugger/errors/replay-source-map.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-source-map.exception.js +3 -0
- package/dist/debugger/errors/replay-state-hydration.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-state-hydration.exception.js +3 -0
- package/dist/debugger/errors/replay-unsupported-lf-construct.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-unsupported-lf-construct.exception.js +3 -0
- package/dist/debugger/errors/replay-unsupported-update.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-unsupported-update.exception.js +3 -0
- package/dist/debugger/index.d.ts +31 -0
- package/dist/debugger/index.js +31 -0
- package/dist/debugger/ledger-replay-debugger-client.d.ts +31 -0
- package/dist/debugger/ledger-replay-debugger-client.js +53 -0
- package/dist/debugger/replay/ledger-replay-environment-builder.d.ts +95 -0
- package/dist/debugger/replay/ledger-replay-environment-builder.js +249 -0
- package/dist/debugger/replay/ledger-replay-session-loader.d.ts +78 -0
- package/dist/debugger/replay/ledger-replay-session-loader.js +565 -0
- package/dist/debugger/replay/replay-artifact-resolver.d.ts +30 -0
- package/dist/debugger/replay/replay-artifact-resolver.js +210 -0
- package/dist/debugger/replay/replay-determinism-validator.d.ts +12 -0
- package/dist/debugger/replay/replay-determinism-validator.js +161 -0
- package/dist/debugger/replay/replay-entrypoint-definition-resolver.d.ts +40 -0
- package/dist/debugger/replay/replay-entrypoint-definition-resolver.js +337 -0
- package/dist/debugger/replay/replay-entrypoint.d.ts +22 -0
- package/dist/debugger/replay/replay-entrypoint.js +14 -0
- package/dist/debugger/replay/replay-ledger-value-normalizer.d.ts +7 -0
- package/dist/debugger/replay/replay-ledger-value-normalizer.js +194 -0
- package/dist/debugger/replay/replay-update-loader.d.ts +24 -0
- package/dist/debugger/replay/replay-update-loader.js +94 -0
- package/dist/debugger/replay/replay-update-visibility-validator.d.ts +19 -0
- package/dist/debugger/replay/replay-update-visibility-validator.js +19 -0
- package/dist/debugger/session/in-memory-replay-session-store.d.ts +27 -0
- package/dist/debugger/session/in-memory-replay-session-store.js +109 -0
- package/dist/debugger/session/replay-phase.d.ts +7 -0
- package/dist/debugger/session/replay-phase.js +8 -0
- package/dist/debugger/session/replay-scope.d.ts +10 -0
- package/dist/debugger/session/replay-scope.js +10 -0
- package/dist/debugger/session/replay-session-metadata.d.ts +10 -0
- package/dist/debugger/session/replay-session-metadata.js +10 -0
- package/dist/debugger/session/replay-session-request.d.ts +6 -0
- package/dist/debugger/session/replay-session-request.js +10 -0
- package/dist/debugger/session/replay-session.d.ts +12 -0
- package/dist/debugger/session/replay-session.js +10 -0
- package/dist/debugger/session/replay-source-location.d.ts +17 -0
- package/dist/debugger/session/replay-source-location.js +16 -0
- package/dist/debugger/session/replay-stack-frame.d.ts +8 -0
- package/dist/debugger/session/replay-stack-frame.js +8 -0
- package/dist/debugger/session/replay-state-delta.d.ts +29 -0
- package/dist/debugger/session/replay-state-delta.js +24 -0
- package/dist/debugger/session/replay-step-advance-result.d.ts +24 -0
- package/dist/debugger/session/replay-step-advance-result.js +16 -0
- package/dist/debugger/session/replay-step.d.ts +30 -0
- package/dist/debugger/session/replay-step.js +24 -0
- package/dist/debugger/session/replay-value-preview.d.ts +8 -0
- package/dist/debugger/session/replay-value-preview.js +15 -0
- package/dist/debugger/source/daml-source-mapper.d.ts +12 -0
- package/dist/debugger/source/daml-source-mapper.js +21 -0
- package/dist/debugger/source/dar-source-map-metadata.d.ts +26 -0
- package/dist/debugger/source/dar-source-map-metadata.js +10 -0
- package/dist/debugger/source/source-coverage-validator.d.ts +8 -0
- package/dist/debugger/source/source-coverage-validator.js +16 -0
- package/dist/debugger/source/source-indexed-compilation.d.ts +45 -0
- package/dist/debugger/source/source-indexed-compilation.js +110 -0
- package/dist/debugger/source/source-mapping-precision.d.ts +5 -0
- package/dist/debugger/source/source-mapping-precision.js +4 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +13 -0
- package/dist/query/cache/memory-query-cache.d.ts +9 -0
- package/dist/query/cache/memory-query-cache.js +24 -0
- package/dist/query/cache/query-cache-store.d.ts +5 -0
- package/dist/query/cache/query-cache-store.js +1 -0
- package/dist/query/canton-manager-options.d.ts +17 -0
- package/dist/query/canton-manager-options.js +1 -0
- package/dist/query/canton-manager.d.ts +11 -0
- package/dist/query/canton-manager.js +42 -0
- package/dist/query/errors/pqs-query-error.d.ts +10 -0
- package/dist/query/errors/pqs-query-error.js +11 -0
- package/dist/query/errors/pqs-schema-profile-error.d.ts +3 -0
- package/dist/query/errors/pqs-schema-profile-error.js +3 -0
- package/dist/query/errors/query-capability-error.d.ts +7 -0
- package/dist/query/errors/query-capability-error.js +10 -0
- package/dist/query/grpc/grpc-contract-query-client.d.ts +32 -0
- package/dist/query/grpc/grpc-contract-query-client.js +126 -0
- package/dist/query/model-types.d.ts +258 -0
- package/dist/query/model-types.js +14 -0
- package/dist/query/pqs/pqs-pool.d.ts +13 -0
- package/dist/query/pqs/pqs-pool.js +18 -0
- package/dist/query/pqs/pqs-query-client.d.ts +49 -0
- package/dist/query/pqs/pqs-query-client.js +324 -0
- package/dist/query/pqs/pqs-schema-profile.d.ts +25 -0
- package/dist/query/pqs/pqs-schema-profile.js +120 -0
- package/dist/query/pqs/pqs-sql-compiler.d.ts +7 -0
- package/dist/query/pqs/pqs-sql-compiler.js +132 -0
- package/dist/query/pqs/read-only-sql.d.ts +1 -0
- package/dist/query/pqs/read-only-sql.js +35 -0
- package/dist/query/query-client.d.ts +61 -0
- package/dist/query/query-client.js +1 -0
- package/dist/query/query-source.d.ts +4 -0
- package/dist/query/query-source.js +5 -0
- package/dist/services/command/command-service-client.d.ts +2 -2
- package/dist/services/commands/command-submission-pipeline.d.ts +2 -2
- package/dist/services/party-management/decentralized-party-lifecycle.d.ts +6 -0
- package/dist/services/party-management/decentralized-party-lifecycle.js +82 -0
- package/dist/services/party-management/party-management-service-client.d.ts +16 -1
- package/dist/services/party-management/party-management-service-client.js +142 -1
- package/dist/services/topology-manager-write/topology-signed-transaction-assembler.js +4 -0
- package/dist/testing/campaign/campaign-artifact.d.ts +20 -0
- package/dist/testing/campaign/campaign-artifact.js +147 -0
- package/dist/testing/campaign/campaign-definition.d.ts +9 -0
- package/dist/testing/campaign/campaign-definition.js +78 -0
- package/dist/testing/campaign/campaign-metrics.d.ts +32 -0
- package/dist/testing/campaign/campaign-metrics.js +26 -0
- package/dist/testing/campaign/campaign-model.d.ts +11 -0
- package/dist/testing/campaign/campaign-model.js +21 -0
- package/dist/testing/campaign/campaign-runner.d.ts +99 -0
- package/dist/testing/campaign/campaign-runner.js +194 -0
- package/dist/testing/campaign/campaign-scheduler.d.ts +40 -0
- package/dist/testing/campaign/campaign-scheduler.js +75 -0
- package/dist/testing/campaign/campaign-types.d.ts +52 -0
- package/dist/testing/campaign/campaign-types.js +11 -0
- package/dist/testing/daml/daml-action-arbitrary.d.ts +13 -0
- package/dist/testing/daml/daml-action-arbitrary.js +24 -0
- package/dist/testing/daml/daml-choice-action-arbitrary.d.ts +18 -0
- package/dist/testing/daml/daml-choice-action-arbitrary.js +27 -0
- package/dist/testing/daml/daml-create-action-arbitrary.d.ts +19 -0
- package/dist/testing/daml/daml-create-action-arbitrary.js +34 -0
- package/dist/testing/daml/daml-testing-catalog.d.ts +38 -0
- package/dist/testing/daml/daml-testing-catalog.js +40 -0
- package/dist/testing/daml/daml-value-arbitrary.d.ts +8 -0
- package/dist/testing/daml/daml-value-arbitrary.js +43 -0
- package/dist/testing/daml/declarative-campaign-arbitrary.d.ts +15 -0
- package/dist/testing/daml/declarative-campaign-arbitrary.js +30 -0
- package/dist/testing/errors/invariant-campaign-failure.d.ts +24 -0
- package/dist/testing/errors/invariant-campaign-failure.js +37 -0
- package/dist/testing/errors/testing-configuration-error.d.ts +3 -0
- package/dist/testing/errors/testing-configuration-error.js +6 -0
- package/dist/testing/handlers/handler.d.ts +19 -0
- package/dist/testing/handlers/handler.js +31 -0
- package/dist/testing/index.d.ts +22 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/runtime/campaign-isolation.d.ts +14 -0
- package/dist/testing/runtime/campaign-isolation.js +23 -0
- package/dist/testing/runtime/canton-test-runtime.d.ts +58 -0
- package/dist/testing/runtime/canton-test-runtime.js +138 -0
- package/dist/testing/runtime/declarative-action-executor.d.ts +16 -0
- package/dist/testing/runtime/declarative-action-executor.js +41 -0
- package/dist/testing/targets/target.d.ts +49 -0
- package/dist/testing/targets/target.js +121 -0
- package/dist/transports/grpc/grpc-channel-factory.js +31 -1
- package/dist/transports/grpc/grpc-transport.d.ts +2 -2
- package/dist/transports/grpc/grpc-transport.js +11 -8
- package/dist/transports/grpc/mappers/commands-mapper.js +23 -2
- package/dist/transports/grpc/mappers/contracts-mapper.d.ts +3 -1
- package/dist/transports/grpc/mappers/contracts-mapper.js +16 -3
- package/dist/transports/grpc/mappers/interactive-command-mapper.d.ts +4 -1
- package/dist/transports/grpc/mappers/interactive-command-mapper.js +3 -8
- package/dist/transports/grpc/mappers/topology-manager-write-mapper.js +59 -1
- package/dist/transports/json/mappers/commands-mapper.js +20 -6
- package/node/.generated/start-local/additional-config.extra-participants.conf +37 -0
- package/node/.generated/start-local/additional-config.extra-validators.conf +35 -0
- package/node/.generated/start-local/compose-extra-participants.yaml +147 -0
- package/node/.generated/start-local/extra-participants.env +30 -0
- package/node/es256-jwt.mjs +177 -0
- package/node/start-local.sh +886 -0
- package/node/stop-local.sh +200 -0
- package/node/test-start-local.sh +354 -0
- package/node/test-stop-local.sh +112 -0
- package/package.json +21 -2
|
@@ -8,7 +8,9 @@ import { ImportTopologySnapshotResponse } from "../../../core/types/responses/im
|
|
|
8
8
|
import { ImportTopologySnapshotV2Response } from "../../../core/types/responses/import-topology-snapshot-v2-response.js";
|
|
9
9
|
import { SignTopologyTransactionsResponse } from "../../../core/types/responses/sign-topology-transactions-response.js";
|
|
10
10
|
import { GeneratedTopologyTransaction } from "../../../core/types/topology/generated-topology-transaction.js";
|
|
11
|
+
import { DecentralizedNamespaceDefinition } from "../../../core/types/topology/decentralized-namespace-definition.js";
|
|
11
12
|
import { MultiTopologyTransactionSignature } from "../../../core/types/topology/multi-topology-transaction-signature.js";
|
|
13
|
+
import { NamespaceDelegation, NamespaceDelegationRestrictionKind, } from "../../../core/types/topology/namespace-delegation.js";
|
|
12
14
|
import { PartyToParticipant, PartyToParticipantOnboarding, } from "../../../core/types/topology/party-to-participant.js";
|
|
13
15
|
import { SignedTopologyTransaction } from "../../../core/types/topology/signed-topology-transaction.js";
|
|
14
16
|
import { TopologyForceFlag } from "../../../core/types/topology/topology-force-flag.js";
|
|
@@ -18,7 +20,7 @@ import { TopologyTransactionSignature } from "../../../core/types/topology/topol
|
|
|
18
20
|
import { CryptoKeyFormat, SignatureFormat as GrpcSignatureFormat, SigningAlgorithmSpec, SigningKeyScheme, SigningKeySpec, SigningKeyUsage, } from "../generated/canton/com/digitalasset/canton/crypto/v30/crypto.js";
|
|
19
21
|
import { ForceFlag, } from "../generated/canton/com/digitalasset/canton/topology/admin/v30/topology_manager_write_service.js";
|
|
20
22
|
import { Enums_ParticipantPermission, } from "../generated/canton/com/digitalasset/canton/protocol/v30/topology.js";
|
|
21
|
-
import { mapGrpcTopologyChangeOp, mapGrpcTopologyStoreId, } from "./topology-common-mapper.js";
|
|
23
|
+
import { mapGrpcTopologyChangeOp, mapGrpcTopologyMappingCode, mapGrpcTopologyStoreId, } from "./topology-common-mapper.js";
|
|
22
24
|
export function mapGrpcGenerateTopologyTransactionsRequest(request) {
|
|
23
25
|
return {
|
|
24
26
|
proposals: request.proposals.map(mapGrpcGenerateTopologyTransactionsProposal),
|
|
@@ -155,8 +157,64 @@ function mapGrpcTopologyMapping(mapping) {
|
|
|
155
157
|
},
|
|
156
158
|
};
|
|
157
159
|
}
|
|
160
|
+
else if (mapping instanceof DecentralizedNamespaceDefinition) {
|
|
161
|
+
return {
|
|
162
|
+
mapping: {
|
|
163
|
+
oneofKind: "decentralizedNamespaceDefinition",
|
|
164
|
+
decentralizedNamespaceDefinition: mapGrpcDecentralizedNamespaceDefinition(mapping),
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else if (mapping instanceof NamespaceDelegation) {
|
|
169
|
+
return {
|
|
170
|
+
mapping: {
|
|
171
|
+
oneofKind: "namespaceDelegation",
|
|
172
|
+
namespaceDelegation: mapGrpcNamespaceDelegation(mapping),
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
158
176
|
throw new ValidationError(`Unsupported topology write mapping type: ${mapping.constructor.name}.`);
|
|
159
177
|
}
|
|
178
|
+
function mapGrpcDecentralizedNamespaceDefinition(value) {
|
|
179
|
+
return {
|
|
180
|
+
decentralizedNamespace: value.decentralizedNamespace,
|
|
181
|
+
threshold: value.threshold,
|
|
182
|
+
owners: [...value.owners],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function mapGrpcNamespaceDelegation(value) {
|
|
186
|
+
return {
|
|
187
|
+
namespace: value.namespace,
|
|
188
|
+
targetKey: value.targetKey === undefined
|
|
189
|
+
? undefined
|
|
190
|
+
: mapGrpcSigningPublicKey(value.targetKey),
|
|
191
|
+
isRootDelegation: value.isRootDelegation,
|
|
192
|
+
restriction: mapGrpcNamespaceDelegationRestriction(value),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function mapGrpcNamespaceDelegationRestriction(value) {
|
|
196
|
+
switch (value.restriction?.kind) {
|
|
197
|
+
case NamespaceDelegationRestrictionKind.canSignAllMappings:
|
|
198
|
+
return {
|
|
199
|
+
oneofKind: "canSignAllMappings",
|
|
200
|
+
canSignAllMappings: {},
|
|
201
|
+
};
|
|
202
|
+
case NamespaceDelegationRestrictionKind.canSignAllButNamespaceDelegations:
|
|
203
|
+
return {
|
|
204
|
+
oneofKind: "canSignAllButNamespaceDelegations",
|
|
205
|
+
canSignAllButNamespaceDelegations: {},
|
|
206
|
+
};
|
|
207
|
+
case NamespaceDelegationRestrictionKind.canSignSpecificMappings:
|
|
208
|
+
return {
|
|
209
|
+
oneofKind: "canSignSpecificMapings",
|
|
210
|
+
canSignSpecificMapings: {
|
|
211
|
+
mappings: value.restriction.mappings.map(mapGrpcTopologyMappingCode),
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
default:
|
|
215
|
+
return { oneofKind: undefined };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
160
218
|
function mapGrpcPartyToParticipant(value) {
|
|
161
219
|
return {
|
|
162
220
|
party: value.party,
|
|
@@ -2,6 +2,8 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { ValidationError } from "../../../core/errors/validation-error.js";
|
|
3
3
|
import { CreateAndExerciseCommand } from "../../../core/types/commands/create-and-exercise-command.js";
|
|
4
4
|
import { CreateCommand } from "../../../core/types/commands/create-command.js";
|
|
5
|
+
import { DamlNumeric } from "../../../core/types/daml-numeric.js";
|
|
6
|
+
import { DamlParty } from "../../../core/types/daml-party.js";
|
|
5
7
|
import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
|
|
6
8
|
import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
|
|
7
9
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
@@ -28,7 +30,7 @@ function mapJsonCommand(command) {
|
|
|
28
30
|
return {
|
|
29
31
|
CreateCommand: {
|
|
30
32
|
templateId: command.templateId,
|
|
31
|
-
createArguments: command.payload,
|
|
33
|
+
createArguments: mapJsonValue(command.payload),
|
|
32
34
|
},
|
|
33
35
|
};
|
|
34
36
|
}
|
|
@@ -38,7 +40,7 @@ function mapJsonCommand(command) {
|
|
|
38
40
|
templateId: command.templateId,
|
|
39
41
|
contractId: command.contractId,
|
|
40
42
|
choice: command.choice,
|
|
41
|
-
choiceArgument: command.argument,
|
|
43
|
+
choiceArgument: mapJsonValue(command.argument),
|
|
42
44
|
},
|
|
43
45
|
};
|
|
44
46
|
}
|
|
@@ -46,9 +48,9 @@ function mapJsonCommand(command) {
|
|
|
46
48
|
return {
|
|
47
49
|
ExerciseByKeyCommand: {
|
|
48
50
|
templateId: command.templateId,
|
|
49
|
-
contractKey: command.contractKey,
|
|
51
|
+
contractKey: mapJsonValue(command.contractKey),
|
|
50
52
|
choice: command.choice,
|
|
51
|
-
choiceArgument: command.argument,
|
|
53
|
+
choiceArgument: mapJsonValue(command.argument),
|
|
52
54
|
},
|
|
53
55
|
};
|
|
54
56
|
}
|
|
@@ -56,11 +58,23 @@ function mapJsonCommand(command) {
|
|
|
56
58
|
return {
|
|
57
59
|
CreateAndExerciseCommand: {
|
|
58
60
|
templateId: command.templateId,
|
|
59
|
-
createArguments: command.payload,
|
|
61
|
+
createArguments: mapJsonValue(command.payload),
|
|
60
62
|
choice: command.choice,
|
|
61
|
-
choiceArgument: command.argument,
|
|
63
|
+
choiceArgument: mapJsonValue(command.argument),
|
|
62
64
|
},
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
throw new ValidationError("unsupported submit command type");
|
|
66
68
|
}
|
|
69
|
+
function mapJsonValue(value) {
|
|
70
|
+
if (value instanceof DamlParty || value instanceof DamlNumeric) {
|
|
71
|
+
return value.value;
|
|
72
|
+
}
|
|
73
|
+
else if (Array.isArray(value)) {
|
|
74
|
+
return value.map(mapJsonValue);
|
|
75
|
+
}
|
|
76
|
+
else if (value !== null && typeof value === "object") {
|
|
77
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, mapJsonValue(item)]));
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
canton.participants.extra-1 = $${_participant} {
|
|
2
|
+
storage.config.properties.databaseName = "participant-extra-1"
|
|
3
|
+
init {
|
|
4
|
+
generate-topology-transactions-and-keys = true
|
|
5
|
+
identity.type = auto
|
|
6
|
+
}
|
|
7
|
+
monitoring {
|
|
8
|
+
http-health-server.port = ${EXTRA_PARTICIPANT_1_HTTP_HEALTHCHECK_PORT}
|
|
9
|
+
grpc-health-server.port = ${EXTRA_PARTICIPANT_1_GRPC_HEALTHCHECK_PORT}
|
|
10
|
+
}
|
|
11
|
+
http-ledger-api.port = ${EXTRA_PARTICIPANT_1_JSON_API_PORT}
|
|
12
|
+
admin-api.port = ${EXTRA_PARTICIPANT_1_ADMIN_API_PORT}
|
|
13
|
+
ledger-api.port = ${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}
|
|
14
|
+
ledger-api {
|
|
15
|
+
auth-services = [{
|
|
16
|
+
type = unsafe-jwt-hmac-256
|
|
17
|
+
target-audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
18
|
+
secret = "unsafe"
|
|
19
|
+
}]
|
|
20
|
+
|
|
21
|
+
user-management-service.additional-admin-user-id = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
canton.participants.extra-1.ledger-api.auth-services = [
|
|
26
|
+
{
|
|
27
|
+
type = unsafe-jwt-hmac-256
|
|
28
|
+
target-audience = "https://canton.network.global"
|
|
29
|
+
secret = "unsafe"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type = jwt-es-256-crt
|
|
33
|
+
certificate = "/app/es256-certificate.pem"
|
|
34
|
+
target-audience = "https://canton.network.global/es256"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
canton.validator-apps.extra-1-validator_backend = $${_validator_backend} {
|
|
2
|
+
onboarding.secret = "${EXTRA_VALIDATOR_1_ONBOARDING_SECRET}"
|
|
3
|
+
domain-migration-dump-path = "/domain-upgrade-dump/domain_migration_dump-extra-1.json"
|
|
4
|
+
storage.config.properties.databaseName = "${EXTRA_VALIDATOR_1_DB}"
|
|
5
|
+
admin-api.port = ${EXTRA_VALIDATOR_1_ADMIN_API_PORT}
|
|
6
|
+
canton-identifier-config.participant = extra-1
|
|
7
|
+
participant-client {
|
|
8
|
+
admin-api.port = ${EXTRA_PARTICIPANT_1_ADMIN_API_PORT}
|
|
9
|
+
ledger-api {
|
|
10
|
+
client-config.port = ${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}
|
|
11
|
+
auth-config = {
|
|
12
|
+
type = "self-signed"
|
|
13
|
+
user = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
14
|
+
audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
15
|
+
secret = "unsafe"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
auth = {
|
|
20
|
+
algorithm = "hs-256-unsafe"
|
|
21
|
+
audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
22
|
+
secret = "unsafe"
|
|
23
|
+
}
|
|
24
|
+
ledger-api-user = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
25
|
+
validator-wallet-users.0 = "${EXTRA_VALIDATOR_1_WALLET_ADMIN_USER_NAME}"
|
|
26
|
+
validator-party-hint = "${EXTRA_VALIDATOR_1_PARTY_HINT}"
|
|
27
|
+
|
|
28
|
+
domains.global.buy-extra-traffic {
|
|
29
|
+
min-topup-interval = ${?MIN_TRAFFIC_TOPUP_INTERVAL}
|
|
30
|
+
target-throughput = ${?TARGET_TRAFFIC_THROUGHPUT}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
canton.sv-apps.sv.expected-validator-onboardings += { secret = "${EXTRA_VALIDATOR_1_ONBOARDING_SECRET}" }
|
|
35
|
+
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
volumes:
|
|
2
|
+
postgres-pqs-extra-1:
|
|
3
|
+
|
|
4
|
+
services:
|
|
5
|
+
postgres:
|
|
6
|
+
env_file:
|
|
7
|
+
- ${START_LOCAL_GENERATED_DIR}/extra-participants.env
|
|
8
|
+
canton:
|
|
9
|
+
env_file:
|
|
10
|
+
- ${START_LOCAL_GENERATED_DIR}/extra-participants.env
|
|
11
|
+
environment:
|
|
12
|
+
ADDITIONAL_CONFIG_EXTRA_PARTICIPANTS: |
|
|
13
|
+
canton.participants.extra-1 = $${_participant} {
|
|
14
|
+
storage.config.properties.databaseName = "participant-extra-1"
|
|
15
|
+
init {
|
|
16
|
+
generate-topology-transactions-and-keys = true
|
|
17
|
+
identity.type = auto
|
|
18
|
+
}
|
|
19
|
+
monitoring {
|
|
20
|
+
http-health-server.port = ${EXTRA_PARTICIPANT_1_HTTP_HEALTHCHECK_PORT}
|
|
21
|
+
grpc-health-server.port = ${EXTRA_PARTICIPANT_1_GRPC_HEALTHCHECK_PORT}
|
|
22
|
+
}
|
|
23
|
+
http-ledger-api.port = ${EXTRA_PARTICIPANT_1_JSON_API_PORT}
|
|
24
|
+
admin-api.port = ${EXTRA_PARTICIPANT_1_ADMIN_API_PORT}
|
|
25
|
+
ledger-api.port = ${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}
|
|
26
|
+
ledger-api {
|
|
27
|
+
auth-services = [{
|
|
28
|
+
type = unsafe-jwt-hmac-256
|
|
29
|
+
target-audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
30
|
+
secret = "unsafe"
|
|
31
|
+
}]
|
|
32
|
+
|
|
33
|
+
user-management-service.additional-admin-user-id = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
canton.participants.extra-1.ledger-api.auth-services = [
|
|
38
|
+
{
|
|
39
|
+
type = unsafe-jwt-hmac-256
|
|
40
|
+
target-audience = "https://canton.network.global"
|
|
41
|
+
secret = "unsafe"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type = jwt-es-256-crt
|
|
45
|
+
certificate = "/app/es256-certificate.pem"
|
|
46
|
+
target-audience = "https://canton.network.global/es256"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
ports:
|
|
51
|
+
- "${EXTRA_PARTICIPANT_1_LEDGER_API_PUBLISHED_PORT}:${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}"
|
|
52
|
+
- "${EXTRA_PARTICIPANT_1_ADMIN_API_PUBLISHED_PORT}:${EXTRA_PARTICIPANT_1_ADMIN_API_PORT}"
|
|
53
|
+
- "${EXTRA_PARTICIPANT_1_JSON_API_PUBLISHED_PORT}:${EXTRA_PARTICIPANT_1_JSON_API_PORT}"
|
|
54
|
+
splice:
|
|
55
|
+
env_file:
|
|
56
|
+
- ${START_LOCAL_GENERATED_DIR}/extra-participants.env
|
|
57
|
+
environment:
|
|
58
|
+
ADDITIONAL_CONFIG_EXTRA_VALIDATORS: |
|
|
59
|
+
canton.validator-apps.extra-1-validator_backend = $${_validator_backend} {
|
|
60
|
+
onboarding.secret = "${EXTRA_VALIDATOR_1_ONBOARDING_SECRET}"
|
|
61
|
+
domain-migration-dump-path = "/domain-upgrade-dump/domain_migration_dump-extra-1.json"
|
|
62
|
+
storage.config.properties.databaseName = "${EXTRA_VALIDATOR_1_DB}"
|
|
63
|
+
admin-api.port = ${EXTRA_VALIDATOR_1_ADMIN_API_PORT}
|
|
64
|
+
canton-identifier-config.participant = extra-1
|
|
65
|
+
participant-client {
|
|
66
|
+
admin-api.port = ${EXTRA_PARTICIPANT_1_ADMIN_API_PORT}
|
|
67
|
+
ledger-api {
|
|
68
|
+
client-config.port = ${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}
|
|
69
|
+
auth-config = {
|
|
70
|
+
type = "self-signed"
|
|
71
|
+
user = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
72
|
+
audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
73
|
+
secret = "unsafe"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
auth = {
|
|
78
|
+
algorithm = "hs-256-unsafe"
|
|
79
|
+
audience = "${EXTRA_VALIDATOR_1_AUTH_AUDIENCE}"
|
|
80
|
+
secret = "unsafe"
|
|
81
|
+
}
|
|
82
|
+
ledger-api-user = "${EXTRA_VALIDATOR_1_USER_NAME}"
|
|
83
|
+
validator-wallet-users.0 = "${EXTRA_VALIDATOR_1_WALLET_ADMIN_USER_NAME}"
|
|
84
|
+
validator-party-hint = "${EXTRA_VALIDATOR_1_PARTY_HINT}"
|
|
85
|
+
|
|
86
|
+
domains.global.buy-extra-traffic {
|
|
87
|
+
min-topup-interval = $${?MIN_TRAFFIC_TOPUP_INTERVAL}
|
|
88
|
+
target-throughput = $${?TARGET_TRAFFIC_THROUGHPUT}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
canton.sv-apps.sv.expected-validator-onboardings += { secret = "${EXTRA_VALIDATOR_1_ONBOARDING_SECRET}" }
|
|
93
|
+
|
|
94
|
+
ports:
|
|
95
|
+
- "${EXTRA_VALIDATOR_1_ADMIN_API_PUBLISHED_PORT}:${EXTRA_VALIDATOR_1_ADMIN_API_PORT}"
|
|
96
|
+
postgres-pqs-extra-1:
|
|
97
|
+
image: "postgres:${POSTGRES_VERSION}"
|
|
98
|
+
container_name: postgres-pqs-extra-1
|
|
99
|
+
volumes:
|
|
100
|
+
- postgres-pqs-extra-1:/var/lib/postgresql/data
|
|
101
|
+
- ${LOCALNET_DIR}/docker/postgres/postgres-entrypoint.sh:/postgres-entrypoint.sh
|
|
102
|
+
environment:
|
|
103
|
+
POSTGRES_USER: ${DB_USER}
|
|
104
|
+
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
105
|
+
POSTGRES_DB: postgres
|
|
106
|
+
CREATE_DATABASE_EXTRA_PQS_1: ${EXTRA_PQS_1_POSTGRES_DB}
|
|
107
|
+
ports:
|
|
108
|
+
- "${EXTRA_PQS_1_POSTGRES_PUBLISHED_PORT}:5432"
|
|
109
|
+
entrypoint: /postgres-entrypoint.sh
|
|
110
|
+
healthcheck:
|
|
111
|
+
test: "pg_isready -U ${DB_USER} -d postgres"
|
|
112
|
+
interval: 10s
|
|
113
|
+
timeout: 3s
|
|
114
|
+
retries: 3
|
|
115
|
+
start_period: 30s
|
|
116
|
+
user: "postgres"
|
|
117
|
+
command:
|
|
118
|
+
- postgres
|
|
119
|
+
- -c
|
|
120
|
+
- max_connections=1000
|
|
121
|
+
pqs-extra-1:
|
|
122
|
+
image: ${SCRIBE_IMAGE}:${SCRIBE_VERSION}
|
|
123
|
+
container_name: pqs-extra-1
|
|
124
|
+
environment:
|
|
125
|
+
SCRIBE_SOURCE_LEDGER_HOST: canton
|
|
126
|
+
SCRIBE_SOURCE_LEDGER_PORT: ${EXTRA_PARTICIPANT_1_LEDGER_API_PORT}
|
|
127
|
+
SCRIBE_SOURCE_LEDGER_AUTH: OAuth
|
|
128
|
+
SCRIBE_TARGET_POSTGRES_HOST: postgres-pqs-extra-1
|
|
129
|
+
SCRIBE_TARGET_POSTGRES_PORT: 5432
|
|
130
|
+
SCRIBE_TARGET_POSTGRES_DATABASE: ${EXTRA_PQS_1_POSTGRES_DB}
|
|
131
|
+
SCRIBE_TARGET_POSTGRES_USERNAME: ${DB_USER}
|
|
132
|
+
SCRIBE_TARGET_POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
133
|
+
SCRIBE_CONFIG: /onboarding/extra-1-pqs.conf
|
|
134
|
+
volumes:
|
|
135
|
+
- onboarding:/onboarding
|
|
136
|
+
command:
|
|
137
|
+
- pipeline
|
|
138
|
+
- ledger
|
|
139
|
+
- postgres-document
|
|
140
|
+
depends_on:
|
|
141
|
+
canton:
|
|
142
|
+
condition: service_healthy
|
|
143
|
+
splice-onboarding:
|
|
144
|
+
condition: service_healthy
|
|
145
|
+
postgres-pqs-extra-1:
|
|
146
|
+
condition: service_healthy
|
|
147
|
+
restart: on-failure:100
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
START_LOCAL_GENERATED_DIR=/home/helena/env/daml/typescript-sdk/node/.generated/start-local
|
|
2
|
+
CREATE_DATABASE_EXTRA_1=participant-extra-1
|
|
3
|
+
CREATE_DATABASE_EXTRA_VALIDATOR_1=validator-extra-1
|
|
4
|
+
CREATE_DATABASE_EXTRA_PQS_1=pqs-extra-1
|
|
5
|
+
EXTRA_PARTICIPANT_1_NAME=extra-1
|
|
6
|
+
EXTRA_PARTICIPANT_1_DB=participant-extra-1
|
|
7
|
+
EXTRA_PARTICIPANT_1_PARTY_HINT=extra_1_quickstart-helena-1
|
|
8
|
+
EXTRA_PARTICIPANT_1_LEDGER_API_PORT=5901
|
|
9
|
+
EXTRA_PARTICIPANT_1_ADMIN_API_PORT=5902
|
|
10
|
+
EXTRA_PARTICIPANT_1_JSON_API_PORT=5975
|
|
11
|
+
EXTRA_PARTICIPANT_1_HTTP_HEALTHCHECK_PORT=5900
|
|
12
|
+
EXTRA_PARTICIPANT_1_GRPC_HEALTHCHECK_PORT=5961
|
|
13
|
+
EXTRA_PARTICIPANT_1_LEDGER_API_PUBLISHED_PORT=5901
|
|
14
|
+
EXTRA_PARTICIPANT_1_ADMIN_API_PUBLISHED_PORT=5902
|
|
15
|
+
EXTRA_PARTICIPANT_1_JSON_API_PUBLISHED_PORT=5975
|
|
16
|
+
EXTRA_VALIDATOR_1_DB=validator-extra-1
|
|
17
|
+
EXTRA_VALIDATOR_1_PARTY_HINT=validator_1_quickstart-helena-1
|
|
18
|
+
EXTRA_VALIDATOR_1_ONBOARDING_SECRET=extra-1-validator-onboarding-secret
|
|
19
|
+
EXTRA_VALIDATOR_1_ADMIN_API_PORT=5903
|
|
20
|
+
EXTRA_VALIDATOR_1_ADMIN_API_PUBLISHED_PORT=5903
|
|
21
|
+
EXTRA_VALIDATOR_1_USER_NAME=ledger-api-user
|
|
22
|
+
EXTRA_VALIDATOR_1_WALLET_ADMIN_USER_NAME=extra-1
|
|
23
|
+
EXTRA_VALIDATOR_1_AUTH_AUDIENCE=https://canton.network.global
|
|
24
|
+
EXTRA_VALIDATOR_1_AUTH_MODE=shared-secret
|
|
25
|
+
EXTRA_PQS_1_NAME=pqs-extra-1
|
|
26
|
+
EXTRA_PQS_1_USER_NAME=extra-1-pqs-user
|
|
27
|
+
EXTRA_PQS_1_POSTGRES_NAME=postgres-pqs-extra-1
|
|
28
|
+
EXTRA_PQS_1_POSTGRES_DB=pqs-extra-1
|
|
29
|
+
EXTRA_PQS_1_POSTGRES_PUBLISHED_PORT=5541
|
|
30
|
+
EXTRA_PQS_1_CONFIG_FILE=extra-1-pqs.conf
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHash,
|
|
3
|
+
createPrivateKey,
|
|
4
|
+
createPublicKey,
|
|
5
|
+
generateKeyPairSync,
|
|
6
|
+
sign,
|
|
7
|
+
} from "node:crypto";
|
|
8
|
+
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const maximumTtlSeconds = 600;
|
|
13
|
+
|
|
14
|
+
function encodeJson(value) {
|
|
15
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getKid(jwk) {
|
|
19
|
+
const thumbprint = JSON.stringify({
|
|
20
|
+
crv: jwk.crv,
|
|
21
|
+
kty: jwk.kty,
|
|
22
|
+
x: jwk.x,
|
|
23
|
+
y: jwk.y,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return createHash("sha256").update(thumbprint).digest("base64url");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function toPublicJwk(publicKey) {
|
|
30
|
+
const jwk = publicKey.export({ format: "jwk" });
|
|
31
|
+
|
|
32
|
+
if (jwk.kty !== "EC" || jwk.crv !== "P-256" || !jwk.x || !jwk.y) {
|
|
33
|
+
throw new Error("Expected a P-256 public key.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
alg: "ES256",
|
|
38
|
+
crv: jwk.crv,
|
|
39
|
+
kid: getKid(jwk),
|
|
40
|
+
kty: jwk.kty,
|
|
41
|
+
use: "sig",
|
|
42
|
+
x: jwk.x,
|
|
43
|
+
y: jwk.y,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function writePrivateFileAsync(path, content) {
|
|
48
|
+
await writeFile(path, content, { mode: 0o600 });
|
|
49
|
+
await chmod(path, 0o600);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function writePublicFileAsync(path, content) {
|
|
53
|
+
await writeFile(path, content, { mode: 0o644 });
|
|
54
|
+
await chmod(path, 0o644);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function generateKeyMaterialAsync(runtimeDirectory) {
|
|
58
|
+
await mkdir(runtimeDirectory, { recursive: true });
|
|
59
|
+
|
|
60
|
+
const { privateKey, publicKey } = generateKeyPairSync("ec", {
|
|
61
|
+
namedCurve: "prime256v1",
|
|
62
|
+
});
|
|
63
|
+
const jwk = toPublicJwk(publicKey);
|
|
64
|
+
const privateKeyPath = join(runtimeDirectory, "es256-private-key.pem");
|
|
65
|
+
const jwksPath = join(runtimeDirectory, "jwks.json");
|
|
66
|
+
|
|
67
|
+
await writePrivateFileAsync(
|
|
68
|
+
privateKeyPath,
|
|
69
|
+
privateKey.export({ format: "pem", type: "pkcs8" }),
|
|
70
|
+
);
|
|
71
|
+
await writePublicFileAsync(jwksPath, `${JSON.stringify({ keys: [jwk] })}\n`);
|
|
72
|
+
|
|
73
|
+
return { jwk, jwks: { keys: [jwk] }, jwksPath, privateKeyPath };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function mintTokenAsync({
|
|
77
|
+
audience,
|
|
78
|
+
privateKeyPath,
|
|
79
|
+
subject,
|
|
80
|
+
ttlSeconds,
|
|
81
|
+
}) {
|
|
82
|
+
if (!Number.isInteger(ttlSeconds) || ttlSeconds < 1 || ttlSeconds > maximumTtlSeconds) {
|
|
83
|
+
throw new Error(`TTL must be an integer between 1 and ${maximumTtlSeconds} seconds.`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const privateKey = createPrivateKey(await readFile(privateKeyPath));
|
|
87
|
+
const jwk = toPublicJwk(createPublicKey(privateKey));
|
|
88
|
+
const issuedAt = Math.floor(Date.now() / 1000);
|
|
89
|
+
const encodedHeader = encodeJson({ alg: "ES256", kid: jwk.kid, typ: "JWT" });
|
|
90
|
+
const encodedPayload = encodeJson({
|
|
91
|
+
aud: audience,
|
|
92
|
+
exp: issuedAt + ttlSeconds,
|
|
93
|
+
iat: issuedAt,
|
|
94
|
+
nbf: issuedAt,
|
|
95
|
+
scope: "daml_ledger_api",
|
|
96
|
+
sub: subject,
|
|
97
|
+
});
|
|
98
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
99
|
+
const signature = sign("sha256", Buffer.from(signingInput), {
|
|
100
|
+
dsaEncoding: "ieee-p1363",
|
|
101
|
+
key: privateKey,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return `${signingInput}.${signature.toString("base64url")}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function validateSuppliedKeyAsync({ jwks, privateKeyPath }) {
|
|
108
|
+
const privateKey = createPrivateKey(await readFile(privateKeyPath));
|
|
109
|
+
const expectedJwk = toPublicJwk(createPublicKey(privateKey));
|
|
110
|
+
const matches = jwks.keys.some(
|
|
111
|
+
(jwk) =>
|
|
112
|
+
jwk.kid === expectedJwk.kid &&
|
|
113
|
+
jwk.kty === expectedJwk.kty &&
|
|
114
|
+
jwk.crv === expectedJwk.crv &&
|
|
115
|
+
jwk.x === expectedJwk.x &&
|
|
116
|
+
jwk.y === expectedJwk.y,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (!matches) {
|
|
120
|
+
throw new Error("Supplied JWKS does not contain a matching P-256 public key.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getArgument(argumentsList, name) {
|
|
125
|
+
const index = argumentsList.indexOf(name);
|
|
126
|
+
|
|
127
|
+
if (index < 0 || argumentsList[index + 1] === undefined) {
|
|
128
|
+
throw new Error(`Missing ${name}.`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return argumentsList[index + 1];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function mainAsync() {
|
|
135
|
+
const [command, ...argumentsList] = process.argv.slice(2);
|
|
136
|
+
|
|
137
|
+
if (command === "init") {
|
|
138
|
+
const material = await generateKeyMaterialAsync(
|
|
139
|
+
getArgument(argumentsList, "--runtime-dir"),
|
|
140
|
+
);
|
|
141
|
+
process.stdout.write(`${JSON.stringify(material)}\n`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (command === "mint") {
|
|
146
|
+
const token = await mintTokenAsync({
|
|
147
|
+
audience: getArgument(argumentsList, "--audience"),
|
|
148
|
+
privateKeyPath: getArgument(argumentsList, "--private-key-path"),
|
|
149
|
+
subject: getArgument(argumentsList, "--subject"),
|
|
150
|
+
ttlSeconds: Number.parseInt(getArgument(argumentsList, "--ttl-seconds"), 10),
|
|
151
|
+
});
|
|
152
|
+
process.stdout.write(`${token}\n`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (command === "validate-supplied") {
|
|
157
|
+
const jwks = JSON.parse(
|
|
158
|
+
await readFile(getArgument(argumentsList, "--jwks-path"), "utf8"),
|
|
159
|
+
);
|
|
160
|
+
await validateSuppliedKeyAsync({
|
|
161
|
+
jwks,
|
|
162
|
+
privateKeyPath: getArgument(argumentsList, "--private-key-path"),
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
throw new Error("Expected 'init', 'mint', or 'validate-supplied'.");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const scriptPath = fileURLToPath(import.meta.url);
|
|
171
|
+
|
|
172
|
+
if (process.argv[1] === scriptPath) {
|
|
173
|
+
mainAsync().catch((error) => {
|
|
174
|
+
process.stderr.write(`${error.message}\n`);
|
|
175
|
+
process.exitCode = 1;
|
|
176
|
+
});
|
|
177
|
+
}
|