@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/commands/ledger.js
CHANGED
|
@@ -1,397 +1,574 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"ptr",
|
|
15
|
-
"tir",
|
|
16
|
-
"tsr",
|
|
17
|
-
"tpr",
|
|
18
|
-
"tnt",
|
|
19
|
-
];
|
|
20
|
-
const onlyApiMethods = [
|
|
21
|
-
{
|
|
22
|
-
contract: "did",
|
|
23
|
-
method: "addService",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
contract: "did",
|
|
27
|
-
method: "revokeService",
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
export async function ledger(method, inputs, useProxy, context) {
|
|
31
|
-
if (useProxy) {
|
|
32
|
-
try {
|
|
33
|
-
new URL(context.config.besuProvider);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
throw new Error(`Invalid URL for besu provider: ${context.config.besuProvider}`);
|
|
37
|
-
}
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { getClient, unwrap } from "../api/fetch.js";
|
|
3
|
+
import { validateScope } from "../auth/presentation.js";
|
|
4
|
+
import { getAccessToken } from "../auth/token.js";
|
|
5
|
+
import { readFromRegistry } from "../ledger/read.js";
|
|
6
|
+
import { defaultScopeFor, deriveScopeForRegistries, REGISTRIES, REGISTRY_NAMES, } from "../ledger/registries.js";
|
|
7
|
+
import { signWriteBatch, writeToRegistry } from "../ledger/write.js";
|
|
8
|
+
import { requiredArg } from "./shared/args.js";
|
|
9
|
+
import { resolveWallet, WALLET_KEY_OPTIONS } from "./shared/wallet-opts.js";
|
|
10
|
+
function normalizeBatchEntry(entry, index) {
|
|
11
|
+
const position = `Batch entry #${(index + 1).toString()}`;
|
|
12
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
13
|
+
throw new Error(`${position} must be a JSON object with a "method" field (e.g. {"method": "eth_blockNumber"}).`);
|
|
38
14
|
}
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
const { id, method, params } = entry;
|
|
16
|
+
if (typeof method !== "string" || method === "") {
|
|
17
|
+
throw new Error(`${position} is missing a "method" string.`);
|
|
41
18
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return ledgerGetBlock(inputs, useProxy, context);
|
|
48
|
-
}
|
|
49
|
-
case "getChainId": {
|
|
50
|
-
return ledgerGetChainId(inputs, useProxy, context);
|
|
51
|
-
}
|
|
52
|
-
case "getGasPrice": {
|
|
53
|
-
return ledgerGetGasPrice(useProxy, context);
|
|
54
|
-
}
|
|
55
|
-
case "getTransaction": {
|
|
56
|
-
return ledgerGetTransaction(inputs, useProxy, context);
|
|
57
|
-
}
|
|
58
|
-
case "getTransactionCount": {
|
|
59
|
-
return ledgerGetTransactionCount(inputs, useProxy, context);
|
|
60
|
-
}
|
|
61
|
-
case "getTransactionReceipt": {
|
|
62
|
-
return ledgerGetTransactionReceipt(inputs, useProxy, context);
|
|
63
|
-
}
|
|
64
|
-
case "send": {
|
|
65
|
-
return ledgerSendCustomContract(inputs, useProxy, context);
|
|
66
|
-
}
|
|
67
|
-
case "sendEth": {
|
|
68
|
-
return ledgerSendEth(inputs[0], inputs[1], useProxy, context);
|
|
69
|
-
}
|
|
70
|
-
case "sendTransaction": {
|
|
71
|
-
return ledgerSendTransaction(inputs, useProxy, context);
|
|
72
|
-
}
|
|
73
|
-
default: {
|
|
74
|
-
throw new Error(`Invalid method '${method}'`);
|
|
75
|
-
}
|
|
19
|
+
if (params !== undefined && !Array.isArray(params)) {
|
|
20
|
+
throw new Error(`${position}: "params" must be a JSON array when present.`);
|
|
21
|
+
}
|
|
22
|
+
if (id !== undefined && typeof id !== "number" && typeof id !== "string") {
|
|
23
|
+
throw new Error(`${position}: "id" must be a number or string when present.`);
|
|
76
24
|
}
|
|
25
|
+
return {
|
|
26
|
+
...(id !== undefined && { id: id }),
|
|
27
|
+
jsonrpc: "2.0",
|
|
28
|
+
method,
|
|
29
|
+
...(params !== undefined && { params: params }),
|
|
30
|
+
};
|
|
77
31
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
32
|
+
function parseGasBigInt(raw, flag) {
|
|
33
|
+
try {
|
|
34
|
+
return BigInt(raw);
|
|
81
35
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
throw new Error(`
|
|
36
|
+
catch (error) {
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
throw new Error(`Invalid ${flag} value "${raw}": ${message}`, {
|
|
39
|
+
cause: error,
|
|
40
|
+
});
|
|
85
41
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
switch (contractName) {
|
|
93
|
-
case "ptr": {
|
|
94
|
-
return readPtrContract(path, useProxy, context);
|
|
95
|
-
}
|
|
96
|
-
case "tcr": {
|
|
97
|
-
return readTcrContract(path, useProxy, context);
|
|
98
|
-
}
|
|
99
|
-
case "tsr": {
|
|
100
|
-
return readTsrContract(path, useProxy, context);
|
|
101
|
-
}
|
|
102
|
-
default: {
|
|
103
|
-
throw new Error(`contract ${contractName} not supported`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
42
|
+
}
|
|
43
|
+
function parseGasOverrides(opts) {
|
|
44
|
+
const gasLimitRaw = opts["gasLimit"];
|
|
45
|
+
const gasPriceRaw = opts["gasPrice"];
|
|
46
|
+
if (gasLimitRaw === undefined && gasPriceRaw === undefined) {
|
|
47
|
+
return undefined;
|
|
106
48
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
49
|
+
return {
|
|
50
|
+
...(gasLimitRaw !== undefined && {
|
|
51
|
+
gasLimit: parseGasBigInt(gasLimitRaw, "--gas-limit"),
|
|
52
|
+
}),
|
|
53
|
+
...(gasPriceRaw !== undefined && {
|
|
54
|
+
gasPrice: parseGasBigInt(gasPriceRaw, "--gas-price"),
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function parseJsonArray(raw, argName) {
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(raw);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const message = error instanceof Error ? error.message : "parse error";
|
|
65
|
+
throw new Error(`Invalid ${argName} JSON: ${message}`, { cause: error });
|
|
66
|
+
}
|
|
67
|
+
if (!Array.isArray(parsed)) {
|
|
68
|
+
throw new TypeError(`${argName} must be a JSON array`);
|
|
69
|
+
}
|
|
70
|
+
return parsed;
|
|
71
|
+
}
|
|
72
|
+
function parseWriteBatchFile(raw) {
|
|
73
|
+
let parsed;
|
|
74
|
+
try {
|
|
75
|
+
parsed = JSON.parse(raw);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : "parse error";
|
|
79
|
+
throw new Error(`Invalid JSON: ${message}`, { cause: error });
|
|
135
80
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
81
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
82
|
+
throw new Error("Batch file must contain a non-empty JSON array of write entries " +
|
|
83
|
+
'(each: {"registry", "function", "args", "to"?}).');
|
|
84
|
+
}
|
|
85
|
+
return parsed.map((entry, index) => {
|
|
86
|
+
const position = `Entry #${(index + 1).toString()}`;
|
|
87
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
88
|
+
throw new Error(`${position} must be a JSON object with "registry", "function", and "args".`);
|
|
89
|
+
}
|
|
90
|
+
const { args, function: fn, registry, to, } = entry;
|
|
91
|
+
if (typeof registry !== "string" || registry === "") {
|
|
92
|
+
throw new Error(`${position} is missing a "registry" string.`);
|
|
143
93
|
}
|
|
144
|
-
|
|
145
|
-
|
|
94
|
+
if (typeof fn !== "string" || fn === "") {
|
|
95
|
+
throw new Error(`${position} is missing a "function" string.`);
|
|
146
96
|
}
|
|
147
|
-
|
|
148
|
-
|
|
97
|
+
if (!Array.isArray(args)) {
|
|
98
|
+
throw new TypeError(`${position}: "args" must be a JSON array.`);
|
|
149
99
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const sgnTx = (await compute("signTransaction", [uTx], context));
|
|
156
|
-
console.log(`==> ${cmd} sendTransaction ${sgnTx}`);
|
|
157
|
-
const receipt = await ledgerSendTransaction([sgnTx], useProxy, context);
|
|
158
|
-
await view(["transactionInfo"], context);
|
|
159
|
-
return receipt;
|
|
100
|
+
if (to !== undefined && typeof to !== "string") {
|
|
101
|
+
throw new Error(`${position}: "to" must be a string when present.`);
|
|
102
|
+
}
|
|
103
|
+
return { args, function: fn, registry, ...(to !== undefined && { to }) };
|
|
104
|
+
});
|
|
160
105
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
106
|
+
async function readStdin() {
|
|
107
|
+
const chunks = [];
|
|
108
|
+
for await (const chunk of process.stdin) {
|
|
109
|
+
chunks.push(chunk);
|
|
165
110
|
}
|
|
166
|
-
|
|
167
|
-
const urlPath = inputs.join("");
|
|
168
|
-
const url = urlPath.startsWith("http") ? urlPath : `${apiUrl}${urlPath}`;
|
|
169
|
-
const response = await httpCall.get(url, context.httpOpts);
|
|
170
|
-
return response.data;
|
|
171
|
-
}
|
|
172
|
-
export async function ledgerGetBlock(inputs, useProxy, context) {
|
|
173
|
-
const apiUrl = useProxy
|
|
174
|
-
? context.config.besuProvider
|
|
175
|
-
: `${context.config.api.ledger.url}/blockchains/besu`;
|
|
176
|
-
const body = jsonrpcBody("eth_getBlockByNumber", [inputs[0], true]);
|
|
177
|
-
const response = await httpCall.post(apiUrl, body, context.httpOpts);
|
|
178
|
-
return response.data.result;
|
|
111
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
179
112
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
: `${context.config.api.ledger.url}/blockchains/besu`);
|
|
193
|
-
const contract = new ethers.Contract(address, abi, provider);
|
|
194
|
-
const result = (await contract[method](...args));
|
|
195
|
-
const fragment = contract.interface.getFunction(method);
|
|
196
|
-
if (!fragment) {
|
|
197
|
-
throw new Error(`Can't get function fragment for ${method}`);
|
|
113
|
+
async function resolveWriteToken(opts, config, wallet, defaultScope) {
|
|
114
|
+
if (opts["autoToken"]) {
|
|
115
|
+
const scope = opts["scope"] ?? defaultScope;
|
|
116
|
+
validateScope(scope);
|
|
117
|
+
const vcFile = opts["vc"];
|
|
118
|
+
const vcJwt = vcFile ? readFileSync(vcFile, "utf8").trim() : undefined;
|
|
119
|
+
return getAccessToken({
|
|
120
|
+
config,
|
|
121
|
+
scope,
|
|
122
|
+
wallet,
|
|
123
|
+
...(vcJwt !== undefined && { vcJwt }),
|
|
124
|
+
});
|
|
198
125
|
}
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
: getProperties(result, outputs);
|
|
205
|
-
const dataDecoded = {
|
|
206
|
-
name: fragment.name,
|
|
207
|
-
outputs: outputsDecoded,
|
|
208
|
-
};
|
|
209
|
-
green({ dataDecoded, result });
|
|
210
|
-
return { dataDecoded, result };
|
|
211
|
-
}
|
|
212
|
-
export async function ledgerGetGasPrice(useProxy, context) {
|
|
213
|
-
const apiUrl = useProxy
|
|
214
|
-
? context.config.besuProvider
|
|
215
|
-
: `${context.config.api.ledger.url}/blockchains/besu`;
|
|
216
|
-
const body = jsonrpcBody("eth_gasPrice", []);
|
|
217
|
-
const response = await httpCall.post(apiUrl, body, context.httpOpts);
|
|
218
|
-
return response.data.result;
|
|
219
|
-
}
|
|
220
|
-
export async function ledgerGetTransaction(inputs, useProxy, context) {
|
|
221
|
-
const apiUrl = useProxy
|
|
222
|
-
? context.config.besuProvider
|
|
223
|
-
: `${context.config.api.ledger.url}/blockchains/besu`;
|
|
224
|
-
const body = jsonrpcBody("eth_getTransactionByHash", [inputs[0]]);
|
|
225
|
-
const response = await httpCall.post(apiUrl, body, context.httpOpts);
|
|
226
|
-
return response.data.result;
|
|
227
|
-
}
|
|
228
|
-
export async function ledgerGetTransactionCount(inputs, useProxy, context) {
|
|
229
|
-
const apiUrl = useProxy
|
|
230
|
-
? context.config.besuProvider
|
|
231
|
-
: `${context.config.api.ledger.url}/blockchains/besu`;
|
|
232
|
-
const body = jsonrpcBody("eth_getTransactionCount", [inputs[0], "latest"]);
|
|
233
|
-
const response = await httpCall.post(apiUrl, body, context.httpOpts);
|
|
234
|
-
return response.data.result;
|
|
235
|
-
}
|
|
236
|
-
export async function ledgerGetTransactionReceipt(inputs, useProxy, context) {
|
|
237
|
-
const apiUrl = useProxy
|
|
238
|
-
? context.config.besuProvider
|
|
239
|
-
: `${context.config.api.ledger.url}/blockchains/besu`;
|
|
240
|
-
const body = jsonrpcBody("eth_getTransactionReceipt", [inputs[0]]);
|
|
241
|
-
const response = await httpCall.post(apiUrl, body, context.httpOpts);
|
|
242
|
-
const receipt = response.data.result;
|
|
243
|
-
if (receipt && Number(receipt.status) !== 1) {
|
|
244
|
-
const message = `Transaction failed: Status ${receipt.status}. Revert reason: ${parseRevertReason(receipt, context)}`;
|
|
245
|
-
red(message);
|
|
246
|
-
throw new Error(message);
|
|
126
|
+
const resolvedToken = opts["token"] ?? config.token;
|
|
127
|
+
if (!resolvedToken) {
|
|
128
|
+
throw new Error("No access token found. " +
|
|
129
|
+
"Use --auto-token to mint one via the VP flow, " +
|
|
130
|
+
"or provide --token <jwt> / EBSI_ACCESS_TOKEN / `ebsi config set token <jwt>`.");
|
|
247
131
|
}
|
|
248
|
-
return
|
|
132
|
+
return resolvedToken;
|
|
249
133
|
}
|
|
250
|
-
export
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
to: address,
|
|
265
|
-
value: "0x0",
|
|
266
|
-
};
|
|
267
|
-
context.transactionInfo = {
|
|
268
|
-
build: {
|
|
269
|
-
info: {
|
|
270
|
-
data: params,
|
|
271
|
-
title: `call ${method} on ${address}`,
|
|
134
|
+
export const ledgerCommands = [
|
|
135
|
+
{
|
|
136
|
+
args: [
|
|
137
|
+
{
|
|
138
|
+
description: "JSON-RPC method to invoke (e.g. eth_getBlockByNumber, eth_sendRawTransaction)",
|
|
139
|
+
example: "eth_getBlockByNumber",
|
|
140
|
+
name: "method",
|
|
141
|
+
required: true,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
description: "JSON array of parameters encoded as a string (e.g. '[\"latest\", false]'). Omit or pass '[]' for methods with no params.",
|
|
145
|
+
example: '["latest", false]',
|
|
146
|
+
name: "params",
|
|
147
|
+
required: false,
|
|
272
148
|
},
|
|
273
|
-
|
|
274
|
-
|
|
149
|
+
],
|
|
150
|
+
group: "Ledger",
|
|
151
|
+
async handler(args, opts, config) {
|
|
152
|
+
const method = requiredArg(args, "method");
|
|
153
|
+
const rawParams = args["params"];
|
|
154
|
+
let params = [];
|
|
155
|
+
if (rawParams !== undefined && rawParams !== "") {
|
|
156
|
+
try {
|
|
157
|
+
const parsed = JSON.parse(rawParams);
|
|
158
|
+
if (!Array.isArray(parsed)) {
|
|
159
|
+
throw new TypeError("params must be a JSON array");
|
|
160
|
+
}
|
|
161
|
+
params = parsed;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const message = error instanceof Error ? error.message : "parse error";
|
|
165
|
+
throw new Error(`Invalid params JSON: ${message}`, { cause: error });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const id = Number(opts["id"] ?? 1);
|
|
169
|
+
const client = getClient(config);
|
|
170
|
+
const result = await client.POST("/ledger", {
|
|
171
|
+
body: { id, jsonrpc: "2.0", method, params },
|
|
172
|
+
});
|
|
173
|
+
return unwrap(result);
|
|
275
174
|
},
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
context.transactionInfo = {
|
|
299
|
-
build: {
|
|
300
|
-
info: {
|
|
301
|
-
data: { amount, to },
|
|
302
|
-
title: `send ETH: ${amount} to ${to}`,
|
|
175
|
+
id: "ledger.call",
|
|
176
|
+
options: [
|
|
177
|
+
{
|
|
178
|
+
defaultValue: "1",
|
|
179
|
+
description: "JSON-RPC request id (default: 1)",
|
|
180
|
+
flags: "--id <n>",
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
segments: ["ledger", "call"],
|
|
184
|
+
summary: "Send a JSON-RPC request to the Besu node via POST /ledger. " +
|
|
185
|
+
"Read methods (eth_getBlock*, eth_getTransaction*, ...) are forwarded anonymously. " +
|
|
186
|
+
"Write methods (eth_sendRawTransaction) require a Bearer token via --token, " +
|
|
187
|
+
"EBSI_ACCESS_TOKEN env var, or `ebsi config set token <jwt>`. " +
|
|
188
|
+
"The caller is responsible for building and signing the raw transaction.",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
args: [
|
|
192
|
+
{
|
|
193
|
+
description: "Block number (hex, e.g. 0x1e240) or tag (latest, earliest, pending)",
|
|
194
|
+
example: "latest",
|
|
195
|
+
name: "blockNumberOrTag",
|
|
196
|
+
required: true,
|
|
303
197
|
},
|
|
304
|
-
|
|
305
|
-
|
|
198
|
+
],
|
|
199
|
+
group: "Ledger",
|
|
200
|
+
async handler(args, _opts, config) {
|
|
201
|
+
const tag = requiredArg(args, "blockNumberOrTag", "latest");
|
|
202
|
+
const client = getClient(config);
|
|
203
|
+
const result = await client.POST("/ledger", {
|
|
204
|
+
body: {
|
|
205
|
+
id: 1,
|
|
206
|
+
jsonrpc: "2.0",
|
|
207
|
+
method: "eth_getBlockByNumber",
|
|
208
|
+
params: [tag, false],
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
return unwrap(result);
|
|
306
212
|
},
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
213
|
+
id: "ledger.block",
|
|
214
|
+
options: [],
|
|
215
|
+
segments: ["ledger", "block"],
|
|
216
|
+
summary: "Get a block by number or tag (eth_getBlockByNumber). Shorthand for `ledger call eth_getBlockByNumber`.",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
args: [
|
|
220
|
+
{
|
|
221
|
+
description: "Transaction hash (0x-prefixed hex)",
|
|
222
|
+
example: "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b",
|
|
223
|
+
name: "hash",
|
|
224
|
+
required: true,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
group: "Ledger",
|
|
228
|
+
async handler(args, _opts, config) {
|
|
229
|
+
const hash = requiredArg(args, "hash");
|
|
230
|
+
const client = getClient(config);
|
|
231
|
+
const result = await client.POST("/ledger", {
|
|
232
|
+
body: {
|
|
233
|
+
id: 1,
|
|
234
|
+
jsonrpc: "2.0",
|
|
235
|
+
method: "eth_getTransactionByHash",
|
|
236
|
+
params: [hash],
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
return unwrap(result);
|
|
240
|
+
},
|
|
241
|
+
id: "ledger.tx",
|
|
242
|
+
options: [],
|
|
243
|
+
segments: ["ledger", "tx"],
|
|
244
|
+
summary: "Get a transaction by hash (eth_getTransactionByHash). Shorthand for `ledger call eth_getTransactionByHash`.",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
args: [
|
|
248
|
+
{
|
|
249
|
+
description: "Registry name: " + REGISTRY_NAMES.join(", "),
|
|
250
|
+
example: "did-registry",
|
|
251
|
+
name: "registry",
|
|
252
|
+
required: true,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
description: "Smart-contract function to call (e.g. insertDidDocument, addIssuer)",
|
|
256
|
+
example: "insertDidDocument",
|
|
257
|
+
name: "function",
|
|
258
|
+
required: true,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
description: 'Function arguments as a JSON array string (e.g. \'["did:ebsi:z123", "..."]\'). ' +
|
|
262
|
+
"Types must match the contract ABI exactly.",
|
|
263
|
+
example: '["did:ebsi:z123", "{}", "thumbprint", "0xpubkey", true, 0, 9999999999]',
|
|
264
|
+
name: "args",
|
|
265
|
+
required: true,
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
group: "Ledger",
|
|
269
|
+
async handler(args, opts, config) {
|
|
270
|
+
const registryName = requiredArg(args, "registry");
|
|
271
|
+
const functionName = requiredArg(args, "function");
|
|
272
|
+
const argsRaw = requiredArg(args, "args");
|
|
273
|
+
const registry = REGISTRIES[registryName];
|
|
274
|
+
if (!registry) {
|
|
275
|
+
throw new Error(`Unknown registry "${registryName}". Known registries: ${REGISTRY_NAMES.join(", ")}`);
|
|
276
|
+
}
|
|
277
|
+
const functionArgs = parseJsonArray(argsRaw, "args");
|
|
278
|
+
const toOpt = opts["to"];
|
|
279
|
+
const contractAddress = toOpt ?? process.env[registry.addressEnvKey];
|
|
280
|
+
if (!contractAddress) {
|
|
281
|
+
throw new Error(`No contract address for "${registryName}". ` +
|
|
282
|
+
`Provide --to <address> or set ${registry.addressEnvKey}.`);
|
|
283
|
+
}
|
|
284
|
+
const wallet = await resolveWallet(opts, config);
|
|
285
|
+
const token = await resolveWriteToken(opts, config, wallet, `${defaultScopeFor(registryName, functionName, registry)}:${contractAddress}`);
|
|
286
|
+
const gas = parseGasOverrides(opts);
|
|
287
|
+
const receipt = await writeToRegistry({
|
|
288
|
+
config,
|
|
289
|
+
contractAddress,
|
|
290
|
+
functionArgs,
|
|
291
|
+
functionName,
|
|
292
|
+
...(gas !== undefined && { gas }),
|
|
293
|
+
registry,
|
|
294
|
+
token,
|
|
295
|
+
wallet,
|
|
296
|
+
});
|
|
297
|
+
return receipt;
|
|
298
|
+
},
|
|
299
|
+
id: "ledger.write",
|
|
300
|
+
options: [
|
|
301
|
+
{
|
|
302
|
+
description: "Contract address (0x-prefixed). If omitted, read from the corresponding env var " +
|
|
303
|
+
"(e.g. DID_REGISTRY_CONTRACT_ADDRESS for did-registry).",
|
|
304
|
+
flags: "--to <address>",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
description: "Obtain a fresh access token automatically using the VP flow " +
|
|
308
|
+
"before submitting the transaction. Uses the registry/function's default scope " +
|
|
309
|
+
'(e.g. "did-registry:invite" for did-registry insertDidDocument, "track-and-trace:authorise" for ' +
|
|
310
|
+
'track-and-trace authoriseDid, "track-and-trace:create" for track-and-trace createDocument/' +
|
|
311
|
+
"commitCreateDocument, and each registry's plain write scope for every other " +
|
|
312
|
+
"function), targeted at the resolved --to contract instance, unless --scope " +
|
|
313
|
+
"overrides it.",
|
|
314
|
+
flags: "--auto-token",
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
description: "EBSI scope to use when requesting a token with --auto-token " +
|
|
318
|
+
'(e.g. "did-registry:write", "issuers-registry:invite", or "track-and-trace:write:0x61c3..." to target a specific ' +
|
|
319
|
+
"instance). Defaults to the registry/function's default scope targeted at --to.",
|
|
320
|
+
flags: "--scope <scope>",
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
description: "Path to a VC JWT file. Required for VC-required scopes " +
|
|
324
|
+
"(did-registry:invite, ledger:invoke, issuers-registry:invite, track-and-trace:authorise) when using --auto-token.",
|
|
325
|
+
flags: "--vc <file>",
|
|
326
|
+
},
|
|
327
|
+
...WALLET_KEY_OPTIONS,
|
|
328
|
+
{
|
|
329
|
+
description: "EBSI DID to use. Overrides config/env.",
|
|
330
|
+
flags: "--did <did>",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
description: "Advanced: manual gas limit (decimal or 0x-prefixed hex), overriding the " +
|
|
334
|
+
"eth_estimateGas result. By default the gas limit is estimated dynamically from the node.",
|
|
335
|
+
flags: "--gas-limit <value>",
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
description: "Advanced: manual gas price (decimal or 0x-prefixed hex), forcing a legacy " +
|
|
339
|
+
"transaction. By default fees are derived dynamically from the node (EIP-1559 when supported).",
|
|
340
|
+
flags: "--gas-price <value>",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
segments: ["ledger", "write"],
|
|
344
|
+
summary: "ABI-encode a registry function call, sign an Ethereum transaction, and submit it " +
|
|
345
|
+
"via POST /ledger. " +
|
|
346
|
+
"Requires a private key and an access token (or --auto-token to mint one inline). " +
|
|
347
|
+
"Contract address comes from --to or the corresponding env var " +
|
|
348
|
+
"(e.g. DID_REGISTRY_CONTRACT_ADDRESS). " +
|
|
349
|
+
"Known registries: " +
|
|
350
|
+
REGISTRY_NAMES.join(", ") +
|
|
351
|
+
".",
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
args: [
|
|
355
|
+
{
|
|
356
|
+
description: "Registry name: " + REGISTRY_NAMES.join(", "),
|
|
357
|
+
example: "timestamp",
|
|
358
|
+
name: "registry",
|
|
359
|
+
required: true,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
description: "Smart-contract view/pure function to call (e.g. getTimestamp, computeTimestampCommitment)",
|
|
363
|
+
example: "computeTimestampCommitment",
|
|
364
|
+
name: "function",
|
|
365
|
+
required: true,
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
description: "Function arguments as a JSON array string (e.g. '[\"0x1234\"]'). " +
|
|
369
|
+
"Types must match the contract ABI exactly.",
|
|
370
|
+
example: '["0xCommitter", [1], ["0xhash"], [], "0xsalt"]',
|
|
371
|
+
name: "args",
|
|
372
|
+
required: true,
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
group: "Ledger",
|
|
376
|
+
async handler(args, opts, config) {
|
|
377
|
+
const registryName = requiredArg(args, "registry");
|
|
378
|
+
const functionName = requiredArg(args, "function");
|
|
379
|
+
const functionArgs = parseJsonArray(requiredArg(args, "args"), "args");
|
|
380
|
+
const registry = REGISTRIES[registryName];
|
|
381
|
+
if (!registry) {
|
|
382
|
+
throw new Error(`Unknown registry "${registryName}". Known registries: ${REGISTRY_NAMES.join(", ")}`);
|
|
383
|
+
}
|
|
384
|
+
const toOpt = opts["to"];
|
|
385
|
+
const contractAddress = toOpt ?? process.env[registry.addressEnvKey];
|
|
386
|
+
if (!contractAddress) {
|
|
387
|
+
throw new Error(`No contract address for "${registryName}". ` +
|
|
388
|
+
`Provide --to <address> or set ${registry.addressEnvKey}.`);
|
|
389
|
+
}
|
|
390
|
+
return readFromRegistry({
|
|
391
|
+
config,
|
|
392
|
+
contractAddress,
|
|
393
|
+
functionArgs,
|
|
394
|
+
functionName,
|
|
395
|
+
registry,
|
|
396
|
+
});
|
|
397
|
+
},
|
|
398
|
+
id: "ledger.read",
|
|
399
|
+
options: [
|
|
400
|
+
{
|
|
401
|
+
description: "Contract address (0x-prefixed). If omitted, read from the corresponding env var " +
|
|
402
|
+
"(e.g. TIMESTAMP_CONTRACT_ADDRESS for timestamp).",
|
|
403
|
+
flags: "--to <address>",
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
segments: ["ledger", "read"],
|
|
407
|
+
summary: "ABI-encode a registry view/pure function call and resolve it via eth_call — " +
|
|
408
|
+
"the read-only counterpart to `ledger write`. No wallet or token needed, since " +
|
|
409
|
+
"eth_call is served anonymously. Returns the function's outputs as an array, " +
|
|
410
|
+
"in declaration order. Contract address comes from --to or the corresponding " +
|
|
411
|
+
"env var. Known registries: " +
|
|
412
|
+
REGISTRY_NAMES.join(", ") +
|
|
413
|
+
".",
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
args: [
|
|
417
|
+
{
|
|
418
|
+
description: "Path to a JSON file containing a JSON array of JSON-RPC requests, or '-' to read from stdin. " +
|
|
419
|
+
'Each entry needs a "method" field; "params" defaults to [] and "id" may be omitted to send ' +
|
|
420
|
+
"a notification (no response entry for that request).",
|
|
421
|
+
example: "./batch.json",
|
|
422
|
+
name: "source",
|
|
423
|
+
required: true,
|
|
424
|
+
},
|
|
425
|
+
],
|
|
426
|
+
group: "Ledger",
|
|
427
|
+
async handler(args, _opts, config) {
|
|
428
|
+
const source = requiredArg(args, "source");
|
|
429
|
+
const raw = source === "-" ? await readStdin() : readFileSync(source, "utf8");
|
|
430
|
+
let parsed;
|
|
359
431
|
try {
|
|
360
|
-
|
|
361
|
-
if (selector === errorSelector) {
|
|
362
|
-
errorName = fragment.name;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
432
|
+
parsed = JSON.parse(raw);
|
|
365
433
|
}
|
|
366
|
-
catch {
|
|
367
|
-
|
|
434
|
+
catch (error) {
|
|
435
|
+
const message = error instanceof Error ? error.message : "parse error";
|
|
436
|
+
throw new Error(`Invalid JSON in "${source}": ${message}`, {
|
|
437
|
+
cause: error,
|
|
438
|
+
});
|
|
368
439
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
440
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
441
|
+
throw new Error("Batch source must contain a non-empty JSON array of JSON-RPC requests.");
|
|
442
|
+
}
|
|
443
|
+
const batch = parsed.map((entry, index) => normalizeBatchEntry(entry, index));
|
|
444
|
+
const client = getClient(config);
|
|
445
|
+
const result = await client.POST("/ledger", {
|
|
446
|
+
body: batch,
|
|
447
|
+
});
|
|
448
|
+
return unwrap(result);
|
|
449
|
+
},
|
|
450
|
+
id: "ledger.batch",
|
|
451
|
+
options: [],
|
|
452
|
+
segments: ["ledger", "batch"],
|
|
453
|
+
summary: "Send a JSON-RPC batch request to the Besu node via POST /ledger — an array of independent " +
|
|
454
|
+
"requests processed in order under a single Authorization header (--token, EBSI_ACCESS_TOKEN, " +
|
|
455
|
+
"or `ebsi config set token`). Besu accepts at most 1024 requests per batch. Useful for grouping " +
|
|
456
|
+
"reads, or submitting several pre-signed raw transactions (eth_sendRawTransaction) together. " +
|
|
457
|
+
"For signing and submitting several registry writes in one batch, use `ledger write-batch`.",
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
args: [
|
|
461
|
+
{
|
|
462
|
+
description: 'Path to a JSON file containing a JSON array of write entries: {"registry", "function", ' +
|
|
463
|
+
'"args", "to"?} — same shape as the `ledger write` positional args. "to" falls back to the ' +
|
|
464
|
+
"registry's env var, per entry, if omitted.",
|
|
465
|
+
example: "./writes.json",
|
|
466
|
+
name: "file",
|
|
467
|
+
required: true,
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
group: "Ledger",
|
|
471
|
+
async handler(args, opts, config) {
|
|
472
|
+
const file = requiredArg(args, "file");
|
|
473
|
+
const fileEntries = parseWriteBatchFile(readFileSync(file, "utf8"));
|
|
474
|
+
const resolvedEntries = fileEntries.map((entry, index) => {
|
|
475
|
+
const position = `Entry #${(index + 1).toString()}`;
|
|
476
|
+
const registry = REGISTRIES[entry.registry];
|
|
477
|
+
if (!registry) {
|
|
478
|
+
throw new Error(`${position}: unknown registry "${entry.registry}". Known registries: ${REGISTRY_NAMES.join(", ")}`);
|
|
479
|
+
}
|
|
480
|
+
const to = entry.to ?? process.env[registry.addressEnvKey];
|
|
481
|
+
if (!to) {
|
|
482
|
+
throw new Error(`${position}: no contract address for "${entry.registry}". ` +
|
|
483
|
+
`Set "to" in the batch file or the ${registry.addressEnvKey} env var.`);
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
functionArgs: entry.args,
|
|
487
|
+
functionName: entry.function,
|
|
488
|
+
registry,
|
|
489
|
+
registryName: entry.registry,
|
|
490
|
+
to,
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
const wallet = await resolveWallet(opts, config);
|
|
494
|
+
const defaultScope = deriveScopeForRegistries(resolvedEntries.map(({ functionName, registryName, to }) => ({
|
|
495
|
+
functionName,
|
|
496
|
+
registryName,
|
|
497
|
+
to,
|
|
498
|
+
})));
|
|
499
|
+
const token = await resolveWriteToken(opts, config, wallet, defaultScope);
|
|
500
|
+
const gas = parseGasOverrides(opts);
|
|
501
|
+
const rawTxs = await signWriteBatch({
|
|
502
|
+
config,
|
|
503
|
+
entries: resolvedEntries.map(({ functionArgs, functionName, registry, to }) => ({
|
|
504
|
+
functionArgs,
|
|
505
|
+
functionName,
|
|
506
|
+
registry,
|
|
507
|
+
to,
|
|
508
|
+
})),
|
|
509
|
+
...(gas !== undefined && { gas }),
|
|
510
|
+
token,
|
|
511
|
+
wallet,
|
|
512
|
+
});
|
|
513
|
+
const batchBody = rawTxs.map((rawTx, index) => ({
|
|
514
|
+
id: index + 1,
|
|
515
|
+
jsonrpc: "2.0",
|
|
516
|
+
method: "eth_sendRawTransaction",
|
|
517
|
+
params: [rawTx],
|
|
518
|
+
}));
|
|
519
|
+
const client = getClient(config);
|
|
520
|
+
const result = await client.POST("/ledger", {
|
|
521
|
+
body: batchBody,
|
|
522
|
+
});
|
|
523
|
+
return unwrap(result);
|
|
524
|
+
},
|
|
525
|
+
id: "ledger.write-batch",
|
|
526
|
+
options: [
|
|
527
|
+
{
|
|
528
|
+
description: "Obtain a fresh access token automatically using the VP flow before submitting the batch. " +
|
|
529
|
+
"Uses the minimal multi-scope token covering every distinct registry in the batch, each " +
|
|
530
|
+
"targeted at the instance it's being written to, unless --scope overrides it.",
|
|
531
|
+
flags: "--auto-token",
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
description: 'EBSI scope to use when requesting a token with --auto-token (e.g. "did-registry:write issuers-registry:write"). ' +
|
|
535
|
+
"Defaults to the minimal multi-scope combination derived from the batch's registries, " +
|
|
536
|
+
"each instance-targeted at its resolved contract address.",
|
|
537
|
+
flags: "--scope <scope>",
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
description: "Path to a VC JWT file. Only relevant if --scope is overridden to a VC-required scope " +
|
|
541
|
+
"(uncommon for a multi-write batch).",
|
|
542
|
+
flags: "--vc <file>",
|
|
543
|
+
},
|
|
544
|
+
...WALLET_KEY_OPTIONS,
|
|
545
|
+
{
|
|
546
|
+
description: "EBSI DID to use. Overrides config/env.",
|
|
547
|
+
flags: "--did <did>",
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
description: "Advanced: manual gas limit (decimal or 0x-prefixed hex), shared by every entry, " +
|
|
551
|
+
"overriding the eth_estimateGas result. By default the gas limit is estimated dynamically, " +
|
|
552
|
+
"per entry, from the node.",
|
|
553
|
+
flags: "--gas-limit <value>",
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
description: "Advanced: manual gas price (decimal or 0x-prefixed hex), shared by every entry, " +
|
|
557
|
+
"forcing legacy transactions. By default fees are derived dynamically from the node " +
|
|
558
|
+
"(EIP-1559 when supported).",
|
|
559
|
+
flags: "--gas-price <value>",
|
|
560
|
+
},
|
|
561
|
+
],
|
|
562
|
+
segments: ["ledger", "write-batch"],
|
|
563
|
+
summary: "Sign several registry writes from one wallet, under one access token, and submit them as a " +
|
|
564
|
+
"single JSON-RPC batch request via POST /ledger — one round-trip instead of one per write. " +
|
|
565
|
+
"Each write gets a sequential nonce so they don't collide. With --auto-token, one multi-scope " +
|
|
566
|
+
"token is minted covering every distinct registry referenced in the batch file " +
|
|
567
|
+
"(combinable scopes only: did-registry:write, issuers-registry:write, timestamp:write, track-and-trace:create, track-and-trace:write, " +
|
|
568
|
+
"policies-registry:write, schemas-registry:write). Returns transaction hashes, not receipts — use `ledger tx <hash>` " +
|
|
569
|
+
"to check status afterwards. Known registries: " +
|
|
570
|
+
REGISTRY_NAMES.join(", ") +
|
|
571
|
+
".",
|
|
572
|
+
},
|
|
573
|
+
];
|
|
397
574
|
//# sourceMappingURL=ledger.js.map
|