@europeum-ebsi/cli 0.0.0 → 1.0.0-rc.0
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/LICENSE.txt +289 -289
- package/LICENSES.txt +538 -0
- package/README.md +1140 -98
- package/dist/api/client.d.ts +4 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +14 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/fetch.d.ts +13 -0
- package/dist/api/fetch.d.ts.map +1 -0
- package/dist/api/fetch.js +30 -0
- package/dist/api/fetch.js.map +1 -0
- package/dist/api/params.d.ts +4 -0
- package/dist/api/params.d.ts.map +1 -0
- package/dist/api/params.js +9 -0
- package/dist/api/params.js.map +1 -0
- package/dist/auth/dcql.d.ts +5 -0
- package/dist/auth/dcql.d.ts.map +1 -0
- package/dist/auth/dcql.js +41 -0
- package/dist/auth/dcql.js.map +1 -0
- package/dist/auth/presentation.d.ts +30 -0
- package/dist/auth/presentation.d.ts.map +1 -0
- package/dist/auth/presentation.js +99 -0
- package/dist/auth/presentation.js.map +1 -0
- package/dist/auth/token.d.ts +11 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +116 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +96 -10
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +99 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/config-cmd.d.ts +3 -0
- package/dist/commands/config-cmd.d.ts.map +1 -0
- package/dist/commands/config-cmd.js +86 -0
- package/dist/commands/config-cmd.js.map +1 -0
- package/dist/commands/contracts-registry.d.ts +3 -0
- package/dist/commands/contracts-registry.d.ts.map +1 -0
- package/dist/commands/contracts-registry.js +132 -0
- package/dist/commands/contracts-registry.js.map +1 -0
- package/dist/commands/did-registry.d.ts +3 -0
- package/dist/commands/did-registry.d.ts.map +1 -0
- package/dist/commands/did-registry.js +110 -0
- package/dist/commands/did-registry.js.map +1 -0
- package/dist/commands/faucet.d.ts +3 -0
- package/dist/commands/faucet.d.ts.map +1 -0
- package/dist/commands/faucet.js +78 -0
- package/dist/commands/faucet.js.map +1 -0
- package/dist/commands/health.d.ts +3 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +20 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/issuers-registry.d.ts +3 -0
- package/dist/commands/issuers-registry.d.ts.map +1 -0
- package/dist/commands/issuers-registry.js +340 -0
- package/dist/commands/issuers-registry.js.map +1 -0
- package/dist/commands/ledger.d.ts +3 -0
- package/dist/commands/ledger.d.ts.map +1 -0
- package/dist/commands/ledger.js +549 -372
- package/dist/commands/ledger.js.map +1 -1
- package/dist/commands/onboarding.d.ts +3 -0
- package/dist/commands/onboarding.d.ts.map +1 -0
- package/dist/commands/onboarding.js +301 -0
- package/dist/commands/onboarding.js.map +1 -0
- package/dist/commands/openapi.d.ts +3 -0
- package/dist/commands/openapi.d.ts.map +1 -0
- package/dist/commands/openapi.js +37 -0
- package/dist/commands/openapi.js.map +1 -0
- package/dist/commands/policies-registry.d.ts +3 -0
- package/dist/commands/policies-registry.d.ts.map +1 -0
- package/dist/commands/policies-registry.js +198 -0
- package/dist/commands/policies-registry.js.map +1 -0
- package/dist/commands/registry.d.ts +27 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +62 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/schemas-registry.d.ts +3 -0
- package/dist/commands/schemas-registry.d.ts.map +1 -0
- package/dist/commands/schemas-registry.js +231 -0
- package/dist/commands/schemas-registry.js.map +1 -0
- package/dist/commands/shared/args.d.ts +2 -0
- package/dist/commands/shared/args.d.ts.map +1 -0
- package/dist/commands/shared/args.js +4 -0
- package/dist/commands/shared/args.js.map +1 -0
- package/dist/commands/shared/wallet-opts.d.ts +9 -0
- package/dist/commands/shared/wallet-opts.d.ts.map +1 -0
- package/dist/commands/shared/wallet-opts.js +44 -0
- package/dist/commands/shared/wallet-opts.js.map +1 -0
- package/dist/commands/timestamp.d.ts +3 -0
- package/dist/commands/timestamp.d.ts.map +1 -0
- package/dist/commands/timestamp.js +250 -0
- package/dist/commands/timestamp.js.map +1 -0
- package/dist/commands/track-and-trace.d.ts +3 -0
- package/dist/commands/track-and-trace.d.ts.map +1 -0
- package/dist/commands/track-and-trace.js +235 -0
- package/dist/commands/track-and-trace.js.map +1 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +123 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config/config.d.ts +45 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +111 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/ebsi-env.d.ts +4 -0
- package/dist/config/ebsi-env.d.ts.map +1 -0
- package/dist/config/ebsi-env.js +37 -0
- package/dist/config/ebsi-env.js.map +1 -0
- package/dist/crypto/wallet.d.ts +34 -0
- package/dist/crypto/wallet.d.ts.map +1 -0
- package/dist/crypto/wallet.js +100 -0
- package/dist/crypto/wallet.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/ledger/read.d.ts +11 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +24 -0
- package/dist/ledger/read.js.map +1 -0
- package/dist/ledger/registries.d.ts +25 -0
- package/dist/ledger/registries.d.ts.map +1 -0
- package/dist/ledger/registries.js +111 -0
- package/dist/ledger/registries.js.map +1 -0
- package/dist/ledger/write.d.ts +43 -0
- package/dist/ledger/write.d.ts.map +1 -0
- package/dist/ledger/write.js +119 -0
- package/dist/ledger/write.js.map +1 -0
- package/dist/onboarding/vc.d.ts +18 -0
- package/dist/onboarding/vc.d.ts.map +1 -0
- package/dist/onboarding/vc.js +72 -0
- package/dist/onboarding/vc.js.map +1 -0
- package/dist/output/format.d.ts +7 -0
- package/dist/output/format.d.ts.map +1 -0
- package/dist/output/format.js +94 -0
- package/dist/output/format.js.map +1 -0
- package/dist/tui/App.d.ts +3 -0
- package/dist/tui/App.d.ts.map +1 -0
- package/dist/tui/App.js +99 -0
- package/dist/tui/App.js.map +1 -0
- package/dist/tui/CommandPalette.d.ts +8 -0
- package/dist/tui/CommandPalette.d.ts.map +1 -0
- package/dist/tui/CommandPalette.js +105 -0
- package/dist/tui/CommandPalette.js.map +1 -0
- package/package.json +66 -108
- package/src/api/client.ts +26 -0
- package/src/api/fetch.ts +53 -0
- package/src/api/params.ts +17 -0
- package/src/auth/dcql.ts +84 -0
- package/src/auth/presentation.ts +255 -0
- package/src/auth/token.ts +244 -0
- package/src/cli.ts +164 -0
- package/src/commands/auth.ts +119 -0
- package/src/commands/config-cmd.ts +122 -0
- package/src/commands/contracts-registry.ts +156 -0
- package/src/commands/did-registry.ts +126 -0
- package/src/commands/faucet.ts +112 -0
- package/src/commands/health.ts +21 -0
- package/src/commands/issuers-registry.ts +385 -0
- package/src/commands/ledger.ts +777 -0
- package/src/commands/onboarding.ts +411 -0
- package/src/commands/openapi.ts +42 -0
- package/src/commands/policies-registry.ts +218 -0
- package/src/commands/registry.ts +152 -0
- package/src/commands/schemas-registry.ts +255 -0
- package/src/commands/shared/args.ts +14 -0
- package/src/commands/shared/wallet-opts.ts +85 -0
- package/src/commands/timestamp.ts +272 -0
- package/src/commands/track-and-trace.ts +263 -0
- package/src/commands/wallet.ts +175 -0
- package/src/config/config.ts +275 -0
- package/src/config/ebsi-env.ts +67 -0
- package/src/crypto/wallet.ts +291 -0
- package/src/index.ts +24 -0
- package/src/ledger/read.ts +70 -0
- package/src/ledger/registries.ts +285 -0
- package/src/ledger/write.ts +381 -0
- package/src/onboarding/vc.ts +205 -0
- package/src/output/format.ts +157 -0
- package/src/tui/App.tsx +282 -0
- package/src/tui/CommandPalette.tsx +223 -0
- package/bin/cli.js +0 -13
- package/dist/abi/pilot/DidRegistry.js +0 -568
- package/dist/abi/pilot/DidRegistry.js.map +0 -1
- package/dist/abi/pilot/Ptr.js +0 -666
- package/dist/abi/pilot/Ptr.js.map +0 -1
- package/dist/abi/pilot/SchemaSCRegistry.js +0 -264
- package/dist/abi/pilot/SchemaSCRegistry.js.map +0 -1
- package/dist/abi/pilot/Tcr.js +0 -715
- package/dist/abi/pilot/Tcr.js.map +0 -1
- package/dist/abi/pilot/Timestamp.js +0 -658
- package/dist/abi/pilot/Timestamp.js.map +0 -1
- package/dist/abi/pilot/Tir.js +0 -428
- package/dist/abi/pilot/Tir.js.map +0 -1
- package/dist/abi/pilot/TnT.js +0 -842
- package/dist/abi/pilot/TnT.js.map +0 -1
- package/dist/abi/pilot/Tpr.js +0 -492
- package/dist/abi/pilot/Tpr.js.map +0 -1
- package/dist/abi/test/DidRegistry.js +0 -568
- package/dist/abi/test/DidRegistry.js.map +0 -1
- package/dist/abi/test/Ptr.js +0 -666
- package/dist/abi/test/Ptr.js.map +0 -1
- package/dist/abi/test/SchemaSCRegistry.js +0 -300
- package/dist/abi/test/SchemaSCRegistry.js.map +0 -1
- package/dist/abi/test/Tcr.js +0 -715
- package/dist/abi/test/Tcr.js.map +0 -1
- package/dist/abi/test/Timestamp.js +0 -658
- package/dist/abi/test/Timestamp.js.map +0 -1
- package/dist/abi/test/Tir.js +0 -428
- package/dist/abi/test/Tir.js.map +0 -1
- package/dist/abi/test/TnT.js +0 -842
- package/dist/abi/test/TnT.js.map +0 -1
- package/dist/abi/test/Tpr.js +0 -492
- package/dist/abi/test/Tpr.js.map +0 -1
- package/dist/app.js +0 -659
- package/dist/app.js.map +0 -1
- package/dist/buildParam/didr.js +0 -374
- package/dist/buildParam/didr.js.map +0 -1
- package/dist/buildParam/index.js +0 -53
- package/dist/buildParam/index.js.map +0 -1
- package/dist/buildParam/ptr.js +0 -80
- package/dist/buildParam/ptr.js.map +0 -1
- package/dist/buildParam/tcr.js +0 -36
- package/dist/buildParam/tcr.js.map +0 -1
- package/dist/buildParam/timestamp.js +0 -350
- package/dist/buildParam/timestamp.js.map +0 -1
- package/dist/buildParam/tir.js +0 -110
- package/dist/buildParam/tir.js.map +0 -1
- package/dist/buildParam/tnt.js +0 -214
- package/dist/buildParam/tnt.js.map +0 -1
- package/dist/buildParam/tpr.js +0 -91
- package/dist/buildParam/tpr.js.map +0 -1
- package/dist/buildParam/tsr.js +0 -115
- package/dist/buildParam/tsr.js.map +0 -1
- package/dist/commands/authorisation.js +0 -144
- package/dist/commands/authorisation.js.map +0 -1
- package/dist/commands/compute.js +0 -680
- package/dist/commands/compute.js.map +0 -1
- package/dist/commands/conformance.js +0 -813
- package/dist/commands/conformance.js.map +0 -1
- package/dist/commands/hardwarewallet.js +0 -41
- package/dist/commands/hardwarewallet.js.map +0 -1
- package/dist/commands/index.js +0 -8
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/ptr.js +0 -54
- package/dist/commands/ptr.js.map +0 -1
- package/dist/commands/tcr.js +0 -50
- package/dist/commands/tcr.js.map +0 -1
- package/dist/commands/tir.js +0 -64
- package/dist/commands/tir.js.map +0 -1
- package/dist/commands/tnl.js +0 -81
- package/dist/commands/tnl.js.map +0 -1
- package/dist/commands/tsr.js +0 -45
- package/dist/commands/tsr.js.map +0 -1
- package/dist/commands/view.js +0 -53
- package/dist/commands/view.js.map +0 -1
- package/dist/config.js +0 -497
- package/dist/config.js.map +0 -1
- package/dist/interfaces/context.js +0 -2
- package/dist/interfaces/context.js.map +0 -1
- package/dist/interfaces/contracts/ProxyFactory.js +0 -2
- package/dist/interfaces/contracts/ProxyFactory.js.map +0 -1
- package/dist/interfaces/contracts/ProxyTemplateRegistry.js +0 -2
- package/dist/interfaces/contracts/ProxyTemplateRegistry.js.map +0 -1
- package/dist/interfaces/contracts/SchemaSCRegistry.js +0 -2
- package/dist/interfaces/contracts/SchemaSCRegistry.js.map +0 -1
- package/dist/interfaces/contracts/common.js +0 -2
- package/dist/interfaces/contracts/common.js.map +0 -1
- package/dist/interfaces/index.js +0 -5
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/jsonrpc.interface.js +0 -2
- package/dist/interfaces/jsonrpc.interface.js.map +0 -1
- package/dist/interfaces/paginated-list.interface.js +0 -2
- package/dist/interfaces/paginated-list.interface.js.map +0 -1
- package/dist/interfaces/unsigned-transaction.interface.js +0 -2
- package/dist/interfaces/unsigned-transaction.interface.js.map +0 -1
- package/dist/interfaces/utils.interface.js +0 -2
- package/dist/interfaces/utils.interface.js.map +0 -1
- package/dist/programs/migrateDid.js +0 -159
- package/dist/programs/migrateDid.js.map +0 -1
- package/dist/programs/migrateDids.js +0 -232
- package/dist/programs/migrateDids.js.map +0 -1
- package/dist/programs/migrateTsr.js +0 -201
- package/dist/programs/migrateTsr.js.map +0 -1
- package/dist/scripts/accreditAndAuthorize/conformance/step1 +0 -34
- package/dist/scripts/accreditAndAuthorize/conformance/step2 +0 -18
- package/dist/scripts/accreditAndAuthorize/conformance/step3 +0 -9
- package/dist/scripts/accreditAndAuthorize/conformance/step4 +0 -27
- package/dist/scripts/accreditAndAuthorize/conformance/step5 +0 -13
- package/dist/scripts/accreditAndAuthorize/conformance/step6 +0 -14
- package/dist/scripts/accreditAndAuthorize/conformance/step7 +0 -7
- package/dist/scripts/accreditAndAuthorize/test/step1 +0 -34
- package/dist/scripts/accreditAndAuthorize/test/step2 +0 -18
- package/dist/scripts/accreditAndAuthorize/test/step3 +0 -9
- package/dist/scripts/accreditAndAuthorize/test/step4 +0 -27
- package/dist/scripts/accreditAndAuthorize/test/step5 +0 -13
- package/dist/scripts/accreditAndAuthorize/test/step6 +0 -14
- package/dist/scripts/accreditAndAuthorize/test/step7 +0 -7
- package/dist/scripts/accreditTI +0 -21
- package/dist/scripts/assets/Nodes.json +0 -27
- package/dist/scripts/assets/vcdm1.1/CTRevocableCredential.json +0 -30
- package/dist/scripts/assets/vcdm1.1/CredentialToAttestVerifiableAuthorisationForTrustChain.json +0 -29
- package/dist/scripts/assets/vcdm1.1/Nodes.json +0 -27
- package/dist/scripts/assets/vcdm1.1/TrustedNodesList.json +0 -35
- package/dist/scripts/assets/vcdm1.1/VerifiableAccreditationToAccredit.json +0 -35
- package/dist/scripts/assets/vcdm1.1/VerifiableAccreditationToAttest.json +0 -33
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationForTrustChain.json +0 -22
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationToInvoke.json +0 -24
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationToOnboard.json +0 -24
- package/dist/scripts/assets/vcdm2.0/CredentialToAttestVerifiableAuthorisationForTrustChain.json +0 -29
- package/dist/scripts/assets/vcdm2.0/TrustedNodesList.json +0 -36
- package/dist/scripts/assets/vcdm2.0/VerifiableAccreditationToAccredit.json +0 -40
- package/dist/scripts/assets/vcdm2.0/VerifiableAccreditationToAttest.json +0 -38
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationForTrustChain.json +0 -30
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationToInvoke.json +0 -24
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationToOnboard.json +0 -23
- package/dist/scripts/bootstrap/0a-loadTPROperator +0 -5
- package/dist/scripts/bootstrap/0b-loadAdmin +0 -8
- package/dist/scripts/bootstrap/1-populateTPR +0 -92
- package/dist/scripts/bootstrap/2-populateDID +0 -6
- package/dist/scripts/bootstrap/3-populateTimestamp +0 -9
- package/dist/scripts/bootstrap/4-populateTIR +0 -8
- package/dist/scripts/bootstrap/5-populateTSR +0 -85
- package/dist/scripts/bootstrap/6-setupConformanceIssuer +0 -35
- package/dist/scripts/bootstrap/README.md +0 -218
- package/dist/scripts/issueVcInvoke +0 -10
- package/dist/scripts/issueVcOnboard +0 -9
- package/dist/scripts/issueVcRootTAO +0 -11
- package/dist/scripts/issueVcTAO +0 -12
- package/dist/scripts/issueVcTI +0 -12
- package/dist/scripts/issueVcTnl +0 -32
- package/dist/scripts/issue_CTRevocableCredential +0 -12
- package/dist/scripts/issue_SelfAttestationSupportOffice +0 -10
- package/dist/scripts/issue_VerifiableAccreditationToAccredit +0 -11
- package/dist/scripts/issue_VerifiableAccreditationToAttest +0 -11
- package/dist/scripts/issue_VerifiableAuthorisationForTrustChain +0 -10
- package/dist/scripts/issue_VerifiableAuthorisationToOnboard +0 -9
- package/dist/scripts/preregisterIssuer +0 -6
- package/dist/scripts/registerDidDocument +0 -15
- package/dist/scripts/registerIssuer +0 -6
- package/dist/scripts/updateVcRootTAO +0 -10
- package/dist/scripts/updateVcTAO +0 -11
- package/dist/scripts/updateVcTI +0 -11
- package/dist/scripts/vcdm2.0/issueSelfAttestationSupportOffice +0 -10
- package/dist/scripts/vcdm2.0/issueVcInvoke +0 -12
- package/dist/scripts/vcdm2.0/issueVcOnboard +0 -11
- package/dist/scripts/vcdm2.0/issueVcRootTAO +0 -14
- package/dist/scripts/vcdm2.0/issueVcTAO +0 -15
- package/dist/scripts/vcdm2.0/issueVcTI +0 -15
- package/dist/scripts/vcdm2.0/issueVcTnl +0 -34
- package/dist/scripts/vcdm2.0/registerDidDocument +0 -15
- package/dist/scripts/vcdm2.0/updateVcRootTAO +0 -13
- package/dist/scripts/vcdm2.0/updateVcTAO +0 -14
- package/dist/scripts/vcdm2.0/updateVcTI +0 -14
- package/dist/scripts/vcdm2.0/verifyVcTnl +0 -10
- package/dist/scripts/verifyVcTnl +0 -10
- package/dist/scripts/wct/accreditAndAuthorize +0 -133
- package/dist/scripts/wct/accreditAndAuthorize2 +0 -89
- package/dist/scripts/wct/holderWallet +0 -39
- package/dist/scripts/wct/holderWallet2 +0 -39
- package/dist/scripts/wct/issueToHolder +0 -38
- package/dist/scripts/wct/issueToHolder2 +0 -38
- package/dist/scripts/wct/pda1 +0 -3
- package/dist/scripts/wct/verifier +0 -8
- package/dist/scripts/wct/verifier2 +0 -7
- package/dist/utils/Client.js +0 -155
- package/dist/utils/Client.js.map +0 -1
- package/dist/utils/HardwareWallet.js +0 -326
- package/dist/utils/HardwareWallet.js.map +0 -1
- package/dist/utils/http.js +0 -132
- package/dist/utils/http.js.map +0 -1
- package/dist/utils/index.js +0 -8
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/jsonrpc.js +0 -38
- package/dist/utils/jsonrpc.js.map +0 -1
- package/dist/utils/print.js +0 -56
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/utils.js +0 -427
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/vcdm.js +0 -47
- package/dist/utils/vcdm.js.map +0 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type { CommandDescriptor } from "./registry.ts";
|
|
2
|
+
|
|
3
|
+
import { getClient, unwrap } from "../api/fetch.ts";
|
|
4
|
+
import { q } from "../api/params.ts";
|
|
5
|
+
import { contractAddressOptionFor } from "../ledger/registries.ts";
|
|
6
|
+
import { requiredArg } from "./shared/args.ts";
|
|
7
|
+
|
|
8
|
+
const PAGINATION_OPTIONS = [
|
|
9
|
+
{
|
|
10
|
+
description: "Cursor for pagination (page[after])",
|
|
11
|
+
flags: "--page-after <cursor>",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
description: "Maximum number of items per page (page[size])",
|
|
15
|
+
flags: "--page-size <n>",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const { option: CONTRACT_ADDRESS_OPTION, resolve: contractAddress } =
|
|
20
|
+
contractAddressOptionFor("timestamp");
|
|
21
|
+
|
|
22
|
+
export const timestampCommands: CommandDescriptor[] = [
|
|
23
|
+
{
|
|
24
|
+
args: [],
|
|
25
|
+
group: "Timestamp",
|
|
26
|
+
async handler(_args, opts, config) {
|
|
27
|
+
const client = getClient(config);
|
|
28
|
+
const result = await client.GET("/timestamp/timestamps", {
|
|
29
|
+
params: {
|
|
30
|
+
query: q({
|
|
31
|
+
contractAddress: contractAddress(opts),
|
|
32
|
+
"page[after]": opts["pageAfter"]
|
|
33
|
+
? Number(opts["pageAfter"])
|
|
34
|
+
: undefined,
|
|
35
|
+
"page[size]": opts["pageSize"]
|
|
36
|
+
? Number(opts["pageSize"])
|
|
37
|
+
: undefined,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return unwrap(result);
|
|
42
|
+
},
|
|
43
|
+
id: "timestamp.timestamps.list",
|
|
44
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
45
|
+
segments: ["timestamp", "timestamps", "list"],
|
|
46
|
+
summary: "List timestamps on the EBSI ledger",
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
args: [
|
|
51
|
+
{
|
|
52
|
+
description: "Timestamp ID",
|
|
53
|
+
example: "0x1234...",
|
|
54
|
+
name: "timestampId",
|
|
55
|
+
required: true,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
group: "Timestamp",
|
|
59
|
+
async handler(args, opts, config) {
|
|
60
|
+
const client = getClient(config);
|
|
61
|
+
const result = await client.GET("/timestamp/timestamps/{timestampId}", {
|
|
62
|
+
params: {
|
|
63
|
+
path: { timestampId: requiredArg(args, "timestampId") },
|
|
64
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return unwrap(result);
|
|
68
|
+
},
|
|
69
|
+
id: "timestamp.timestamps.get",
|
|
70
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
71
|
+
segments: ["timestamp", "timestamps", "get"],
|
|
72
|
+
summary: "Get a timestamp by its ID",
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
args: [],
|
|
77
|
+
group: "Timestamp",
|
|
78
|
+
async handler(_args, opts, config) {
|
|
79
|
+
const client = getClient(config);
|
|
80
|
+
const result = await client.GET("/timestamp/records", {
|
|
81
|
+
params: {
|
|
82
|
+
query: q({
|
|
83
|
+
contractAddress: contractAddress(opts),
|
|
84
|
+
"page[after]": opts["pageAfter"]
|
|
85
|
+
? Number(opts["pageAfter"])
|
|
86
|
+
: undefined,
|
|
87
|
+
"page[size]": opts["pageSize"]
|
|
88
|
+
? Number(opts["pageSize"])
|
|
89
|
+
: undefined,
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return unwrap(result);
|
|
94
|
+
},
|
|
95
|
+
id: "timestamp.records.list",
|
|
96
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
97
|
+
segments: ["timestamp", "records", "list"],
|
|
98
|
+
summary: "List timestamp records",
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
{
|
|
102
|
+
args: [
|
|
103
|
+
{
|
|
104
|
+
description: "Record ID",
|
|
105
|
+
example: "0x1234...",
|
|
106
|
+
name: "recordId",
|
|
107
|
+
required: true,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
group: "Timestamp",
|
|
111
|
+
async handler(args, opts, config) {
|
|
112
|
+
const client = getClient(config);
|
|
113
|
+
const result = await client.GET("/timestamp/records/{recordId}", {
|
|
114
|
+
params: {
|
|
115
|
+
path: { recordId: requiredArg(args, "recordId") },
|
|
116
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
return unwrap(result);
|
|
120
|
+
},
|
|
121
|
+
id: "timestamp.records.get",
|
|
122
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
123
|
+
segments: ["timestamp", "records", "get"],
|
|
124
|
+
summary: "Get a timestamp record by ID",
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
args: [
|
|
129
|
+
{
|
|
130
|
+
description: "Record ID",
|
|
131
|
+
example: "0x1234...",
|
|
132
|
+
name: "recordId",
|
|
133
|
+
required: true,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
group: "Timestamp",
|
|
137
|
+
async handler(args, opts, config) {
|
|
138
|
+
const client = getClient(config);
|
|
139
|
+
const result = await client.GET(
|
|
140
|
+
"/timestamp/records/{recordId}/versions",
|
|
141
|
+
{
|
|
142
|
+
params: {
|
|
143
|
+
path: { recordId: requiredArg(args, "recordId") },
|
|
144
|
+
query: q({
|
|
145
|
+
contractAddress: contractAddress(opts),
|
|
146
|
+
"page[after]": opts["pageAfter"]
|
|
147
|
+
? Number(opts["pageAfter"])
|
|
148
|
+
: undefined,
|
|
149
|
+
"page[size]": opts["pageSize"]
|
|
150
|
+
? Number(opts["pageSize"])
|
|
151
|
+
: undefined,
|
|
152
|
+
}),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
return unwrap(result);
|
|
157
|
+
},
|
|
158
|
+
id: "timestamp.records.versions",
|
|
159
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
160
|
+
segments: ["timestamp", "records", "versions"],
|
|
161
|
+
summary: "List all versions of a timestamp record",
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
{
|
|
165
|
+
args: [
|
|
166
|
+
{
|
|
167
|
+
description: "Record ID",
|
|
168
|
+
example: "0x1234...",
|
|
169
|
+
name: "recordId",
|
|
170
|
+
required: true,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
description: "Version ID",
|
|
174
|
+
example: "0",
|
|
175
|
+
name: "versionId",
|
|
176
|
+
required: true,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
group: "Timestamp",
|
|
180
|
+
async handler(args, opts, config) {
|
|
181
|
+
const client = getClient(config);
|
|
182
|
+
const result = await client.GET(
|
|
183
|
+
"/timestamp/records/{recordId}/versions/{versionId}",
|
|
184
|
+
{
|
|
185
|
+
params: {
|
|
186
|
+
path: {
|
|
187
|
+
recordId: requiredArg(args, "recordId"),
|
|
188
|
+
versionId: Number(requiredArg(args, "versionId")),
|
|
189
|
+
},
|
|
190
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
return unwrap(result);
|
|
195
|
+
},
|
|
196
|
+
id: "timestamp.records.version",
|
|
197
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
198
|
+
segments: ["timestamp", "records", "version"],
|
|
199
|
+
summary: "Get a specific version of a timestamp record",
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
{
|
|
203
|
+
args: [],
|
|
204
|
+
group: "Timestamp",
|
|
205
|
+
async handler(_args, opts, config) {
|
|
206
|
+
const client = getClient(config);
|
|
207
|
+
const result = await client.GET("/timestamp/hash-algorithms", {
|
|
208
|
+
params: {
|
|
209
|
+
query: q({
|
|
210
|
+
contractAddress: contractAddress(opts),
|
|
211
|
+
"page[after]": opts["pageAfter"]
|
|
212
|
+
? Number(opts["pageAfter"])
|
|
213
|
+
: undefined,
|
|
214
|
+
"page[size]": opts["pageSize"]
|
|
215
|
+
? Number(opts["pageSize"])
|
|
216
|
+
: undefined,
|
|
217
|
+
}),
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
return unwrap(result);
|
|
221
|
+
},
|
|
222
|
+
id: "timestamp.hash-algorithms.list",
|
|
223
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
224
|
+
segments: ["timestamp", "hash-algorithms", "list"],
|
|
225
|
+
summary: "List supported hash algorithms for timestamping",
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
{
|
|
229
|
+
args: [
|
|
230
|
+
{
|
|
231
|
+
description: "Hash algorithm ID",
|
|
232
|
+
example: "0",
|
|
233
|
+
name: "hashAlgorithmId",
|
|
234
|
+
required: true,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
group: "Timestamp",
|
|
238
|
+
async handler(args, opts, config) {
|
|
239
|
+
const client = getClient(config);
|
|
240
|
+
const result = await client.GET(
|
|
241
|
+
"/timestamp/hash-algorithms/{hashAlgorithmId}",
|
|
242
|
+
{
|
|
243
|
+
params: {
|
|
244
|
+
path: {
|
|
245
|
+
hashAlgorithmId: Number(requiredArg(args, "hashAlgorithmId")),
|
|
246
|
+
},
|
|
247
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
|
+
return unwrap(result);
|
|
252
|
+
},
|
|
253
|
+
id: "timestamp.hash-algorithms.get",
|
|
254
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
255
|
+
segments: ["timestamp", "hash-algorithms", "get"],
|
|
256
|
+
summary: "Get a hash algorithm by its ID",
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
{
|
|
260
|
+
args: [],
|
|
261
|
+
group: "Timestamp",
|
|
262
|
+
async handler(_args, _opts, config) {
|
|
263
|
+
const client = getClient(config);
|
|
264
|
+
const result = await client.GET("/timestamp/abi");
|
|
265
|
+
return unwrap(result);
|
|
266
|
+
},
|
|
267
|
+
id: "timestamp.abi",
|
|
268
|
+
options: [],
|
|
269
|
+
segments: ["timestamp", "abi"],
|
|
270
|
+
summary: "Get the ABI of the Timestamp smart contract",
|
|
271
|
+
},
|
|
272
|
+
];
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type { CommandDescriptor } from "./registry.ts";
|
|
2
|
+
|
|
3
|
+
import { ApiError, getClient, unwrap } from "../api/fetch.ts";
|
|
4
|
+
import { q } from "../api/params.ts";
|
|
5
|
+
import { contractAddressOptionFor } from "../ledger/registries.ts";
|
|
6
|
+
import { requiredArg } from "./shared/args.ts";
|
|
7
|
+
|
|
8
|
+
const PAGINATION_OPTIONS = [
|
|
9
|
+
{
|
|
10
|
+
description: "Cursor for pagination (page[after])",
|
|
11
|
+
flags: "--page-after <cursor>",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
description: "Maximum number of items per page (page[size])",
|
|
15
|
+
flags: "--page-size <n>",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const { option: CONTRACT_ADDRESS_OPTION, resolve: contractAddress } =
|
|
20
|
+
contractAddressOptionFor("track-and-trace");
|
|
21
|
+
|
|
22
|
+
export const trackAndTraceCommands: CommandDescriptor[] = [
|
|
23
|
+
{
|
|
24
|
+
args: [],
|
|
25
|
+
group: "Track & Trace",
|
|
26
|
+
async handler(_args, opts, config) {
|
|
27
|
+
const client = getClient(config);
|
|
28
|
+
const result = await client.GET("/track-and-trace/documents", {
|
|
29
|
+
params: {
|
|
30
|
+
query: q({
|
|
31
|
+
contractAddress: contractAddress(opts),
|
|
32
|
+
"page[after]": opts["pageAfter"]
|
|
33
|
+
? Number(opts["pageAfter"])
|
|
34
|
+
: undefined,
|
|
35
|
+
"page[size]": opts["pageSize"]
|
|
36
|
+
? Number(opts["pageSize"])
|
|
37
|
+
: undefined,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return unwrap(result);
|
|
42
|
+
},
|
|
43
|
+
id: "track-and-trace.documents.list",
|
|
44
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
45
|
+
segments: ["track-and-trace", "documents", "list"],
|
|
46
|
+
summary: "List all Track and Trace documents",
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
args: [
|
|
51
|
+
{
|
|
52
|
+
description: "Document ID",
|
|
53
|
+
example: "0x1234...",
|
|
54
|
+
name: "documentId",
|
|
55
|
+
required: true,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
group: "Track & Trace",
|
|
59
|
+
async handler(args, opts, config) {
|
|
60
|
+
const client = getClient(config);
|
|
61
|
+
const result = await client.GET(
|
|
62
|
+
"/track-and-trace/documents/{documentId}",
|
|
63
|
+
{
|
|
64
|
+
params: {
|
|
65
|
+
path: { documentId: requiredArg(args, "documentId") },
|
|
66
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
return unwrap(result);
|
|
71
|
+
},
|
|
72
|
+
id: "track-and-trace.documents.get",
|
|
73
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
74
|
+
segments: ["track-and-trace", "documents", "get"],
|
|
75
|
+
summary: "Get a Track and Trace document by ID",
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
args: [
|
|
80
|
+
{
|
|
81
|
+
description: "Document ID",
|
|
82
|
+
example: "0x1234...",
|
|
83
|
+
name: "documentId",
|
|
84
|
+
required: true,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
group: "Track & Trace",
|
|
88
|
+
async handler(args, opts, config) {
|
|
89
|
+
const client = getClient(config);
|
|
90
|
+
const result = await client.GET(
|
|
91
|
+
"/track-and-trace/documents/{documentId}/events",
|
|
92
|
+
{
|
|
93
|
+
params: {
|
|
94
|
+
path: { documentId: requiredArg(args, "documentId") },
|
|
95
|
+
query: q({
|
|
96
|
+
contractAddress: contractAddress(opts),
|
|
97
|
+
"page[after]": opts["pageAfter"]
|
|
98
|
+
? Number(opts["pageAfter"])
|
|
99
|
+
: undefined,
|
|
100
|
+
"page[size]": opts["pageSize"]
|
|
101
|
+
? Number(opts["pageSize"])
|
|
102
|
+
: undefined,
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
return unwrap(result);
|
|
108
|
+
},
|
|
109
|
+
id: "track-and-trace.documents.events",
|
|
110
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
111
|
+
segments: ["track-and-trace", "documents", "events"],
|
|
112
|
+
summary: "List events for a Track and Trace document",
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
{
|
|
116
|
+
args: [
|
|
117
|
+
{
|
|
118
|
+
description: "Document ID",
|
|
119
|
+
example: "0x1234...",
|
|
120
|
+
name: "documentId",
|
|
121
|
+
required: true,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
description: "Event ID",
|
|
125
|
+
example:
|
|
126
|
+
"0x4791c04d2e4838042c67f3e739ab8639b6bd0f6896ec7e32e99c640d43b530c7",
|
|
127
|
+
name: "eventId",
|
|
128
|
+
required: true,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
group: "Track & Trace",
|
|
132
|
+
async handler(args, opts, config) {
|
|
133
|
+
const client = getClient(config);
|
|
134
|
+
const result = await client.GET(
|
|
135
|
+
"/track-and-trace/documents/{documentId}/events/{eventId}",
|
|
136
|
+
{
|
|
137
|
+
params: {
|
|
138
|
+
path: {
|
|
139
|
+
documentId: requiredArg(args, "documentId"),
|
|
140
|
+
eventId: requiredArg(args, "eventId"),
|
|
141
|
+
},
|
|
142
|
+
query: q({ contractAddress: contractAddress(opts) }),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
return unwrap(result);
|
|
147
|
+
},
|
|
148
|
+
id: "track-and-trace.documents.event",
|
|
149
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
150
|
+
segments: ["track-and-trace", "documents", "event"],
|
|
151
|
+
summary: "Get an event for a Track and Trace document",
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
{
|
|
155
|
+
args: [
|
|
156
|
+
{
|
|
157
|
+
description: "Document ID",
|
|
158
|
+
example: "0x1234...",
|
|
159
|
+
name: "documentId",
|
|
160
|
+
required: true,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
group: "Track & Trace",
|
|
164
|
+
async handler(args, opts, config) {
|
|
165
|
+
const client = getClient(config);
|
|
166
|
+
const result = await client.GET(
|
|
167
|
+
"/track-and-trace/documents/{documentId}/accesses",
|
|
168
|
+
{
|
|
169
|
+
params: {
|
|
170
|
+
path: { documentId: requiredArg(args, "documentId") },
|
|
171
|
+
query: q({
|
|
172
|
+
contractAddress: contractAddress(opts),
|
|
173
|
+
"page[after]": opts["pageAfter"]
|
|
174
|
+
? Number(opts["pageAfter"])
|
|
175
|
+
: undefined,
|
|
176
|
+
"page[size]": opts["pageSize"]
|
|
177
|
+
? Number(opts["pageSize"])
|
|
178
|
+
: undefined,
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
return unwrap(result);
|
|
184
|
+
},
|
|
185
|
+
id: "track-and-trace.documents.accesses",
|
|
186
|
+
options: [...PAGINATION_OPTIONS, CONTRACT_ADDRESS_OPTION],
|
|
187
|
+
segments: ["track-and-trace", "documents", "accesses"],
|
|
188
|
+
summary: "List accesses for a Track and Trace document",
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
{
|
|
192
|
+
args: [
|
|
193
|
+
{
|
|
194
|
+
description: "Subject DID to filter accesses by",
|
|
195
|
+
example: "did:ebsi:ztqWJAmfyuUEf9Jvh97p167",
|
|
196
|
+
name: "subject",
|
|
197
|
+
required: true,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
group: "Track & Trace",
|
|
201
|
+
async handler(args, opts, config) {
|
|
202
|
+
const client = getClient(config);
|
|
203
|
+
const subject = requiredArg(args, "subject");
|
|
204
|
+
const result = await client.GET("/track-and-trace/accesses", {
|
|
205
|
+
params: {
|
|
206
|
+
query: { ...q({ contractAddress: contractAddress(opts) }), subject },
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
return unwrap(result);
|
|
210
|
+
},
|
|
211
|
+
id: "track-and-trace.accesses.get",
|
|
212
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
213
|
+
segments: ["track-and-trace", "accesses", "get"],
|
|
214
|
+
summary: "Get access control entries for a subject DID",
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
{
|
|
218
|
+
args: [
|
|
219
|
+
{
|
|
220
|
+
description: "Creator DID to check",
|
|
221
|
+
example: "did:ebsi:zxaYaUtb8pvoAtYNWbKcveg",
|
|
222
|
+
name: "creator",
|
|
223
|
+
required: true,
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
group: "Track & Trace",
|
|
227
|
+
async handler(args, opts, config) {
|
|
228
|
+
const client = getClient(config);
|
|
229
|
+
const creator = requiredArg(args, "creator");
|
|
230
|
+
// HEAD responses never carry a body: openapi-fetch always returns
|
|
231
|
+
// `data: undefined` for them (see its source), so the shared `unwrap()`
|
|
232
|
+
// (which throws whenever `data` is `undefined`) can't be used here --
|
|
233
|
+
// check `response.status` directly instead.
|
|
234
|
+
const { response } = await client.HEAD("/track-and-trace/accesses", {
|
|
235
|
+
params: {
|
|
236
|
+
query: { ...q({ contractAddress: contractAddress(opts) }), creator },
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
if (response.status === 204) return { allowed: true, creator };
|
|
240
|
+
if (response.status === 404) return { allowed: false, creator };
|
|
241
|
+
throw new ApiError(response.status, undefined);
|
|
242
|
+
},
|
|
243
|
+
id: "track-and-trace.accesses.check",
|
|
244
|
+
options: [CONTRACT_ADDRESS_OPTION],
|
|
245
|
+
segments: ["track-and-trace", "accesses", "check"],
|
|
246
|
+
summary:
|
|
247
|
+
"Check whether a DID is allowlisted as a Track and Trace document creator",
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
{
|
|
251
|
+
args: [],
|
|
252
|
+
group: "Track & Trace",
|
|
253
|
+
async handler(_args, _opts, config) {
|
|
254
|
+
const client = getClient(config);
|
|
255
|
+
const result = await client.GET("/track-and-trace/abi");
|
|
256
|
+
return unwrap(result);
|
|
257
|
+
},
|
|
258
|
+
id: "track-and-trace.abi",
|
|
259
|
+
options: [],
|
|
260
|
+
segments: ["track-and-trace", "abi"],
|
|
261
|
+
summary: "Get the ABI of the Track and Trace smart contract",
|
|
262
|
+
},
|
|
263
|
+
];
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
import type { KeyMaterial } from "../crypto/wallet.ts";
|
|
4
|
+
import type { CommandDescriptor } from "./registry.ts";
|
|
5
|
+
|
|
6
|
+
import { getConfigFilePath } from "../config/config.ts";
|
|
7
|
+
import { deriveWallet, generatePrivateKey } from "../crypto/wallet.ts";
|
|
8
|
+
import { resolveSignAlg, resolveWallet } from "./shared/wallet-opts.ts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Persist { es256kPrivateKey, es256PrivateKey?, did } to the config file and
|
|
12
|
+
* emit a plaintext warning.
|
|
13
|
+
*/
|
|
14
|
+
function persistKeyToDisk(
|
|
15
|
+
es256kPrivateKey: string,
|
|
16
|
+
es256PrivateKey: string | undefined,
|
|
17
|
+
did: string,
|
|
18
|
+
): void {
|
|
19
|
+
const configFilePath = getConfigFilePath();
|
|
20
|
+
let persisted: Record<string, string> = {};
|
|
21
|
+
if (existsSync(configFilePath)) {
|
|
22
|
+
try {
|
|
23
|
+
persisted = JSON.parse(readFileSync(configFilePath, "utf8")) as Record<
|
|
24
|
+
string,
|
|
25
|
+
string
|
|
26
|
+
>;
|
|
27
|
+
} catch /* v8 ignore next */ {
|
|
28
|
+
// ignore parse errors, start fresh
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
persisted["es256kPrivateKey"] = es256kPrivateKey;
|
|
32
|
+
if (es256PrivateKey !== undefined) {
|
|
33
|
+
persisted["es256PrivateKey"] = es256PrivateKey;
|
|
34
|
+
}
|
|
35
|
+
persisted["did"] = did;
|
|
36
|
+
writeFileSync(
|
|
37
|
+
configFilePath,
|
|
38
|
+
JSON.stringify(persisted, undefined, 2) + "\n",
|
|
39
|
+
"utf8",
|
|
40
|
+
);
|
|
41
|
+
process.stderr.write(
|
|
42
|
+
"\n⚠️ WARNING: Private key(s) stored in plaintext at " +
|
|
43
|
+
configFilePath +
|
|
44
|
+
"\n Keep this file secret and restrict its permissions.\n\n",
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Summarises one curve's `KeyMaterial` for command output.
|
|
50
|
+
*/
|
|
51
|
+
function summariseKey(key: KeyMaterial): {
|
|
52
|
+
alg: string;
|
|
53
|
+
kid: string;
|
|
54
|
+
thumbprint: string;
|
|
55
|
+
} {
|
|
56
|
+
return { alg: key.alg, kid: key.kid, thumbprint: key.thumbprint };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const SIGN_ALG_OPTION = {
|
|
60
|
+
description:
|
|
61
|
+
'Which key signs VCs/VPs when both are configured: "ES256" or "ES256K". ' +
|
|
62
|
+
"Also read from EBSI_SIGN_ALG or `ebsi config set signAlg <alg>`.",
|
|
63
|
+
flags: "--sign-alg <alg>",
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const ES256_KEY_OPTION = {
|
|
67
|
+
description:
|
|
68
|
+
"P-256 private key (hex), optional. Also read from EBSI_ES256_PRIVATE_KEY " +
|
|
69
|
+
"or `ebsi config set es256PrivateKey <hex>`.",
|
|
70
|
+
flags: "--es256-key <hex>",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const walletCommands: CommandDescriptor[] = [
|
|
74
|
+
{
|
|
75
|
+
args: [],
|
|
76
|
+
group: "Wallet",
|
|
77
|
+
async handler(_args, opts, config) {
|
|
78
|
+
// Resolve keys: flag → env/persisted config → generate new (ES256K only)
|
|
79
|
+
const es256kPrivateKey =
|
|
80
|
+
opts["es256kKey"] ?? config.es256kPrivateKey ?? generatePrivateKey();
|
|
81
|
+
const es256PrivateKey = opts["es256Key"] ?? config.es256PrivateKey;
|
|
82
|
+
const signAlg = resolveSignAlg(opts, config);
|
|
83
|
+
const overrideDid = opts["did"] ?? config.did;
|
|
84
|
+
|
|
85
|
+
const details = await deriveWallet(
|
|
86
|
+
{
|
|
87
|
+
es256kPrivateKey,
|
|
88
|
+
...(es256PrivateKey !== undefined && { es256PrivateKey }),
|
|
89
|
+
...(signAlg !== undefined && { signAlg }),
|
|
90
|
+
},
|
|
91
|
+
overrideDid,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Boolean commander flag arrives as true (or undefined); opts is cast to string record
|
|
95
|
+
// so we check truthiness
|
|
96
|
+
const save = Boolean(opts["save"]);
|
|
97
|
+
if (save) {
|
|
98
|
+
persistKeyToDisk(es256kPrivateKey, es256PrivateKey, details.did);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
address: details.address,
|
|
103
|
+
did: details.did,
|
|
104
|
+
es256: details.es256 ? summariseKey(details.es256) : undefined,
|
|
105
|
+
es256k: summariseKey(details.es256k),
|
|
106
|
+
privateKeys: save
|
|
107
|
+
? "(saved to config)"
|
|
108
|
+
: "(not persisted — use --save to persist)",
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
id: "wallet.create",
|
|
112
|
+
options: [
|
|
113
|
+
{
|
|
114
|
+
description:
|
|
115
|
+
"Use this secp256k1 private key instead of generating a new one " +
|
|
116
|
+
"(0x-prefixed hex). Also read from EBSI_ES256K_PRIVATE_KEY or " +
|
|
117
|
+
"`ebsi config set es256kPrivateKey <hex>`.",
|
|
118
|
+
flags: "--es256k-key <hex>",
|
|
119
|
+
},
|
|
120
|
+
ES256_KEY_OPTION,
|
|
121
|
+
SIGN_ALG_OPTION,
|
|
122
|
+
{
|
|
123
|
+
description:
|
|
124
|
+
"Assign this EBSI DID (did:ebsi:...) instead of generating a new one. " +
|
|
125
|
+
"Also read from EBSI_DID or `ebsi config set did <did>`.",
|
|
126
|
+
flags: "--did <did>",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
description:
|
|
130
|
+
"Persist the private key(s) and DID to the config file. " +
|
|
131
|
+
"⚠ WARNING: stored as plaintext.",
|
|
132
|
+
flags: "--save",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
segments: ["wallet", "create"],
|
|
136
|
+
summary:
|
|
137
|
+
"Generate (or import) a secp256k1 key pair and derive the associated EBSI DID, " +
|
|
138
|
+
"Ethereum address, and JWK thumbprint. Pass --es256-key to also register a P-256 " +
|
|
139
|
+
"key for signing VCs/VPs. " +
|
|
140
|
+
"Use --save to persist the key(s) to the config file (stored as plaintext — handle with care).",
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
args: [],
|
|
145
|
+
group: "Wallet",
|
|
146
|
+
async handler(_args, opts, config) {
|
|
147
|
+
const details = await resolveWallet(opts, config);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
address: details.address,
|
|
151
|
+
did: details.did,
|
|
152
|
+
es256: details.es256 ? summariseKey(details.es256) : undefined,
|
|
153
|
+
es256k: summariseKey(details.es256k),
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
id: "wallet.info",
|
|
157
|
+
options: [
|
|
158
|
+
{
|
|
159
|
+
description:
|
|
160
|
+
"secp256k1 private key (0x-prefixed hex) to derive info from.",
|
|
161
|
+
flags: "--es256k-key <hex>",
|
|
162
|
+
},
|
|
163
|
+
ES256_KEY_OPTION,
|
|
164
|
+
SIGN_ALG_OPTION,
|
|
165
|
+
{
|
|
166
|
+
description: "Override DID (did:ebsi:...)",
|
|
167
|
+
flags: "--did <did>",
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
segments: ["wallet", "info"],
|
|
171
|
+
summary:
|
|
172
|
+
"Show the address, DID, kid, and JWK thumbprint derived from the configured key(s) " +
|
|
173
|
+
"(does not generate or persist anything).",
|
|
174
|
+
},
|
|
175
|
+
];
|