@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
package/dist/app.js
DELETED
|
@@ -1,659 +0,0 @@
|
|
|
1
|
-
import { EbsiWallet } from "@europeum-ebsi/wallet-lib";
|
|
2
|
-
import { ethers } from "ethers";
|
|
3
|
-
import Joi from "joi";
|
|
4
|
-
import { calculateJwkThumbprint } from "jose";
|
|
5
|
-
import lodashSet from "lodash.set";
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { URL } from "node:url";
|
|
9
|
-
import { buildParam } from "./buildParam/index.js";
|
|
10
|
-
import { authorisation, compute, conformance, hardwarewallet, ledger, tnl, view, waitToBeMined, } from "./commands/index.js";
|
|
11
|
-
import { getRootAuthorisation } from "./commands/tir.js";
|
|
12
|
-
import { loadConfig } from "./config.js";
|
|
13
|
-
import { Client } from "./utils/Client.js";
|
|
14
|
-
import * as utils from "./utils/index.js";
|
|
15
|
-
import { HardwareWallet, jsonrpcBody, paramSignedTransaction, parseLine, prefixWith0x, } from "./utils/index.js";
|
|
16
|
-
let config = loadConfig();
|
|
17
|
-
let client = new Client();
|
|
18
|
-
let transactionInfo;
|
|
19
|
-
let token;
|
|
20
|
-
let httpOpts = {
|
|
21
|
-
headers: {},
|
|
22
|
-
};
|
|
23
|
-
const rtVars = {}; // runtime variables
|
|
24
|
-
const algSchema = Joi.string()
|
|
25
|
-
.valid("ES256K", "ES256", "RS256", "EdDSA")
|
|
26
|
-
.required();
|
|
27
|
-
export async function execCommand(command, printCommand = false) {
|
|
28
|
-
if (printCommand)
|
|
29
|
-
console.log(`==> ${command}`);
|
|
30
|
-
const parts = parseLine(command);
|
|
31
|
-
let varName = "";
|
|
32
|
-
if (parts.length === 0)
|
|
33
|
-
return 0;
|
|
34
|
-
if (typeof parts[0] === "string" && parts[0].includes(":")) {
|
|
35
|
-
varName = parts[0].replace(":", "");
|
|
36
|
-
parts.shift();
|
|
37
|
-
}
|
|
38
|
-
const [part0, part1] = parts;
|
|
39
|
-
const parts2 = parts.slice(2);
|
|
40
|
-
const method = part0;
|
|
41
|
-
const word1 = part1;
|
|
42
|
-
Joi.assert(method, Joi.string());
|
|
43
|
-
// APIs linked to smart contracts
|
|
44
|
-
if (["did", "tcr", "timestamp", "tir", "tnt", "tpr", "tsr"].includes(method)) {
|
|
45
|
-
Joi.assert(word1, Joi.string());
|
|
46
|
-
const inputs = parts2.map((p) => readValue(p)).filter(Boolean);
|
|
47
|
-
const response = await smartContractApi(method, word1, ...inputs);
|
|
48
|
-
if (varName)
|
|
49
|
-
await setVar(varName, response);
|
|
50
|
-
return response;
|
|
51
|
-
}
|
|
52
|
-
const schemaStrings = Joi.array().items(Joi.string());
|
|
53
|
-
const context = {
|
|
54
|
-
client,
|
|
55
|
-
config,
|
|
56
|
-
httpOpts,
|
|
57
|
-
rtVars,
|
|
58
|
-
token,
|
|
59
|
-
transactionInfo,
|
|
60
|
-
};
|
|
61
|
-
// Other APIs and configurations
|
|
62
|
-
switch (method) {
|
|
63
|
-
case "authorisation": {
|
|
64
|
-
Joi.assert(word1, Joi.string());
|
|
65
|
-
const inputs = parts2.map((p) => readValue(p)).filter(Boolean);
|
|
66
|
-
const response = await authorisation(word1, inputs, context);
|
|
67
|
-
if (varName)
|
|
68
|
-
await setVar(varName, response);
|
|
69
|
-
return response;
|
|
70
|
-
}
|
|
71
|
-
case "compute": {
|
|
72
|
-
Joi.assert(word1, Joi.string());
|
|
73
|
-
const inputs = parts2.map((p) => readValue(p));
|
|
74
|
-
const response = await compute(word1, inputs, context);
|
|
75
|
-
if (varName)
|
|
76
|
-
await setVar(varName, response);
|
|
77
|
-
return response;
|
|
78
|
-
}
|
|
79
|
-
case "conformance": {
|
|
80
|
-
Joi.assert(word1, Joi.string());
|
|
81
|
-
const inputs = parts2
|
|
82
|
-
.map((p) => readValue(p))
|
|
83
|
-
.filter(Boolean);
|
|
84
|
-
const response = await conformance(word1, inputs, context);
|
|
85
|
-
if (varName)
|
|
86
|
-
await setVar(varName, response);
|
|
87
|
-
return response;
|
|
88
|
-
}
|
|
89
|
-
case "domain": {
|
|
90
|
-
Joi.assert(word1, Joi.string());
|
|
91
|
-
await setDomain(word1);
|
|
92
|
-
return 0;
|
|
93
|
-
}
|
|
94
|
-
case "env": {
|
|
95
|
-
Joi.assert(word1, Joi.string().optional());
|
|
96
|
-
const input = readValue(word1);
|
|
97
|
-
await environment(input);
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
|
-
case "exit": {
|
|
101
|
-
return process.exit(0);
|
|
102
|
-
}
|
|
103
|
-
case "export": {
|
|
104
|
-
let data = readValue(word1);
|
|
105
|
-
const filename = readValue(parts2[0]);
|
|
106
|
-
if (!filename)
|
|
107
|
-
throw new Error("Filename required");
|
|
108
|
-
if (typeof data === "object") {
|
|
109
|
-
data = JSON.stringify(data, null, 2);
|
|
110
|
-
}
|
|
111
|
-
const absolutePath = path.isAbsolute(filename)
|
|
112
|
-
? filename
|
|
113
|
-
: path.join(`${process.cwd()}`, filename);
|
|
114
|
-
fs.writeFileSync(filename, data);
|
|
115
|
-
utils.yellow(`file saved at ${absolutePath}`);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
case "fs": {
|
|
119
|
-
Joi.assert(word1, Joi.string());
|
|
120
|
-
const response = fileSystem(word1, ...parts2);
|
|
121
|
-
console.log(response);
|
|
122
|
-
if (varName)
|
|
123
|
-
await setVar(varName, response);
|
|
124
|
-
return response;
|
|
125
|
-
}
|
|
126
|
-
case "get": {
|
|
127
|
-
Joi.assert(word1, Joi.string());
|
|
128
|
-
const input = readValue(word1);
|
|
129
|
-
const response = await utils.httpCall.get(input, context.httpOpts);
|
|
130
|
-
if (varName)
|
|
131
|
-
await setVar(varName, response.data);
|
|
132
|
-
return response.data;
|
|
133
|
-
}
|
|
134
|
-
case "hardwarewallet":
|
|
135
|
-
case "hw": {
|
|
136
|
-
Joi.assert(word1, Joi.string());
|
|
137
|
-
const inputs = parts2
|
|
138
|
-
.map((p) => {
|
|
139
|
-
if (word1 === "setpin")
|
|
140
|
-
return p;
|
|
141
|
-
return readValue(p);
|
|
142
|
-
})
|
|
143
|
-
.filter(Boolean);
|
|
144
|
-
const response = await hardwarewallet(word1, inputs, context);
|
|
145
|
-
if (varName)
|
|
146
|
-
await setVar(varName, response);
|
|
147
|
-
return response;
|
|
148
|
-
}
|
|
149
|
-
case "ledger": {
|
|
150
|
-
Joi.assert(word1, Joi.string());
|
|
151
|
-
const inputs = parts2
|
|
152
|
-
.map((p) => readValue(p))
|
|
153
|
-
.filter(Boolean);
|
|
154
|
-
const response = await ledger(word1, inputs, false, context);
|
|
155
|
-
if (varName)
|
|
156
|
-
await setVar(varName, response);
|
|
157
|
-
return response;
|
|
158
|
-
}
|
|
159
|
-
case "load": {
|
|
160
|
-
const filename = readValue(word1);
|
|
161
|
-
if (!filename)
|
|
162
|
-
throw new Error("Filename required");
|
|
163
|
-
const data = readFile(filename);
|
|
164
|
-
let response;
|
|
165
|
-
try {
|
|
166
|
-
response = JSON.parse(data);
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
response = data;
|
|
170
|
-
}
|
|
171
|
-
if (varName)
|
|
172
|
-
await setVar(varName, response);
|
|
173
|
-
return response;
|
|
174
|
-
}
|
|
175
|
-
case "proxyledger": {
|
|
176
|
-
Joi.assert(word1, Joi.string());
|
|
177
|
-
const inputs = parts2
|
|
178
|
-
.map((p) => readValue(p))
|
|
179
|
-
.filter(Boolean);
|
|
180
|
-
const response = await ledger(word1, inputs, true, context);
|
|
181
|
-
if (varName)
|
|
182
|
-
await setVar(varName, response);
|
|
183
|
-
return response;
|
|
184
|
-
}
|
|
185
|
-
case "run": {
|
|
186
|
-
Joi.assert(word1, Joi.string());
|
|
187
|
-
const inputs = parts2.map((p) => readValue(p));
|
|
188
|
-
const response = await run(word1, inputs);
|
|
189
|
-
if (varName)
|
|
190
|
-
await setVar(varName, response);
|
|
191
|
-
return response;
|
|
192
|
-
}
|
|
193
|
-
case "set": {
|
|
194
|
-
Joi.assert(word1, Joi.string());
|
|
195
|
-
const inputs = parts2.map((p) => readValue(p));
|
|
196
|
-
let value = inputs[0];
|
|
197
|
-
if (inputs.length > 1) {
|
|
198
|
-
Joi.assert(inputs, schemaStrings);
|
|
199
|
-
value = inputs.join("");
|
|
200
|
-
}
|
|
201
|
-
await setVar(word1, value);
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
case "tnl": {
|
|
205
|
-
Joi.assert(word1, Joi.string());
|
|
206
|
-
const inputs = parts2.map((p) => readValue(p));
|
|
207
|
-
const response = await tnl(word1, inputs, context);
|
|
208
|
-
if (varName)
|
|
209
|
-
await setVar(varName, response);
|
|
210
|
-
return response;
|
|
211
|
-
}
|
|
212
|
-
case "using": {
|
|
213
|
-
Joi.assert(word1, Joi.string());
|
|
214
|
-
const user = await using(word1, ...parts2);
|
|
215
|
-
return user;
|
|
216
|
-
}
|
|
217
|
-
case "version": {
|
|
218
|
-
Joi.assert(word1, Joi.string().optional());
|
|
219
|
-
const input = readValue(word1);
|
|
220
|
-
await setVersionApis(input);
|
|
221
|
-
return 0;
|
|
222
|
-
}
|
|
223
|
-
case "view": {
|
|
224
|
-
Joi.assert(word1, Joi.string());
|
|
225
|
-
return view([readValue(word1)], context);
|
|
226
|
-
}
|
|
227
|
-
default: {
|
|
228
|
-
throw new Error(`Invalid method '${method}'`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
export async function initConfigVars() {
|
|
233
|
-
await setVar("domain", config.domain, false);
|
|
234
|
-
await setVar("versionApis", config.versionApis, false);
|
|
235
|
-
await setVar("timestampUrl", config.api.timestamp.url, false);
|
|
236
|
-
await setVar("didUrl", config.api.did.url, false);
|
|
237
|
-
await setVar("tirUrl", config.api.tir.url, false);
|
|
238
|
-
await setVar("tsrUrl", config.api.tsr.url, false);
|
|
239
|
-
await setVar("tprUrl", config.api.tpr.url, false);
|
|
240
|
-
await setVar("tntUrl", config.api.tnt.url, false);
|
|
241
|
-
await setVar("ledgerUrl", config.api.ledger.url, false);
|
|
242
|
-
await setVar("authorisationUrl", config.api.authorisation.url, false);
|
|
243
|
-
await setVar("gasPrice", config.gasPrice, false);
|
|
244
|
-
await setVar("gasLimit", config.gasLimit, false);
|
|
245
|
-
}
|
|
246
|
-
export async function main() {
|
|
247
|
-
await initConfigVars();
|
|
248
|
-
while (true) {
|
|
249
|
-
const command = await utils.askQuestion("==> ");
|
|
250
|
-
try {
|
|
251
|
-
await execCommand(command);
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
utils.red(error.stack);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async function environment(env) {
|
|
259
|
-
if (env) {
|
|
260
|
-
config = loadConfig(env, config.versionApis);
|
|
261
|
-
await initConfigVars();
|
|
262
|
-
utils.yellow(`Environment ${env} loaded`);
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
utils.yellow(`Current environment: ${config.env}`);
|
|
266
|
-
}
|
|
267
|
-
const { api, contractAddresses, domain, env: envConfig } = config;
|
|
268
|
-
utils.yellow({
|
|
269
|
-
contractAddresses,
|
|
270
|
-
domain,
|
|
271
|
-
env: envConfig,
|
|
272
|
-
urls: Object.keys(api).map((name) => api[name].url),
|
|
273
|
-
version: config.versionApis,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
function fileSystem(method, ...params) {
|
|
277
|
-
switch (method) {
|
|
278
|
-
case "readBinaryFile": {
|
|
279
|
-
const [filename] = params;
|
|
280
|
-
Joi.assert(filename, Joi.string());
|
|
281
|
-
return fs.readFileSync(filename);
|
|
282
|
-
}
|
|
283
|
-
case "writeBinaryFile": {
|
|
284
|
-
const filename = readValue(params[0]);
|
|
285
|
-
const data = readValue(params[1]);
|
|
286
|
-
Joi.assert(filename, Joi.string());
|
|
287
|
-
fs.writeFileSync(filename, data);
|
|
288
|
-
return 0;
|
|
289
|
-
}
|
|
290
|
-
default: {
|
|
291
|
-
throw new Error(`Invalid method '${method}'`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function readFile(filename) {
|
|
296
|
-
try {
|
|
297
|
-
// get the file from the working directory
|
|
298
|
-
return fs.readFileSync(filename, "utf8");
|
|
299
|
-
}
|
|
300
|
-
catch {
|
|
301
|
-
// otherwise get the file from the internal scripts of the CLI tool
|
|
302
|
-
try {
|
|
303
|
-
return fs.readFileSync(new URL(`scripts/${filename}`, import.meta.url), "utf8");
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
throw new Error(`Can't open script ${filename}`);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
function readValue(input, required = false) {
|
|
311
|
-
if (!input || typeof input !== "string")
|
|
312
|
-
return input;
|
|
313
|
-
const parts = input.split(".");
|
|
314
|
-
let fieldName = parts[0];
|
|
315
|
-
if (!fieldName || rtVars[fieldName] === undefined) {
|
|
316
|
-
if (required)
|
|
317
|
-
return undefined;
|
|
318
|
-
return input;
|
|
319
|
-
}
|
|
320
|
-
let i = 0;
|
|
321
|
-
let obj = rtVars;
|
|
322
|
-
while (i < parts.length - 1) {
|
|
323
|
-
obj = obj[fieldName];
|
|
324
|
-
i += 1;
|
|
325
|
-
fieldName = parts[i];
|
|
326
|
-
}
|
|
327
|
-
return obj[fieldName];
|
|
328
|
-
}
|
|
329
|
-
async function run(filename, inputs = []) {
|
|
330
|
-
const filedata = readFile(filename);
|
|
331
|
-
const lines = filedata.split(/\r?\n/);
|
|
332
|
-
let response;
|
|
333
|
-
for (const [i, line_] of lines.entries()) {
|
|
334
|
-
let line = line_.trim();
|
|
335
|
-
if (line.length > 0 && !line.startsWith("#")) {
|
|
336
|
-
for (const [j, input] of inputs.entries()) {
|
|
337
|
-
let param;
|
|
338
|
-
if (typeof input === "number") {
|
|
339
|
-
param = `${input}`;
|
|
340
|
-
}
|
|
341
|
-
else if (typeof input === "string") {
|
|
342
|
-
param = `"${input}"`;
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
param = JSON.stringify(input);
|
|
346
|
-
}
|
|
347
|
-
line = line.replaceAll(new RegExp(String.raw `\$${j + 1}`, "g"), param);
|
|
348
|
-
}
|
|
349
|
-
try {
|
|
350
|
-
response = await execCommand(line, true);
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
353
|
-
utils.red(error.stack);
|
|
354
|
-
throw new Error(`Error in line ${i + 1}: ${error.message}`, {
|
|
355
|
-
cause: error,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
console.log(line);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return response;
|
|
364
|
-
}
|
|
365
|
-
async function setDomain(dom) {
|
|
366
|
-
if (dom) {
|
|
367
|
-
for (const apiName of Object.keys(config.api)) {
|
|
368
|
-
config.api[apiName].url = config.api[apiName].url.replace(config.domain, dom);
|
|
369
|
-
}
|
|
370
|
-
config.domain = dom;
|
|
371
|
-
await setVar("domain", config.domain);
|
|
372
|
-
}
|
|
373
|
-
utils.yellow(`Current domain: ${config.domain}`);
|
|
374
|
-
}
|
|
375
|
-
async function setVar(key, value, printVar = true) {
|
|
376
|
-
lodashSet(rtVars, key, value);
|
|
377
|
-
if (key.startsWith("user.")) {
|
|
378
|
-
await execCommand("using user user");
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
if (!printVar)
|
|
382
|
-
return;
|
|
383
|
-
utils.cyanBold(`Value saved in '${key}':`);
|
|
384
|
-
utils.cyan(value);
|
|
385
|
-
}
|
|
386
|
-
async function setVersionApis(version) {
|
|
387
|
-
if (version) {
|
|
388
|
-
config = loadConfig(config.env, version);
|
|
389
|
-
await initConfigVars();
|
|
390
|
-
utils.yellow(`Version ${config.versionApis} loaded`);
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
utils.yellow(`Current version: ${config.versionApis}`);
|
|
394
|
-
}
|
|
395
|
-
const { api, contractAddresses, domain, env: envConfig } = config;
|
|
396
|
-
utils.yellow({
|
|
397
|
-
contractAddresses,
|
|
398
|
-
domain,
|
|
399
|
-
env: envConfig,
|
|
400
|
-
urls: Object.keys(api).map((name) => api[name].url),
|
|
401
|
-
version: config.versionApis,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
async function smartContractApi(contract, method, ...inputs) {
|
|
405
|
-
if (!(contract in config.api)) {
|
|
406
|
-
throw new Error(`Unknown contract ${contract}`);
|
|
407
|
-
}
|
|
408
|
-
const apiUrl = config.api[contract].url;
|
|
409
|
-
if (method === "get") {
|
|
410
|
-
const response = await utils.httpCall.get(`${apiUrl}${urlPath(inputs)}`, httpOpts);
|
|
411
|
-
return response.data;
|
|
412
|
-
}
|
|
413
|
-
if (method === "head") {
|
|
414
|
-
const response = await utils.httpCall.head(`${apiUrl}${urlPath(inputs)}`, httpOpts);
|
|
415
|
-
return response.data;
|
|
416
|
-
}
|
|
417
|
-
const url = `${apiUrl}/jsonrpc`;
|
|
418
|
-
if (contract === "tcr") {
|
|
419
|
-
throw new Error("TCR API does not have jsonrpc endpoint. Use `ledger tcr` instead.");
|
|
420
|
-
}
|
|
421
|
-
if (contract === "tir" && method === "getRootAuthorisation") {
|
|
422
|
-
return await getRootAuthorisation(inputs);
|
|
423
|
-
}
|
|
424
|
-
if (method === "sendSignedTransaction") {
|
|
425
|
-
const unsignedTransaction = readValue(inputs[0]);
|
|
426
|
-
const sgnTx = readValue(inputs[1]);
|
|
427
|
-
Joi.assert(unsignedTransaction, Joi.object());
|
|
428
|
-
Joi.assert(sgnTx, Joi.string());
|
|
429
|
-
const bodySend = jsonrpcBody(method, [
|
|
430
|
-
paramSignedTransaction(unsignedTransaction, sgnTx),
|
|
431
|
-
]);
|
|
432
|
-
const response = await utils.httpCall.post(url, bodySend, httpOpts);
|
|
433
|
-
// use ledger proxy is besu provider is defined
|
|
434
|
-
const context = {
|
|
435
|
-
client,
|
|
436
|
-
config,
|
|
437
|
-
httpOpts,
|
|
438
|
-
rtVars,
|
|
439
|
-
token,
|
|
440
|
-
transactionInfo,
|
|
441
|
-
};
|
|
442
|
-
transactionInfo.txId = response.data.result;
|
|
443
|
-
transactionInfo.receipt = await waitToBeMined(response.data.result, false, context);
|
|
444
|
-
return transactionInfo.receipt;
|
|
445
|
-
}
|
|
446
|
-
if (!method.startsWith("build-")) {
|
|
447
|
-
const inputsStr = inputs
|
|
448
|
-
.map((input) => {
|
|
449
|
-
let param;
|
|
450
|
-
if (typeof input === "number") {
|
|
451
|
-
param = `${input}`;
|
|
452
|
-
}
|
|
453
|
-
else if (typeof input === "string") {
|
|
454
|
-
param = `"${input}"`;
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
param = JSON.stringify(input);
|
|
458
|
-
}
|
|
459
|
-
return param;
|
|
460
|
-
})
|
|
461
|
-
.join(" ");
|
|
462
|
-
const uTx = await execCommand(`${contract} build-${method} ${inputsStr}`, true);
|
|
463
|
-
const sgnTx = await execCommand(`compute signTransaction ${JSON.stringify(uTx)}`, true);
|
|
464
|
-
await execCommand(`${contract} sendSignedTransaction ${JSON.stringify(uTx)} ${sgnTx}`, true);
|
|
465
|
-
const txInfo = await execCommand("view transactionInfo", true);
|
|
466
|
-
return txInfo;
|
|
467
|
-
}
|
|
468
|
-
let m = method.replace("build-", "");
|
|
469
|
-
const build = await buildParam(contract, m, client, inputs
|
|
470
|
-
.map((input) => readValue(input))
|
|
471
|
-
.filter(Boolean), config.versionApis);
|
|
472
|
-
if (build.method)
|
|
473
|
-
m = build.method.slice(0, Math.max(0, build.method.indexOf("(")));
|
|
474
|
-
const param = {
|
|
475
|
-
from: client.ethWallet.address,
|
|
476
|
-
...build.param,
|
|
477
|
-
};
|
|
478
|
-
const body = jsonrpcBody(m, [param]);
|
|
479
|
-
const response = await utils.httpCall.post(url, body, httpOpts);
|
|
480
|
-
utils.yellow(build.info.title);
|
|
481
|
-
utils.yellow(build.info.data);
|
|
482
|
-
transactionInfo = {
|
|
483
|
-
build,
|
|
484
|
-
contract,
|
|
485
|
-
method: m,
|
|
486
|
-
};
|
|
487
|
-
return response.data.result;
|
|
488
|
-
}
|
|
489
|
-
function updateHttpOpts() {
|
|
490
|
-
const conformanceId = readValue("conformanceId", true);
|
|
491
|
-
httpOpts = {
|
|
492
|
-
headers: {
|
|
493
|
-
...(token && {
|
|
494
|
-
authorization: `Bearer ${token}`,
|
|
495
|
-
}),
|
|
496
|
-
...(conformanceId && { conformance: conformanceId }),
|
|
497
|
-
},
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
function urlPath(inputs) {
|
|
501
|
-
return inputs.map((input) => readValue(input)).join("");
|
|
502
|
-
}
|
|
503
|
-
async function using(method, ...params) {
|
|
504
|
-
switch (method) {
|
|
505
|
-
case "ethuser": {
|
|
506
|
-
if (params[0] === "null") {
|
|
507
|
-
const hw = client.hardwareWallet;
|
|
508
|
-
client = new Client();
|
|
509
|
-
client.hardwareWallet = hw;
|
|
510
|
-
await setVar("user", client.toJSON(), false);
|
|
511
|
-
utils.yellow("User removed");
|
|
512
|
-
return client;
|
|
513
|
-
}
|
|
514
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
515
|
-
await execCommand(`using user ES256K ${params.join(" ")}`, true);
|
|
516
|
-
return client;
|
|
517
|
-
}
|
|
518
|
-
case "token": {
|
|
519
|
-
token = params[0] === "empty" ? null : readValue(params[0]);
|
|
520
|
-
updateHttpOpts();
|
|
521
|
-
utils.yellow(token);
|
|
522
|
-
return 0;
|
|
523
|
-
}
|
|
524
|
-
case "user": {
|
|
525
|
-
const existingUser = readValue(params[0]);
|
|
526
|
-
if (existingUser && typeof existingUser !== "string") {
|
|
527
|
-
// load the existing user
|
|
528
|
-
const hw = client.hardwareWallet;
|
|
529
|
-
client = new Client();
|
|
530
|
-
client.hardwareWallet = hw;
|
|
531
|
-
client.did = existingUser.did;
|
|
532
|
-
client.didVersion = existingUser.didVersion;
|
|
533
|
-
client.keys = existingUser.keys;
|
|
534
|
-
client.clientId = existingUser.clientId;
|
|
535
|
-
client.accreditationUrl = existingUser.accreditationUrl;
|
|
536
|
-
client.supportOfficeAccreditationUrl =
|
|
537
|
-
existingUser.supportOfficeAccreditationUrl;
|
|
538
|
-
if (existingUser.accreditationUrl) {
|
|
539
|
-
client.accreditationId = existingUser.accreditationUrl.slice(existingUser.accreditationUrl.lastIndexOf("/") + 1);
|
|
540
|
-
}
|
|
541
|
-
client.proxyId = existingUser.proxyId;
|
|
542
|
-
client.issuerState = existingUser.issuerState;
|
|
543
|
-
if (existingUser.keys?.ES256K?.privateKeyHex) {
|
|
544
|
-
client.ethWallet = new ethers.Wallet(existingUser.keys.ES256K.privateKeyHex);
|
|
545
|
-
}
|
|
546
|
-
await setVar("user", client.toJSON(), false);
|
|
547
|
-
await execCommand("view user", false);
|
|
548
|
-
return client;
|
|
549
|
-
}
|
|
550
|
-
if (params[0] === "null") {
|
|
551
|
-
const hw = client.hardwareWallet;
|
|
552
|
-
client = new Client();
|
|
553
|
-
client.hardwareWallet = hw;
|
|
554
|
-
await setVar("user", client.toJSON(), false);
|
|
555
|
-
utils.yellow("User removed");
|
|
556
|
-
return 0;
|
|
557
|
-
}
|
|
558
|
-
const alg = readValue(params[0]) ?? "ES256K";
|
|
559
|
-
const didMethod = readValue(params[1]) ?? "did1";
|
|
560
|
-
const privateKey = readValue(params[2]);
|
|
561
|
-
client.did = readValue(params[3]) ?? client.did;
|
|
562
|
-
let verificationMethodId = readValue(params[4]);
|
|
563
|
-
Joi.assert(alg, algSchema);
|
|
564
|
-
if (client.keys[alg] && !privateKey) {
|
|
565
|
-
throw new Error([
|
|
566
|
-
`Private key can not be generated randomly for alg '${alg}' `,
|
|
567
|
-
"because it is already defined. If you want to update it ",
|
|
568
|
-
"set a specific private key. If you want to create a new ",
|
|
569
|
-
"random user remove the existing one first with the command ",
|
|
570
|
-
"'using user null'.",
|
|
571
|
-
].join(""));
|
|
572
|
-
}
|
|
573
|
-
const usingHardwareWallet = privateKey === "hardwarewallet" || privateKey === "hw";
|
|
574
|
-
if (usingHardwareWallet && alg !== "ES256") {
|
|
575
|
-
throw new Error("Hardware wallet must use alg ES256. The CLI does not support other algs");
|
|
576
|
-
}
|
|
577
|
-
if (alg === "ES256K") {
|
|
578
|
-
if (!privateKey) {
|
|
579
|
-
client.ethWallet = ethers.Wallet.createRandom();
|
|
580
|
-
}
|
|
581
|
-
else if (typeof privateKey === "string") {
|
|
582
|
-
client.ethWallet = new ethers.Wallet(prefixWith0x(privateKey));
|
|
583
|
-
}
|
|
584
|
-
else {
|
|
585
|
-
client.ethWallet = new ethers.Wallet(utils.encodePrivateKey({
|
|
586
|
-
format: "hex",
|
|
587
|
-
key: privateKey,
|
|
588
|
-
}));
|
|
589
|
-
}
|
|
590
|
-
const privateKeyJwk = utils.encodePrivateKey({
|
|
591
|
-
alg,
|
|
592
|
-
format: "jwk",
|
|
593
|
-
key: client.ethWallet.privateKey,
|
|
594
|
-
});
|
|
595
|
-
client.setJwk(alg, privateKeyJwk);
|
|
596
|
-
}
|
|
597
|
-
else if (alg === "ES256" && usingHardwareWallet) {
|
|
598
|
-
client.hardwareWallet ??= new HardwareWallet(config.openSClib);
|
|
599
|
-
const publicKeyJwk = client.hardwareWallet.getPublicKey();
|
|
600
|
-
const publicKeyPem = utils.encodePublicKey({
|
|
601
|
-
alg,
|
|
602
|
-
format: "pem",
|
|
603
|
-
key: publicKeyJwk,
|
|
604
|
-
});
|
|
605
|
-
client.keys.ES256 = {
|
|
606
|
-
id: "",
|
|
607
|
-
isHardwareWallet: true,
|
|
608
|
-
kid: "",
|
|
609
|
-
privateKeyJwk: undefined,
|
|
610
|
-
publicKeyJwk,
|
|
611
|
-
publicKeyPem,
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
else if (alg === "ES256" && typeof privateKey === "string") {
|
|
615
|
-
const privateKeyJwk = utils.encodePrivateKey({
|
|
616
|
-
alg,
|
|
617
|
-
format: "jwk",
|
|
618
|
-
key: privateKey,
|
|
619
|
-
});
|
|
620
|
-
client.setJwk(alg, privateKeyJwk);
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
const privateKeyJwk = privateKey;
|
|
624
|
-
if (privateKeyJwk) {
|
|
625
|
-
client.setJwk(alg, privateKeyJwk);
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
await client.createRandom(alg);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
switch (didMethod) {
|
|
632
|
-
case "did1": {
|
|
633
|
-
client.didVersion = 1;
|
|
634
|
-
client.did ??= EbsiWallet.createDid();
|
|
635
|
-
verificationMethodId ??= await calculateJwkThumbprint(client.keys[alg].publicKeyJwk, "sha256");
|
|
636
|
-
break;
|
|
637
|
-
}
|
|
638
|
-
case "did2": {
|
|
639
|
-
client.didVersion = 2;
|
|
640
|
-
client.did = EbsiWallet.createDid("NATURAL_PERSON", client.keys[alg].publicKeyJwk);
|
|
641
|
-
verificationMethodId ??= client.did.slice(8);
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
default: {
|
|
645
|
-
throw new Error("did method must be 'did1' or 'did2'");
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
client.keys[alg].id = verificationMethodId;
|
|
649
|
-
client.keys[alg].kid = `${client.did}#${verificationMethodId}`;
|
|
650
|
-
await setVar("user", client.toJSON(), false);
|
|
651
|
-
await execCommand("view user", false);
|
|
652
|
-
return client;
|
|
653
|
-
}
|
|
654
|
-
default: {
|
|
655
|
-
throw new Error(`Invalid subject '${method}'`);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
//# sourceMappingURL=app.js.map
|