@europeum-ebsi/cli 0.0.0 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +289 -289
- package/LICENSES.txt +538 -0
- package/README.md +1140 -98
- package/dist/api/client.d.ts +4 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +14 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/fetch.d.ts +13 -0
- package/dist/api/fetch.d.ts.map +1 -0
- package/dist/api/fetch.js +30 -0
- package/dist/api/fetch.js.map +1 -0
- package/dist/api/params.d.ts +4 -0
- package/dist/api/params.d.ts.map +1 -0
- package/dist/api/params.js +9 -0
- package/dist/api/params.js.map +1 -0
- package/dist/auth/dcql.d.ts +5 -0
- package/dist/auth/dcql.d.ts.map +1 -0
- package/dist/auth/dcql.js +41 -0
- package/dist/auth/dcql.js.map +1 -0
- package/dist/auth/presentation.d.ts +30 -0
- package/dist/auth/presentation.d.ts.map +1 -0
- package/dist/auth/presentation.js +99 -0
- package/dist/auth/presentation.js.map +1 -0
- package/dist/auth/token.d.ts +11 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +116 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +96 -10
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +99 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/config-cmd.d.ts +3 -0
- package/dist/commands/config-cmd.d.ts.map +1 -0
- package/dist/commands/config-cmd.js +86 -0
- package/dist/commands/config-cmd.js.map +1 -0
- package/dist/commands/contracts-registry.d.ts +3 -0
- package/dist/commands/contracts-registry.d.ts.map +1 -0
- package/dist/commands/contracts-registry.js +132 -0
- package/dist/commands/contracts-registry.js.map +1 -0
- package/dist/commands/did-registry.d.ts +3 -0
- package/dist/commands/did-registry.d.ts.map +1 -0
- package/dist/commands/did-registry.js +110 -0
- package/dist/commands/did-registry.js.map +1 -0
- package/dist/commands/faucet.d.ts +3 -0
- package/dist/commands/faucet.d.ts.map +1 -0
- package/dist/commands/faucet.js +78 -0
- package/dist/commands/faucet.js.map +1 -0
- package/dist/commands/health.d.ts +3 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +20 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/issuers-registry.d.ts +3 -0
- package/dist/commands/issuers-registry.d.ts.map +1 -0
- package/dist/commands/issuers-registry.js +340 -0
- package/dist/commands/issuers-registry.js.map +1 -0
- package/dist/commands/ledger.d.ts +3 -0
- package/dist/commands/ledger.d.ts.map +1 -0
- package/dist/commands/ledger.js +549 -372
- package/dist/commands/ledger.js.map +1 -1
- package/dist/commands/onboarding.d.ts +3 -0
- package/dist/commands/onboarding.d.ts.map +1 -0
- package/dist/commands/onboarding.js +301 -0
- package/dist/commands/onboarding.js.map +1 -0
- package/dist/commands/openapi.d.ts +3 -0
- package/dist/commands/openapi.d.ts.map +1 -0
- package/dist/commands/openapi.js +37 -0
- package/dist/commands/openapi.js.map +1 -0
- package/dist/commands/policies-registry.d.ts +3 -0
- package/dist/commands/policies-registry.d.ts.map +1 -0
- package/dist/commands/policies-registry.js +198 -0
- package/dist/commands/policies-registry.js.map +1 -0
- package/dist/commands/registry.d.ts +27 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +62 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/schemas-registry.d.ts +3 -0
- package/dist/commands/schemas-registry.d.ts.map +1 -0
- package/dist/commands/schemas-registry.js +231 -0
- package/dist/commands/schemas-registry.js.map +1 -0
- package/dist/commands/shared/args.d.ts +2 -0
- package/dist/commands/shared/args.d.ts.map +1 -0
- package/dist/commands/shared/args.js +4 -0
- package/dist/commands/shared/args.js.map +1 -0
- package/dist/commands/shared/wallet-opts.d.ts +9 -0
- package/dist/commands/shared/wallet-opts.d.ts.map +1 -0
- package/dist/commands/shared/wallet-opts.js +44 -0
- package/dist/commands/shared/wallet-opts.js.map +1 -0
- package/dist/commands/timestamp.d.ts +3 -0
- package/dist/commands/timestamp.d.ts.map +1 -0
- package/dist/commands/timestamp.js +250 -0
- package/dist/commands/timestamp.js.map +1 -0
- package/dist/commands/track-and-trace.d.ts +3 -0
- package/dist/commands/track-and-trace.d.ts.map +1 -0
- package/dist/commands/track-and-trace.js +235 -0
- package/dist/commands/track-and-trace.js.map +1 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +123 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config/config.d.ts +45 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +111 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/ebsi-env.d.ts +4 -0
- package/dist/config/ebsi-env.d.ts.map +1 -0
- package/dist/config/ebsi-env.js +37 -0
- package/dist/config/ebsi-env.js.map +1 -0
- package/dist/crypto/wallet.d.ts +34 -0
- package/dist/crypto/wallet.d.ts.map +1 -0
- package/dist/crypto/wallet.js +100 -0
- package/dist/crypto/wallet.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/ledger/read.d.ts +11 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +24 -0
- package/dist/ledger/read.js.map +1 -0
- package/dist/ledger/registries.d.ts +25 -0
- package/dist/ledger/registries.d.ts.map +1 -0
- package/dist/ledger/registries.js +111 -0
- package/dist/ledger/registries.js.map +1 -0
- package/dist/ledger/write.d.ts +43 -0
- package/dist/ledger/write.d.ts.map +1 -0
- package/dist/ledger/write.js +119 -0
- package/dist/ledger/write.js.map +1 -0
- package/dist/onboarding/vc.d.ts +18 -0
- package/dist/onboarding/vc.d.ts.map +1 -0
- package/dist/onboarding/vc.js +72 -0
- package/dist/onboarding/vc.js.map +1 -0
- package/dist/output/format.d.ts +7 -0
- package/dist/output/format.d.ts.map +1 -0
- package/dist/output/format.js +94 -0
- package/dist/output/format.js.map +1 -0
- package/dist/tui/App.d.ts +3 -0
- package/dist/tui/App.d.ts.map +1 -0
- package/dist/tui/App.js +99 -0
- package/dist/tui/App.js.map +1 -0
- package/dist/tui/CommandPalette.d.ts +8 -0
- package/dist/tui/CommandPalette.d.ts.map +1 -0
- package/dist/tui/CommandPalette.js +105 -0
- package/dist/tui/CommandPalette.js.map +1 -0
- package/package.json +66 -108
- package/src/api/client.ts +26 -0
- package/src/api/fetch.ts +53 -0
- package/src/api/params.ts +17 -0
- package/src/auth/dcql.ts +84 -0
- package/src/auth/presentation.ts +255 -0
- package/src/auth/token.ts +244 -0
- package/src/cli.ts +164 -0
- package/src/commands/auth.ts +119 -0
- package/src/commands/config-cmd.ts +122 -0
- package/src/commands/contracts-registry.ts +156 -0
- package/src/commands/did-registry.ts +126 -0
- package/src/commands/faucet.ts +112 -0
- package/src/commands/health.ts +21 -0
- package/src/commands/issuers-registry.ts +385 -0
- package/src/commands/ledger.ts +777 -0
- package/src/commands/onboarding.ts +411 -0
- package/src/commands/openapi.ts +42 -0
- package/src/commands/policies-registry.ts +218 -0
- package/src/commands/registry.ts +152 -0
- package/src/commands/schemas-registry.ts +255 -0
- package/src/commands/shared/args.ts +14 -0
- package/src/commands/shared/wallet-opts.ts +85 -0
- package/src/commands/timestamp.ts +272 -0
- package/src/commands/track-and-trace.ts +263 -0
- package/src/commands/wallet.ts +175 -0
- package/src/config/config.ts +275 -0
- package/src/config/ebsi-env.ts +67 -0
- package/src/crypto/wallet.ts +291 -0
- package/src/index.ts +24 -0
- package/src/ledger/read.ts +70 -0
- package/src/ledger/registries.ts +285 -0
- package/src/ledger/write.ts +381 -0
- package/src/onboarding/vc.ts +205 -0
- package/src/output/format.ts +157 -0
- package/src/tui/App.tsx +282 -0
- package/src/tui/CommandPalette.tsx +223 -0
- package/bin/cli.js +0 -13
- package/dist/abi/pilot/DidRegistry.js +0 -568
- package/dist/abi/pilot/DidRegistry.js.map +0 -1
- package/dist/abi/pilot/Ptr.js +0 -666
- package/dist/abi/pilot/Ptr.js.map +0 -1
- package/dist/abi/pilot/SchemaSCRegistry.js +0 -264
- package/dist/abi/pilot/SchemaSCRegistry.js.map +0 -1
- package/dist/abi/pilot/Tcr.js +0 -715
- package/dist/abi/pilot/Tcr.js.map +0 -1
- package/dist/abi/pilot/Timestamp.js +0 -658
- package/dist/abi/pilot/Timestamp.js.map +0 -1
- package/dist/abi/pilot/Tir.js +0 -428
- package/dist/abi/pilot/Tir.js.map +0 -1
- package/dist/abi/pilot/TnT.js +0 -842
- package/dist/abi/pilot/TnT.js.map +0 -1
- package/dist/abi/pilot/Tpr.js +0 -492
- package/dist/abi/pilot/Tpr.js.map +0 -1
- package/dist/abi/test/DidRegistry.js +0 -568
- package/dist/abi/test/DidRegistry.js.map +0 -1
- package/dist/abi/test/Ptr.js +0 -666
- package/dist/abi/test/Ptr.js.map +0 -1
- package/dist/abi/test/SchemaSCRegistry.js +0 -300
- package/dist/abi/test/SchemaSCRegistry.js.map +0 -1
- package/dist/abi/test/Tcr.js +0 -715
- package/dist/abi/test/Tcr.js.map +0 -1
- package/dist/abi/test/Timestamp.js +0 -658
- package/dist/abi/test/Timestamp.js.map +0 -1
- package/dist/abi/test/Tir.js +0 -428
- package/dist/abi/test/Tir.js.map +0 -1
- package/dist/abi/test/TnT.js +0 -842
- package/dist/abi/test/TnT.js.map +0 -1
- package/dist/abi/test/Tpr.js +0 -492
- package/dist/abi/test/Tpr.js.map +0 -1
- package/dist/app.js +0 -659
- package/dist/app.js.map +0 -1
- package/dist/buildParam/didr.js +0 -374
- package/dist/buildParam/didr.js.map +0 -1
- package/dist/buildParam/index.js +0 -53
- package/dist/buildParam/index.js.map +0 -1
- package/dist/buildParam/ptr.js +0 -80
- package/dist/buildParam/ptr.js.map +0 -1
- package/dist/buildParam/tcr.js +0 -36
- package/dist/buildParam/tcr.js.map +0 -1
- package/dist/buildParam/timestamp.js +0 -350
- package/dist/buildParam/timestamp.js.map +0 -1
- package/dist/buildParam/tir.js +0 -110
- package/dist/buildParam/tir.js.map +0 -1
- package/dist/buildParam/tnt.js +0 -214
- package/dist/buildParam/tnt.js.map +0 -1
- package/dist/buildParam/tpr.js +0 -91
- package/dist/buildParam/tpr.js.map +0 -1
- package/dist/buildParam/tsr.js +0 -115
- package/dist/buildParam/tsr.js.map +0 -1
- package/dist/commands/authorisation.js +0 -144
- package/dist/commands/authorisation.js.map +0 -1
- package/dist/commands/compute.js +0 -680
- package/dist/commands/compute.js.map +0 -1
- package/dist/commands/conformance.js +0 -813
- package/dist/commands/conformance.js.map +0 -1
- package/dist/commands/hardwarewallet.js +0 -41
- package/dist/commands/hardwarewallet.js.map +0 -1
- package/dist/commands/index.js +0 -8
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/ptr.js +0 -54
- package/dist/commands/ptr.js.map +0 -1
- package/dist/commands/tcr.js +0 -50
- package/dist/commands/tcr.js.map +0 -1
- package/dist/commands/tir.js +0 -64
- package/dist/commands/tir.js.map +0 -1
- package/dist/commands/tnl.js +0 -81
- package/dist/commands/tnl.js.map +0 -1
- package/dist/commands/tsr.js +0 -45
- package/dist/commands/tsr.js.map +0 -1
- package/dist/commands/view.js +0 -53
- package/dist/commands/view.js.map +0 -1
- package/dist/config.js +0 -497
- package/dist/config.js.map +0 -1
- package/dist/interfaces/context.js +0 -2
- package/dist/interfaces/context.js.map +0 -1
- package/dist/interfaces/contracts/ProxyFactory.js +0 -2
- package/dist/interfaces/contracts/ProxyFactory.js.map +0 -1
- package/dist/interfaces/contracts/ProxyTemplateRegistry.js +0 -2
- package/dist/interfaces/contracts/ProxyTemplateRegistry.js.map +0 -1
- package/dist/interfaces/contracts/SchemaSCRegistry.js +0 -2
- package/dist/interfaces/contracts/SchemaSCRegistry.js.map +0 -1
- package/dist/interfaces/contracts/common.js +0 -2
- package/dist/interfaces/contracts/common.js.map +0 -1
- package/dist/interfaces/index.js +0 -5
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/jsonrpc.interface.js +0 -2
- package/dist/interfaces/jsonrpc.interface.js.map +0 -1
- package/dist/interfaces/paginated-list.interface.js +0 -2
- package/dist/interfaces/paginated-list.interface.js.map +0 -1
- package/dist/interfaces/unsigned-transaction.interface.js +0 -2
- package/dist/interfaces/unsigned-transaction.interface.js.map +0 -1
- package/dist/interfaces/utils.interface.js +0 -2
- package/dist/interfaces/utils.interface.js.map +0 -1
- package/dist/programs/migrateDid.js +0 -159
- package/dist/programs/migrateDid.js.map +0 -1
- package/dist/programs/migrateDids.js +0 -232
- package/dist/programs/migrateDids.js.map +0 -1
- package/dist/programs/migrateTsr.js +0 -201
- package/dist/programs/migrateTsr.js.map +0 -1
- package/dist/scripts/accreditAndAuthorize/conformance/step1 +0 -34
- package/dist/scripts/accreditAndAuthorize/conformance/step2 +0 -18
- package/dist/scripts/accreditAndAuthorize/conformance/step3 +0 -9
- package/dist/scripts/accreditAndAuthorize/conformance/step4 +0 -27
- package/dist/scripts/accreditAndAuthorize/conformance/step5 +0 -13
- package/dist/scripts/accreditAndAuthorize/conformance/step6 +0 -14
- package/dist/scripts/accreditAndAuthorize/conformance/step7 +0 -7
- package/dist/scripts/accreditAndAuthorize/test/step1 +0 -34
- package/dist/scripts/accreditAndAuthorize/test/step2 +0 -18
- package/dist/scripts/accreditAndAuthorize/test/step3 +0 -9
- package/dist/scripts/accreditAndAuthorize/test/step4 +0 -27
- package/dist/scripts/accreditAndAuthorize/test/step5 +0 -13
- package/dist/scripts/accreditAndAuthorize/test/step6 +0 -14
- package/dist/scripts/accreditAndAuthorize/test/step7 +0 -7
- package/dist/scripts/accreditTI +0 -21
- package/dist/scripts/assets/Nodes.json +0 -27
- package/dist/scripts/assets/vcdm1.1/CTRevocableCredential.json +0 -30
- package/dist/scripts/assets/vcdm1.1/CredentialToAttestVerifiableAuthorisationForTrustChain.json +0 -29
- package/dist/scripts/assets/vcdm1.1/Nodes.json +0 -27
- package/dist/scripts/assets/vcdm1.1/TrustedNodesList.json +0 -35
- package/dist/scripts/assets/vcdm1.1/VerifiableAccreditationToAccredit.json +0 -35
- package/dist/scripts/assets/vcdm1.1/VerifiableAccreditationToAttest.json +0 -33
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationForTrustChain.json +0 -22
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationToInvoke.json +0 -24
- package/dist/scripts/assets/vcdm1.1/VerifiableAuthorisationToOnboard.json +0 -24
- package/dist/scripts/assets/vcdm2.0/CredentialToAttestVerifiableAuthorisationForTrustChain.json +0 -29
- package/dist/scripts/assets/vcdm2.0/TrustedNodesList.json +0 -36
- package/dist/scripts/assets/vcdm2.0/VerifiableAccreditationToAccredit.json +0 -40
- package/dist/scripts/assets/vcdm2.0/VerifiableAccreditationToAttest.json +0 -38
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationForTrustChain.json +0 -30
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationToInvoke.json +0 -24
- package/dist/scripts/assets/vcdm2.0/VerifiableAuthorisationToOnboard.json +0 -23
- package/dist/scripts/bootstrap/0a-loadTPROperator +0 -5
- package/dist/scripts/bootstrap/0b-loadAdmin +0 -8
- package/dist/scripts/bootstrap/1-populateTPR +0 -92
- package/dist/scripts/bootstrap/2-populateDID +0 -6
- package/dist/scripts/bootstrap/3-populateTimestamp +0 -9
- package/dist/scripts/bootstrap/4-populateTIR +0 -8
- package/dist/scripts/bootstrap/5-populateTSR +0 -85
- package/dist/scripts/bootstrap/6-setupConformanceIssuer +0 -35
- package/dist/scripts/bootstrap/README.md +0 -218
- package/dist/scripts/issueVcInvoke +0 -10
- package/dist/scripts/issueVcOnboard +0 -9
- package/dist/scripts/issueVcRootTAO +0 -11
- package/dist/scripts/issueVcTAO +0 -12
- package/dist/scripts/issueVcTI +0 -12
- package/dist/scripts/issueVcTnl +0 -32
- package/dist/scripts/issue_CTRevocableCredential +0 -12
- package/dist/scripts/issue_SelfAttestationSupportOffice +0 -10
- package/dist/scripts/issue_VerifiableAccreditationToAccredit +0 -11
- package/dist/scripts/issue_VerifiableAccreditationToAttest +0 -11
- package/dist/scripts/issue_VerifiableAuthorisationForTrustChain +0 -10
- package/dist/scripts/issue_VerifiableAuthorisationToOnboard +0 -9
- package/dist/scripts/preregisterIssuer +0 -6
- package/dist/scripts/registerDidDocument +0 -15
- package/dist/scripts/registerIssuer +0 -6
- package/dist/scripts/updateVcRootTAO +0 -10
- package/dist/scripts/updateVcTAO +0 -11
- package/dist/scripts/updateVcTI +0 -11
- package/dist/scripts/vcdm2.0/issueSelfAttestationSupportOffice +0 -10
- package/dist/scripts/vcdm2.0/issueVcInvoke +0 -12
- package/dist/scripts/vcdm2.0/issueVcOnboard +0 -11
- package/dist/scripts/vcdm2.0/issueVcRootTAO +0 -14
- package/dist/scripts/vcdm2.0/issueVcTAO +0 -15
- package/dist/scripts/vcdm2.0/issueVcTI +0 -15
- package/dist/scripts/vcdm2.0/issueVcTnl +0 -34
- package/dist/scripts/vcdm2.0/registerDidDocument +0 -15
- package/dist/scripts/vcdm2.0/updateVcRootTAO +0 -13
- package/dist/scripts/vcdm2.0/updateVcTAO +0 -14
- package/dist/scripts/vcdm2.0/updateVcTI +0 -14
- package/dist/scripts/vcdm2.0/verifyVcTnl +0 -10
- package/dist/scripts/verifyVcTnl +0 -10
- package/dist/scripts/wct/accreditAndAuthorize +0 -133
- package/dist/scripts/wct/accreditAndAuthorize2 +0 -89
- package/dist/scripts/wct/holderWallet +0 -39
- package/dist/scripts/wct/holderWallet2 +0 -39
- package/dist/scripts/wct/issueToHolder +0 -38
- package/dist/scripts/wct/issueToHolder2 +0 -38
- package/dist/scripts/wct/pda1 +0 -3
- package/dist/scripts/wct/verifier +0 -8
- package/dist/scripts/wct/verifier2 +0 -7
- package/dist/utils/Client.js +0 -155
- package/dist/utils/Client.js.map +0 -1
- package/dist/utils/HardwareWallet.js +0 -326
- package/dist/utils/HardwareWallet.js.map +0 -1
- package/dist/utils/http.js +0 -132
- package/dist/utils/http.js.map +0 -1
- package/dist/utils/index.js +0 -8
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/jsonrpc.js +0 -38
- package/dist/utils/jsonrpc.js.map +0 -1
- package/dist/utils/print.js +0 -56
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/utils.js +0 -427
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/vcdm.js +0 -47
- package/dist/utils/vcdm.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
|
|
3
|
+
import type { CliConfig } from "../config/config.ts";
|
|
4
|
+
import type { RegistryEntry } from "./registries.ts";
|
|
5
|
+
|
|
6
|
+
export interface ReadOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Resolved CLI configuration (used for baseUrl)
|
|
9
|
+
*/
|
|
10
|
+
config: CliConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Contract address (0x-prefixed)
|
|
13
|
+
*/
|
|
14
|
+
contractAddress: string;
|
|
15
|
+
/**
|
|
16
|
+
* Parsed function arguments (from the JSON array on the CLI)
|
|
17
|
+
*/
|
|
18
|
+
functionArgs: unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* Smart contract view/pure function name (e.g. "getTimestamp")
|
|
21
|
+
*/
|
|
22
|
+
functionName: string;
|
|
23
|
+
/**
|
|
24
|
+
* Registry entry providing the ABI interface
|
|
25
|
+
*/
|
|
26
|
+
registry: RegistryEntry;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Encodes a contract view/pure function call and resolves it via the Ledger
|
|
31
|
+
* service's `eth_call` (served anonymously — no Bearer token needed, unlike
|
|
32
|
+
* `writeToRegistry`), decoding the result with the same registry interface
|
|
33
|
+
* `writeToRegistry` uses to encode writes.
|
|
34
|
+
*
|
|
35
|
+
* Always returns the function's outputs as an array, in declaration order,
|
|
36
|
+
* regardless of how many there are — the same shape for every function,
|
|
37
|
+
* rather than guessing whether to unwrap a single return value.
|
|
38
|
+
*/
|
|
39
|
+
export async function readFromRegistry(opts: ReadOptions): Promise<unknown> {
|
|
40
|
+
const { config, contractAddress, functionArgs, functionName, registry } =
|
|
41
|
+
opts;
|
|
42
|
+
|
|
43
|
+
const iface = registry.getInterface();
|
|
44
|
+
let data: string;
|
|
45
|
+
try {
|
|
46
|
+
data = iface.encodeFunctionData(functionName, functionArgs);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Failed to encode function data for "${functionName}": ${message}. ` +
|
|
51
|
+
"Check the function name and argument types.",
|
|
52
|
+
{ cause: error },
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const provider = new ethers.JsonRpcProvider(`${config.baseUrl}/ledger`);
|
|
57
|
+
const result = await provider.call({ data, to: contractAddress });
|
|
58
|
+
const decoded = iface.decodeFunctionResult(functionName, result);
|
|
59
|
+
|
|
60
|
+
return toJsonSafe(decoded);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Recursively converts ethers decode output (BigInt values, nested Result
|
|
65
|
+
* arrays) into a shape `JSON.stringify` can handle without throwing.
|
|
66
|
+
*/
|
|
67
|
+
function toJsonSafe(value: unknown): unknown {
|
|
68
|
+
if (typeof value === "bigint") return value.toString();
|
|
69
|
+
return Array.isArray(value) ? value.map((item) => toJsonSafe(item)) : value;
|
|
70
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
const req = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
export interface RegistryEntry {
|
|
7
|
+
/**
|
|
8
|
+
* Environment variable that holds the contract address.
|
|
9
|
+
* Mirrors the API's configuration env key (e.g. DID_REGISTRY_CONTRACT_ADDRESS).
|
|
10
|
+
*
|
|
11
|
+
* Dual-purpose: `ledger write` uses it (via `--to`) to pick a signing
|
|
12
|
+
* target, and read commands' `--contract-address` flag (via
|
|
13
|
+
* `resolveContractAddress`) uses the same variable as their default query
|
|
14
|
+
* target, so reads and writes stay consistent within one environment. If
|
|
15
|
+
* you only meant to set this for a one-off write, note that it will also
|
|
16
|
+
* silently redirect reads in the same shell/session unless you pass
|
|
17
|
+
* `--contract-address` explicitly on those calls.
|
|
18
|
+
*/
|
|
19
|
+
addressEnvKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* Default EBSI scope for `--auto-token` (e.g. "did-registry:write")
|
|
22
|
+
*/
|
|
23
|
+
defaultScope: string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the ethers Interface for ABI encoding
|
|
26
|
+
*/
|
|
27
|
+
getInterface(): ethers.Interface;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Loads a contract factory from a CJS package via `createRequire` and calls
|
|
32
|
+
* its static `createInterface()` method to get an `ethers.Interface`.
|
|
33
|
+
*
|
|
34
|
+
* The factory packages are CommonJS; `createRequire` is the idiomatic ESM way
|
|
35
|
+
* to consume CJS in a Node.js ESM module.
|
|
36
|
+
*/
|
|
37
|
+
function loadInterface(pkg: string, factoryName: string): ethers.Interface {
|
|
38
|
+
const mod = req(pkg) as Record<
|
|
39
|
+
string,
|
|
40
|
+
undefined | { createInterface(): ethers.Interface }
|
|
41
|
+
>;
|
|
42
|
+
const factory = mod[factoryName];
|
|
43
|
+
/* v8 ignore next 4 — factory names are hardcoded; unreachable in practice */
|
|
44
|
+
if (!factory) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Factory class "${factoryName}" not found in package "${pkg}"`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return factory.createInterface();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Registry table: CLI name → factory / scope / address info.
|
|
54
|
+
*
|
|
55
|
+
* Contract addresses are NOT served by the API; they must be supplied via
|
|
56
|
+
* `--to`, the matching env var, or (for convenience) the persisted config.
|
|
57
|
+
*/
|
|
58
|
+
export const REGISTRIES: Record<string, RegistryEntry | undefined> = {
|
|
59
|
+
"did-registry": {
|
|
60
|
+
addressEnvKey: "DID_REGISTRY_CONTRACT_ADDRESS",
|
|
61
|
+
defaultScope: "did-registry:write",
|
|
62
|
+
getInterface() {
|
|
63
|
+
return loadInterface(
|
|
64
|
+
"@europeum-ebsi/did-registry-contract",
|
|
65
|
+
"DidRegistry__factory",
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
"issuers-registry": {
|
|
70
|
+
addressEnvKey: "ISSUERS_REGISTRY_CONTRACT_ADDRESS",
|
|
71
|
+
defaultScope: "issuers-registry:write",
|
|
72
|
+
getInterface() {
|
|
73
|
+
return loadInterface(
|
|
74
|
+
"@europeum-ebsi/issuers-registry-contract",
|
|
75
|
+
"IssuersRegistry__factory",
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
"policies-registry": {
|
|
80
|
+
addressEnvKey: "POLICIES_REGISTRY_CONTRACT_ADDRESS",
|
|
81
|
+
defaultScope: "policies-registry:write",
|
|
82
|
+
getInterface() {
|
|
83
|
+
return loadInterface(
|
|
84
|
+
"@europeum-ebsi/policies-registry-contract",
|
|
85
|
+
"PoliciesRegistry__factory",
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
"schemas-registry": {
|
|
90
|
+
addressEnvKey: "SCHEMAS_REGISTRY_CONTRACT_ADDRESS",
|
|
91
|
+
defaultScope: "schemas-registry:write",
|
|
92
|
+
getInterface() {
|
|
93
|
+
return loadInterface(
|
|
94
|
+
"@europeum-ebsi/schemas-registry-contract",
|
|
95
|
+
"SchemasRegistry__factory",
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
timestamp: {
|
|
100
|
+
addressEnvKey: "TIMESTAMP_CONTRACT_ADDRESS",
|
|
101
|
+
defaultScope: "timestamp:write",
|
|
102
|
+
getInterface() {
|
|
103
|
+
return loadInterface(
|
|
104
|
+
"@europeum-ebsi/timestamp-contract",
|
|
105
|
+
"Timestamp__factory",
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
"track-and-trace": {
|
|
110
|
+
addressEnvKey: "TRACK_AND_TRACE_CONTRACT_ADDRESS",
|
|
111
|
+
defaultScope: "track-and-trace:write",
|
|
112
|
+
getInterface() {
|
|
113
|
+
return loadInterface(
|
|
114
|
+
"@europeum-ebsi/track-and-trace-contract",
|
|
115
|
+
"TrackAndTrace__factory",
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns all known registry names (for help text / validation).
|
|
123
|
+
*/
|
|
124
|
+
export const REGISTRY_NAMES = Object.keys(REGISTRIES);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A `--contract-address` CLI option, plus its resolver against `envKey`.
|
|
128
|
+
*/
|
|
129
|
+
export interface ContractAddressOption {
|
|
130
|
+
option: { description: string; flags: string };
|
|
131
|
+
resolve: (opts: Record<string, string>) => string | undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* One resolved write target in a batch: which registry, which function, and
|
|
136
|
+
* which contract instance. `functionName` is optional so callers that don't
|
|
137
|
+
* need the `insertDidDocument` special-case (see `defaultScopeFor`) can omit
|
|
138
|
+
* it.
|
|
139
|
+
*/
|
|
140
|
+
export interface RegistryTarget {
|
|
141
|
+
functionName?: string;
|
|
142
|
+
registryName: string;
|
|
143
|
+
to: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Builds a `--contract-address` option + resolver reading from `envKey`, with
|
|
148
|
+
* a given description. Used directly by `contracts-registry` commands, which
|
|
149
|
+
* (unlike every other registry) have no `ledger write` path and therefore no
|
|
150
|
+
* `REGISTRIES[...].addressEnvKey` to derive from — see
|
|
151
|
+
* `contractAddressOptionFor` for the common case.
|
|
152
|
+
*/
|
|
153
|
+
export function contractAddressOption(
|
|
154
|
+
envKey: string,
|
|
155
|
+
description: string,
|
|
156
|
+
): ContractAddressOption {
|
|
157
|
+
return {
|
|
158
|
+
option: { description, flags: "--contract-address <address>" },
|
|
159
|
+
resolve: (opts) => resolveContractAddress(opts, envKey),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Builds a `--contract-address` option + resolver for `registryName`, using
|
|
165
|
+
* its `REGISTRIES[...].addressEnvKey` and the standard description noting
|
|
166
|
+
* that it defaults to the same address `ledger write` signs against.
|
|
167
|
+
*/
|
|
168
|
+
export function contractAddressOptionFor(
|
|
169
|
+
registryName: string,
|
|
170
|
+
): ContractAddressOption {
|
|
171
|
+
const registry = REGISTRIES[registryName];
|
|
172
|
+
if (!registry) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Unknown registry "${registryName}". Known registries: ${REGISTRY_NAMES.join(", ")}`,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return contractAddressOption(
|
|
178
|
+
registry.addressEnvKey,
|
|
179
|
+
`Contract address to query. Defaults to $${registry.addressEnvKey} if set (the same address "ledger write" signs against), otherwise the API's configured default.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Track and Trace's scope requirement per function — mirrors
|
|
185
|
+
* `TRACK_AND_TRACE_FUNCTION_SCOPE` in `api/src/modules/ledger/validators/track-and-trace.ts`
|
|
186
|
+
* (the API's authoritative, per-function scope gate for this registry).
|
|
187
|
+
* There's no shared package to import this from (it's private to the API's
|
|
188
|
+
* ledger validators), so keep this in sync by hand if that table changes.
|
|
189
|
+
*
|
|
190
|
+
* `registry.defaultScope` ("track-and-trace:write") only covers `grantAccess`,
|
|
191
|
+
* `removeDocument`, `revokeAccess`, and `writeEvent` — `authoriseDid` needs
|
|
192
|
+
* the VC-required `track-and-trace:authorise`, and `createDocument`/`commitCreateDocument`
|
|
193
|
+
* need `track-and-trace:create`.
|
|
194
|
+
*/
|
|
195
|
+
const TRACK_AND_TRACE_FUNCTION_SCOPE: Record<string, string> = {
|
|
196
|
+
authoriseDid: "track-and-trace:authorise",
|
|
197
|
+
commitCreateDocument: "track-and-trace:create",
|
|
198
|
+
createDocument: "track-and-trace:create",
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The scope family a write to `registryName`/`functionName` needs, for
|
|
203
|
+
* deriving a default `--auto-token` scope.
|
|
204
|
+
*
|
|
205
|
+
* This is `registry.defaultScope` for every function except:
|
|
206
|
+
* - DID Registry's `insertDidDocument`, which (unlike every other DID
|
|
207
|
+
* Registry write) onboards a *new* DID and so requires `did-registry:invite`, not
|
|
208
|
+
* `did-registry:write` — see `api/src/modules/ledger/validators/did-registry.ts`.
|
|
209
|
+
* - Track and Trace's `authoriseDid`/`createDocument`/`commitCreateDocument`
|
|
210
|
+
* — see `TRACK_AND_TRACE_FUNCTION_SCOPE`.
|
|
211
|
+
*/
|
|
212
|
+
export function defaultScopeFor(
|
|
213
|
+
registryName: string,
|
|
214
|
+
functionName: string | undefined,
|
|
215
|
+
registry: RegistryEntry,
|
|
216
|
+
): string {
|
|
217
|
+
if (registryName === "did-registry" && functionName === "insertDidDocument") {
|
|
218
|
+
return "did-registry:invite";
|
|
219
|
+
}
|
|
220
|
+
if (registryName === "track-and-trace" && functionName !== undefined) {
|
|
221
|
+
const scope = TRACK_AND_TRACE_FUNCTION_SCOPE[functionName];
|
|
222
|
+
if (scope) {
|
|
223
|
+
return scope;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return registry.defaultScope;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Derives the minimal space-separated multi-scope string covering every
|
|
231
|
+
* resolved `(registryName, functionName, to)` target, using `defaultScopeFor`
|
|
232
|
+
* — instance-targeted at the resolved `to` address, since each write is
|
|
233
|
+
* authorised against the specific beacon-proxy instance it's sent to (see
|
|
234
|
+
* "Auto-target the write instance" in the instance-targeting design). Scopes
|
|
235
|
+
* are deduped and sorted so the result is independent of input order — used
|
|
236
|
+
* by `ledger write-batch --auto-token` to mint a single token that authorises
|
|
237
|
+
* every write in the batch.
|
|
238
|
+
*
|
|
239
|
+
* Throws if any registry name is unknown, or if the batch targets two
|
|
240
|
+
* different instances under the same scope family (a single access token can
|
|
241
|
+
* only target one instance per family — split the batch, or pass
|
|
242
|
+
* `--token`/`--scope` explicitly in that case).
|
|
243
|
+
*/
|
|
244
|
+
export function deriveScopeForRegistries(targets: RegistryTarget[]): string {
|
|
245
|
+
const addressByFamily = new Map<string, string>();
|
|
246
|
+
for (const { functionName, registryName, to } of targets) {
|
|
247
|
+
const registry = REGISTRIES[registryName];
|
|
248
|
+
if (!registry) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Unknown registry "${registryName}". Known registries: ${REGISTRY_NAMES.join(", ")}`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const family = defaultScopeFor(registryName, functionName, registry);
|
|
255
|
+
const existingAddress = addressByFamily.get(family);
|
|
256
|
+
if (existingAddress !== undefined && existingAddress !== to) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
`Batch targets two different "${family}" contract instances (${existingAddress} and ${to}) ` +
|
|
259
|
+
"in a single --auto-token request. A single access token can only target one instance " +
|
|
260
|
+
"per scope family — split the batch, or provide --token/--scope explicitly.",
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
addressByFamily.set(family, to);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return [...addressByFamily]
|
|
267
|
+
.map(([family, address]) => `${family}:${address}`)
|
|
268
|
+
.toSorted((a, b) => a.localeCompare(b))
|
|
269
|
+
.join(" ");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Resolves the contract address for a read command: an explicit
|
|
274
|
+
* `--contract-address` flag value if given, otherwise the given environment
|
|
275
|
+
* variable (typically `RegistryEntry.addressEnvKey`, the same variable
|
|
276
|
+
* `ledger write` uses to pick a signing target — see that field's doc
|
|
277
|
+
* comment). Falls through to `undefined` (the API's own configured default)
|
|
278
|
+
* if neither is set.
|
|
279
|
+
*/
|
|
280
|
+
function resolveContractAddress(
|
|
281
|
+
opts: Record<string, string>,
|
|
282
|
+
envKey: string,
|
|
283
|
+
): string | undefined {
|
|
284
|
+
return opts["contractAddress"] ?? process.env[envKey];
|
|
285
|
+
}
|