@ottochain/sdk 0.2.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/README.md +305 -0
- package/dist/apps/contracts/index.d.ts +21 -0
- package/dist/apps/contracts/index.js +39 -0
- package/dist/apps/contracts/types.d.ts +24 -0
- package/dist/apps/contracts/types.js +48 -0
- package/dist/apps/identity/index.d.ts +22 -0
- package/dist/apps/identity/index.js +40 -0
- package/dist/apps/identity/types.d.ts +30 -0
- package/dist/apps/identity/types.js +53 -0
- package/dist/apps/index.d.ts +29 -0
- package/dist/apps/index.js +60 -0
- package/dist/apps/markets/index.d.ts +26 -0
- package/dist/apps/markets/index.js +46 -0
- package/dist/apps/markets/types.d.ts +185 -0
- package/dist/apps/markets/types.js +252 -0
- package/dist/apps/oracles/index.d.ts +26 -0
- package/dist/apps/oracles/index.js +46 -0
- package/dist/apps/oracles/types.d.ts +211 -0
- package/dist/apps/oracles/types.js +306 -0
- package/dist/cjs/apps/contracts/index.js +60 -0
- package/dist/cjs/apps/contracts/state-machines/contract.json +420 -0
- package/dist/cjs/apps/contracts/state-machines/escrow.json +426 -0
- package/dist/cjs/apps/contracts/types.js +48 -0
- package/dist/cjs/apps/corporate/index.js +112 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-board.json +1064 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-bylaws.json +751 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-committee.json +957 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-compliance.json +1293 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-entity.json +861 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-officers.json +843 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-proxy.json +783 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-resolution.json +1174 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-securities.json +1215 -0
- package/dist/cjs/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
- package/dist/cjs/apps/corporate/types.js +44 -0
- package/dist/cjs/apps/governance/index.js +203 -0
- package/dist/cjs/apps/governance/state-machines/dao-multisig.json +711 -0
- package/dist/cjs/apps/governance/state-machines/dao-single.json +258 -0
- package/dist/cjs/apps/governance/state-machines/dao-threshold.json +660 -0
- package/dist/cjs/apps/governance/state-machines/dao-token.json +680 -0
- package/dist/cjs/apps/governance/state-machines/governance-constitution.json +401 -0
- package/dist/cjs/apps/governance/state-machines/governance-executive.json +441 -0
- package/dist/cjs/apps/governance/state-machines/governance-judiciary.json +626 -0
- package/dist/cjs/apps/governance/state-machines/governance-legislature.json +726 -0
- package/dist/cjs/apps/governance/state-machines/governance-simple.json +679 -0
- package/dist/cjs/apps/governance/types.js +42 -0
- package/dist/cjs/apps/identity/constants.js +58 -0
- package/dist/cjs/apps/identity/index.js +78 -0
- package/dist/cjs/apps/identity/state-machines/agent-identity.json +320 -0
- package/dist/cjs/apps/identity/types.js +53 -0
- package/dist/cjs/apps/index.js +58 -0
- package/dist/cjs/apps/markets/index.js +55 -0
- package/dist/cjs/apps/markets/state-machines/market-universal.json +354 -0
- package/dist/cjs/apps/markets/types.js +219 -0
- package/dist/cjs/apps/oracles/index.js +62 -0
- package/dist/cjs/apps/oracles/state-machines/oracle.json +452 -0
- package/dist/cjs/apps/oracles/types.js +282 -0
- package/dist/cjs/errors.js +293 -0
- package/dist/cjs/generated/google/protobuf/struct.js +514 -0
- package/dist/cjs/generated/google/protobuf/timestamp.js +92 -0
- package/dist/cjs/generated/index.js +150 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +873 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +4515 -0
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +392 -0
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +3255 -0
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +235 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent.js +619 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +780 -0
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1261 -0
- package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle.js +1223 -0
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
- package/dist/cjs/generated/ottochain/v1/common.js +10 -0
- package/dist/cjs/generated/ottochain/v1/common_pb.js +37 -0
- package/dist/cjs/generated/ottochain/v1/fiber.js +1057 -0
- package/dist/cjs/generated/ottochain/v1/fiber_pb.js +86 -0
- package/dist/cjs/generated/ottochain/v1/messages.js +740 -0
- package/dist/cjs/generated/ottochain/v1/messages_pb.js +44 -0
- package/dist/cjs/generated/ottochain/v1/records.js +1253 -0
- package/dist/cjs/generated/ottochain/v1/records_pb.js +44 -0
- package/dist/cjs/index.js +79 -0
- package/dist/cjs/metakit/binary.js +58 -0
- package/dist/cjs/metakit/canonicalize.js +40 -0
- package/dist/cjs/metakit/codec.js +45 -0
- package/dist/cjs/metakit/currency-transaction.js +319 -0
- package/dist/cjs/metakit/currency-types.js +13 -0
- package/dist/cjs/metakit/hash.js +84 -0
- package/dist/cjs/metakit/index.js +74 -0
- package/dist/cjs/metakit/network/client.js +78 -0
- package/dist/cjs/metakit/network/currency-l1-client.js +101 -0
- package/dist/cjs/metakit/network/data-l1-client.js +76 -0
- package/dist/cjs/metakit/network/index.js +16 -0
- package/dist/cjs/metakit/network/types.js +20 -0
- package/dist/cjs/metakit/sign.js +120 -0
- package/dist/cjs/metakit/signed-object.js +100 -0
- package/dist/cjs/metakit/types.js +14 -0
- package/dist/cjs/metakit/verify.js +217 -0
- package/dist/cjs/metakit/wallet.js +127 -0
- package/dist/cjs/ottochain/index.js +47 -0
- package/dist/cjs/ottochain/metagraph-client.js +157 -0
- package/dist/cjs/ottochain/snapshot.js +110 -0
- package/dist/cjs/ottochain/types.js +11 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.js +25 -0
- package/dist/cjs/validation.js +312 -0
- package/dist/errors.d.ts +221 -0
- package/dist/errors.js +293 -0
- package/dist/esm/apps/contracts/index.js +42 -0
- package/dist/esm/apps/contracts/state-machines/contract.json +420 -0
- package/dist/esm/apps/contracts/state-machines/escrow.json +426 -0
- package/dist/esm/apps/contracts/types.js +44 -0
- package/dist/esm/apps/corporate/index.js +57 -0
- package/dist/esm/apps/corporate/state-machines/corporate-board.json +1064 -0
- package/dist/esm/apps/corporate/state-machines/corporate-bylaws.json +751 -0
- package/dist/esm/apps/corporate/state-machines/corporate-committee.json +957 -0
- package/dist/esm/apps/corporate/state-machines/corporate-compliance.json +1293 -0
- package/dist/esm/apps/corporate/state-machines/corporate-entity.json +861 -0
- package/dist/esm/apps/corporate/state-machines/corporate-officers.json +843 -0
- package/dist/esm/apps/corporate/state-machines/corporate-proxy.json +783 -0
- package/dist/esm/apps/corporate/state-machines/corporate-resolution.json +1174 -0
- package/dist/esm/apps/corporate/state-machines/corporate-securities.json +1215 -0
- package/dist/esm/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
- package/dist/esm/apps/corporate/types.js +38 -0
- package/dist/esm/apps/governance/index.js +154 -0
- package/dist/esm/apps/governance/state-machines/dao-multisig.json +711 -0
- package/dist/esm/apps/governance/state-machines/dao-single.json +258 -0
- package/dist/esm/apps/governance/state-machines/dao-threshold.json +660 -0
- package/dist/esm/apps/governance/state-machines/dao-token.json +680 -0
- package/dist/esm/apps/governance/state-machines/governance-constitution.json +401 -0
- package/dist/esm/apps/governance/state-machines/governance-executive.json +441 -0
- package/dist/esm/apps/governance/state-machines/governance-judiciary.json +626 -0
- package/dist/esm/apps/governance/state-machines/governance-legislature.json +726 -0
- package/dist/esm/apps/governance/state-machines/governance-simple.json +679 -0
- package/dist/esm/apps/governance/types.js +35 -0
- package/dist/esm/apps/identity/constants.js +53 -0
- package/dist/esm/apps/identity/index.js +50 -0
- package/dist/esm/apps/identity/state-machines/agent-identity.json +320 -0
- package/dist/esm/apps/identity/types.js +50 -0
- package/dist/esm/apps/index.js +32 -0
- package/dist/esm/apps/markets/index.js +34 -0
- package/dist/esm/apps/markets/state-machines/market-universal.json +354 -0
- package/dist/esm/apps/markets/types.js +206 -0
- package/dist/esm/apps/oracles/index.js +42 -0
- package/dist/esm/apps/oracles/state-machines/oracle.json +452 -0
- package/dist/esm/apps/oracles/types.js +267 -0
- package/dist/esm/errors.js +283 -0
- package/dist/esm/generated/google/protobuf/struct.js +508 -0
- package/dist/esm/generated/google/protobuf/timestamp.js +89 -0
- package/dist/esm/generated/index.js +26 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +867 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +97 -0
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +4493 -0
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +389 -0
- package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +3240 -0
- package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +232 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +610 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +113 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +774 -0
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +76 -0
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1252 -0
- package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +148 -0
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +1217 -0
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +106 -0
- package/dist/esm/generated/ottochain/v1/common.js +7 -0
- package/dist/esm/generated/ottochain/v1/common_pb.js +34 -0
- package/dist/esm/generated/ottochain/v1/fiber.js +1051 -0
- package/dist/esm/generated/ottochain/v1/fiber_pb.js +83 -0
- package/dist/esm/generated/ottochain/v1/messages.js +737 -0
- package/dist/esm/generated/ottochain/v1/messages_pb.js +41 -0
- package/dist/esm/generated/ottochain/v1/records.js +1250 -0
- package/dist/esm/generated/ottochain/v1/records_pb.js +41 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/metakit/binary.js +53 -0
- package/dist/esm/metakit/canonicalize.js +33 -0
- package/dist/esm/metakit/codec.js +38 -0
- package/dist/esm/metakit/currency-transaction.js +306 -0
- package/dist/esm/metakit/currency-types.js +10 -0
- package/dist/esm/metakit/hash.js +77 -0
- package/dist/esm/metakit/index.js +30 -0
- package/dist/esm/metakit/network/client.js +74 -0
- package/dist/esm/metakit/network/currency-l1-client.js +97 -0
- package/dist/esm/metakit/network/data-l1-client.js +72 -0
- package/dist/esm/metakit/network/index.js +9 -0
- package/dist/esm/metakit/network/types.js +16 -0
- package/dist/esm/metakit/sign.js +114 -0
- package/dist/esm/metakit/signed-object.js +94 -0
- package/dist/esm/metakit/types.js +11 -0
- package/dist/esm/metakit/verify.js +210 -0
- package/dist/esm/metakit/wallet.js +117 -0
- package/dist/esm/ottochain/index.js +13 -0
- package/dist/esm/ottochain/metagraph-client.js +153 -0
- package/dist/esm/ottochain/snapshot.js +100 -0
- package/dist/esm/ottochain/types.js +10 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/validation.js +301 -0
- package/dist/generated/index.d.ts +15 -0
- package/dist/generated/index.js +34 -0
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
- package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
- package/dist/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
- package/dist/generated/ottochain/v1/common_pb.d.ts +86 -0
- package/dist/generated/ottochain/v1/common_pb.js +37 -0
- package/dist/generated/ottochain/v1/fiber_pb.d.ts +292 -0
- package/dist/generated/ottochain/v1/fiber_pb.js +86 -0
- package/dist/generated/ottochain/v1/messages_pb.d.ts +190 -0
- package/dist/generated/ottochain/v1/messages_pb.js +44 -0
- package/dist/generated/ottochain/v1/records_pb.d.ts +221 -0
- package/dist/generated/ottochain/v1/records_pb.js +44 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +77 -0
- package/dist/metakit/binary.d.ts +38 -0
- package/dist/metakit/binary.js +58 -0
- package/dist/metakit/canonicalize.d.ts +26 -0
- package/dist/metakit/canonicalize.js +40 -0
- package/dist/metakit/codec.d.ts +16 -0
- package/dist/metakit/codec.js +45 -0
- package/dist/metakit/currency-transaction.d.ts +157 -0
- package/dist/metakit/currency-transaction.js +319 -0
- package/dist/metakit/currency-types.d.ts +55 -0
- package/dist/metakit/currency-types.js +13 -0
- package/dist/metakit/hash.d.ts +50 -0
- package/dist/metakit/hash.js +84 -0
- package/dist/metakit/index.d.ts +23 -0
- package/dist/metakit/index.js +74 -0
- package/dist/metakit/network/client.d.ts +23 -0
- package/dist/metakit/network/client.js +78 -0
- package/dist/metakit/network/currency-l1-client.d.ts +71 -0
- package/dist/metakit/network/currency-l1-client.js +101 -0
- package/dist/metakit/network/data-l1-client.d.ts +57 -0
- package/dist/metakit/network/data-l1-client.js +76 -0
- package/dist/metakit/network/index.d.ts +10 -0
- package/dist/metakit/network/index.js +16 -0
- package/dist/metakit/network/types.d.ts +74 -0
- package/dist/metakit/network/types.js +20 -0
- package/dist/metakit/sign.d.ts +65 -0
- package/dist/metakit/sign.js +120 -0
- package/dist/metakit/signed-object.d.ts +66 -0
- package/dist/metakit/signed-object.js +100 -0
- package/dist/metakit/types.d.ts +67 -0
- package/dist/metakit/types.js +14 -0
- package/dist/metakit/verify.d.ts +55 -0
- package/dist/metakit/verify.js +217 -0
- package/dist/metakit/wallet.d.ts +70 -0
- package/dist/metakit/wallet.js +127 -0
- package/dist/ottochain/index.d.ts +13 -0
- package/dist/ottochain/index.js +45 -0
- package/dist/ottochain/metagraph-client.d.ts +111 -0
- package/dist/ottochain/metagraph-client.js +157 -0
- package/dist/ottochain/snapshot.d.ts +86 -0
- package/dist/ottochain/snapshot.js +110 -0
- package/dist/ottochain/types.d.ts +278 -0
- package/dist/ottochain/types.js +11 -0
- package/dist/types/apps/contracts/index.d.ts +30 -0
- package/dist/types/apps/contracts/types.d.ts +24 -0
- package/dist/types/apps/corporate/index.d.ts +27 -0
- package/dist/types/apps/corporate/types.d.ts +9861 -0
- package/dist/types/apps/governance/index.d.ts +77 -0
- package/dist/types/apps/governance/types.d.ts +344 -0
- package/dist/types/apps/identity/constants.d.ts +27 -0
- package/dist/types/apps/identity/index.d.ts +39 -0
- package/dist/types/apps/identity/types.d.ts +30 -0
- package/dist/types/apps/index.d.ts +31 -0
- package/dist/types/apps/markets/index.d.ts +26 -0
- package/dist/types/apps/markets/types.d.ts +155 -0
- package/dist/types/apps/oracles/index.d.ts +34 -0
- package/dist/types/apps/oracles/types.d.ts +193 -0
- package/dist/types/errors.d.ts +221 -0
- package/dist/types/generated/google/protobuf/struct.d.ts +134 -0
- package/dist/types/generated/google/protobuf/timestamp.d.ts +134 -0
- package/dist/types/generated/index.d.ts +18 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +112 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate.d.ts +376 -0
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +1172 -0
- package/dist/types/generated/ottochain/apps/governance/v1/governance.d.ts +296 -0
- package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +772 -0
- package/dist/types/generated/ottochain/apps/identity/v1/agent.d.ts +94 -0
- package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
- package/dist/types/generated/ottochain/apps/identity/v1/attestation.d.ts +102 -0
- package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
- package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +174 -0
- package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle.d.ts +150 -0
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
- package/dist/types/generated/ottochain/v1/common.d.ts +1 -0
- package/dist/types/generated/ottochain/v1/common_pb.d.ts +86 -0
- package/dist/types/generated/ottochain/v1/fiber.d.ts +130 -0
- package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +292 -0
- package/dist/types/generated/ottochain/v1/messages.d.ts +89 -0
- package/dist/types/generated/ottochain/v1/messages_pb.d.ts +190 -0
- package/dist/types/generated/ottochain/v1/records.d.ts +128 -0
- package/dist/types/generated/ottochain/v1/records_pb.d.ts +221 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/metakit/binary.d.ts +38 -0
- package/dist/types/metakit/canonicalize.d.ts +26 -0
- package/dist/types/metakit/codec.d.ts +16 -0
- package/dist/types/metakit/currency-transaction.d.ts +157 -0
- package/dist/types/metakit/currency-types.d.ts +55 -0
- package/dist/types/metakit/hash.d.ts +50 -0
- package/dist/types/metakit/index.d.ts +23 -0
- package/dist/types/metakit/network/client.d.ts +23 -0
- package/dist/types/metakit/network/currency-l1-client.d.ts +71 -0
- package/dist/types/metakit/network/data-l1-client.d.ts +57 -0
- package/dist/types/metakit/network/index.d.ts +10 -0
- package/dist/types/metakit/network/types.d.ts +74 -0
- package/dist/types/metakit/sign.d.ts +65 -0
- package/dist/types/metakit/signed-object.d.ts +66 -0
- package/dist/types/metakit/types.d.ts +67 -0
- package/dist/types/metakit/verify.d.ts +55 -0
- package/dist/types/metakit/wallet.d.ts +70 -0
- package/dist/types/ottochain/index.d.ts +13 -0
- package/dist/types/ottochain/metagraph-client.d.ts +111 -0
- package/dist/types/ottochain/snapshot.d.ts +86 -0
- package/dist/types/ottochain/types.d.ts +210 -0
- package/dist/types/types.d.ts +51 -0
- package/dist/types/validation.d.ts +449 -0
- package/dist/validation.d.ts +449 -0
- package/dist/validation.js +312 -0
- package/package.json +136 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Signature Verification
|
|
4
|
+
*
|
|
5
|
+
* Verify ECDSA signatures using secp256k1 curve via dag4js.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.normalizeSignatureToLowS = exports.verifySignature = exports.verifyHash = exports.verify = void 0;
|
|
9
|
+
const dag4_1 = require("@stardust-collective/dag4");
|
|
10
|
+
const js_sha256_1 = require("js-sha256");
|
|
11
|
+
const binary_js_1 = require("./binary.js");
|
|
12
|
+
// secp256k1 curve order (n) for signature normalization
|
|
13
|
+
const SECP256K1_N = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141');
|
|
14
|
+
const SECP256K1_HALF_N = SECP256K1_N / 2n;
|
|
15
|
+
/**
|
|
16
|
+
* Verify a signed object
|
|
17
|
+
*
|
|
18
|
+
* @param signed - Signed object with value and proofs
|
|
19
|
+
* @param isDataUpdate - Whether the value was signed as a DataUpdate
|
|
20
|
+
* @returns VerificationResult with valid/invalid proof lists
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const result = await verify(signedObject);
|
|
25
|
+
* if (result.isValid) {
|
|
26
|
+
* console.log('All signatures valid');
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
async function verify(signed, isDataUpdate = false) {
|
|
31
|
+
// Compute the hash that should have been signed
|
|
32
|
+
const bytes = (0, binary_js_1.toBytes)(signed.value, isDataUpdate);
|
|
33
|
+
const hashHex = js_sha256_1.sha256.hex(bytes);
|
|
34
|
+
const validProofs = [];
|
|
35
|
+
const invalidProofs = [];
|
|
36
|
+
for (const proof of signed.proofs) {
|
|
37
|
+
try {
|
|
38
|
+
const isValid = await verifyHash(hashHex, proof.signature, proof.id);
|
|
39
|
+
if (isValid) {
|
|
40
|
+
validProofs.push(proof);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
invalidProofs.push(proof);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Verification error = invalid
|
|
48
|
+
invalidProofs.push(proof);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
isValid: invalidProofs.length === 0 && validProofs.length > 0,
|
|
53
|
+
validProofs,
|
|
54
|
+
invalidProofs,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.verify = verify;
|
|
58
|
+
/**
|
|
59
|
+
* Verify a signature against a SHA-256 hash
|
|
60
|
+
*
|
|
61
|
+
* Protocol:
|
|
62
|
+
* 1. Treat hash hex as UTF-8 bytes (NOT hex decode)
|
|
63
|
+
* 2. SHA-512 hash
|
|
64
|
+
* 3. Truncate to 32 bytes (handled internally by dag4)
|
|
65
|
+
* 4. Verify ECDSA signature
|
|
66
|
+
*
|
|
67
|
+
* @param hashHex - SHA-256 hash as 64-character hex string
|
|
68
|
+
* @param signature - DER-encoded signature in hex format
|
|
69
|
+
* @param publicKeyId - Public key in hex (with or without 04 prefix)
|
|
70
|
+
* @returns true if signature is valid
|
|
71
|
+
*/
|
|
72
|
+
async function verifyHash(hashHex, signature, publicKeyId) {
|
|
73
|
+
try {
|
|
74
|
+
// Normalize public key (add 04 prefix if needed)
|
|
75
|
+
const fullPublicKey = normalizePublicKey(publicKeyId);
|
|
76
|
+
// Normalize signature to low-S form for BIP 62/146 compatibility
|
|
77
|
+
// Some signing implementations produce high-S signatures which are
|
|
78
|
+
// mathematically valid but rejected by strict implementations
|
|
79
|
+
const normalizedSignature = normalizeSignatureToLowS(signature);
|
|
80
|
+
// Use dag4's verify which handles:
|
|
81
|
+
// 1. SHA-512 of hashHex (treating as UTF-8)
|
|
82
|
+
// 2. Internal truncation to 32 bytes
|
|
83
|
+
// 3. ECDSA verification
|
|
84
|
+
return dag4_1.dag4.keyStore.verify(fullPublicKey, hashHex, normalizedSignature);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.verifyHash = verifyHash;
|
|
91
|
+
/**
|
|
92
|
+
* Verify a single signature proof against data
|
|
93
|
+
*
|
|
94
|
+
* @param data - The original data that was signed
|
|
95
|
+
* @param proof - The signature proof to verify
|
|
96
|
+
* @param isDataUpdate - Whether data was signed as DataUpdate
|
|
97
|
+
* @returns true if signature is valid
|
|
98
|
+
*/
|
|
99
|
+
async function verifySignature(data, proof, isDataUpdate = false) {
|
|
100
|
+
const bytes = (0, binary_js_1.toBytes)(data, isDataUpdate);
|
|
101
|
+
const hashHex = js_sha256_1.sha256.hex(bytes);
|
|
102
|
+
return verifyHash(hashHex, proof.signature, proof.id);
|
|
103
|
+
}
|
|
104
|
+
exports.verifySignature = verifySignature;
|
|
105
|
+
/**
|
|
106
|
+
* Normalize public key to full format (with 04 prefix)
|
|
107
|
+
*/
|
|
108
|
+
function normalizePublicKey(publicKey) {
|
|
109
|
+
// If 128 chars (without 04 prefix), add prefix
|
|
110
|
+
if (publicKey.length === 128) {
|
|
111
|
+
return '04' + publicKey;
|
|
112
|
+
}
|
|
113
|
+
// If 130 chars (with 04 prefix), return as-is
|
|
114
|
+
if (publicKey.length === 130 && publicKey.startsWith('04')) {
|
|
115
|
+
return publicKey;
|
|
116
|
+
}
|
|
117
|
+
// Otherwise return as-is
|
|
118
|
+
return publicKey;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Normalize a DER-encoded signature to use low-S value.
|
|
122
|
+
*
|
|
123
|
+
* BIP 62/146 requires S values to be in the lower half of the curve order.
|
|
124
|
+
* Some signing implementations produce high-S signatures which are mathematically
|
|
125
|
+
* valid but rejected by strict verifiers. This normalizes high-S to low-S by
|
|
126
|
+
* computing S' = N - S where N is the curve order.
|
|
127
|
+
*/
|
|
128
|
+
function normalizeSignatureToLowS(signatureHex) {
|
|
129
|
+
const bytes = hexToBytes(signatureHex);
|
|
130
|
+
// Parse DER signature: 0x30 <total_len> 0x02 <r_len> <r> 0x02 <s_len> <s>
|
|
131
|
+
if (bytes[0] !== 0x30) {
|
|
132
|
+
return signatureHex; // Not a valid DER signature
|
|
133
|
+
}
|
|
134
|
+
let offset = 2; // Skip 0x30 and total length
|
|
135
|
+
// Parse R
|
|
136
|
+
if (bytes[offset] !== 0x02) {
|
|
137
|
+
return signatureHex;
|
|
138
|
+
}
|
|
139
|
+
const rLen = bytes[offset + 1];
|
|
140
|
+
const rStart = offset + 2;
|
|
141
|
+
const rEnd = rStart + rLen;
|
|
142
|
+
offset = rEnd;
|
|
143
|
+
// Parse S
|
|
144
|
+
if (bytes[offset] !== 0x02) {
|
|
145
|
+
return signatureHex;
|
|
146
|
+
}
|
|
147
|
+
const sLen = bytes[offset + 1];
|
|
148
|
+
const sStart = offset + 2;
|
|
149
|
+
const sEnd = sStart + sLen;
|
|
150
|
+
// Extract S value
|
|
151
|
+
const sBytes = bytes.slice(sStart, sEnd);
|
|
152
|
+
const s = bytesToBigInt(sBytes);
|
|
153
|
+
// Check if S is high (> N/2)
|
|
154
|
+
if (s <= SECP256K1_HALF_N) {
|
|
155
|
+
return signatureHex; // Already low-S
|
|
156
|
+
}
|
|
157
|
+
// Compute low-S: S' = N - S
|
|
158
|
+
const lowS = SECP256K1_N - s;
|
|
159
|
+
const lowSBytes = bigIntToBytes(lowS);
|
|
160
|
+
// Ensure proper DER encoding (no leading zeros unless needed for sign bit)
|
|
161
|
+
const normalizedSBytes = normalizeDerInteger(lowSBytes);
|
|
162
|
+
// Build new signature
|
|
163
|
+
const rBytes = bytes.slice(rStart, rEnd);
|
|
164
|
+
const normalizedRBytes = normalizeDerInteger(rBytes);
|
|
165
|
+
const newSigContent = new Uint8Array([
|
|
166
|
+
0x02,
|
|
167
|
+
normalizedRBytes.length,
|
|
168
|
+
...normalizedRBytes,
|
|
169
|
+
0x02,
|
|
170
|
+
normalizedSBytes.length,
|
|
171
|
+
...normalizedSBytes,
|
|
172
|
+
]);
|
|
173
|
+
const newSig = new Uint8Array([0x30, newSigContent.length, ...newSigContent]);
|
|
174
|
+
return bytesToHex(newSig);
|
|
175
|
+
}
|
|
176
|
+
exports.normalizeSignatureToLowS = normalizeSignatureToLowS;
|
|
177
|
+
/**
|
|
178
|
+
* Normalize a byte array for DER integer encoding
|
|
179
|
+
*/
|
|
180
|
+
function normalizeDerInteger(bytes) {
|
|
181
|
+
// Remove leading zeros, but keep one if the high bit is set
|
|
182
|
+
let start = 0;
|
|
183
|
+
while (start < bytes.length - 1 && bytes[start] === 0 && (bytes[start + 1] & 0x80) === 0) {
|
|
184
|
+
start++;
|
|
185
|
+
}
|
|
186
|
+
// Add leading zero if high bit is set (to indicate positive number)
|
|
187
|
+
if (bytes[start] & 0x80) {
|
|
188
|
+
const result = new Uint8Array(bytes.length - start + 1);
|
|
189
|
+
result[0] = 0;
|
|
190
|
+
result.set(bytes.slice(start), 1);
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
return bytes.slice(start);
|
|
194
|
+
}
|
|
195
|
+
function hexToBytes(hex) {
|
|
196
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
197
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
198
|
+
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
199
|
+
}
|
|
200
|
+
return bytes;
|
|
201
|
+
}
|
|
202
|
+
function bytesToHex(bytes) {
|
|
203
|
+
return Array.from(bytes)
|
|
204
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
205
|
+
.join('');
|
|
206
|
+
}
|
|
207
|
+
function bytesToBigInt(bytes) {
|
|
208
|
+
let result = 0n;
|
|
209
|
+
for (const byte of bytes) {
|
|
210
|
+
result = (result << 8n) | BigInt(byte);
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
function bigIntToBytes(n) {
|
|
215
|
+
const hex = n.toString(16).padStart(64, '0'); // 32 bytes = 64 hex chars
|
|
216
|
+
return hexToBytes(hex);
|
|
217
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet and Key Management Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for generating and managing cryptographic keys.
|
|
5
|
+
*/
|
|
6
|
+
import { KeyPair } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generate a new random key pair
|
|
9
|
+
*
|
|
10
|
+
* @returns KeyPair with private key, public key, and DAG address
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const keyPair = generateKeyPair();
|
|
15
|
+
* console.log(keyPair.address); // DAG address
|
|
16
|
+
* console.log(keyPair.privateKey); // 64 char hex
|
|
17
|
+
* console.log(keyPair.publicKey); // 130 char hex (with 04 prefix)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateKeyPair(): KeyPair;
|
|
21
|
+
/**
|
|
22
|
+
* Derive a key pair from an existing private key
|
|
23
|
+
*
|
|
24
|
+
* @param privateKey - Private key in hex format (64 characters)
|
|
25
|
+
* @returns KeyPair with private key, public key, and DAG address
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const keyPair = keyPairFromPrivateKey(existingPrivateKey);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function keyPairFromPrivateKey(privateKey: string): KeyPair;
|
|
33
|
+
/**
|
|
34
|
+
* Get the public key hex from a private key
|
|
35
|
+
*
|
|
36
|
+
* @param privateKey - Private key in hex format
|
|
37
|
+
* @param compressed - If true, returns compressed public key (33 bytes)
|
|
38
|
+
* @returns Public key in hex format
|
|
39
|
+
*/
|
|
40
|
+
export declare function getPublicKeyHex(privateKey: string, compressed?: boolean): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get the public key ID (without 04 prefix) from a private key
|
|
43
|
+
*
|
|
44
|
+
* This format is used in SignatureProof.id
|
|
45
|
+
*
|
|
46
|
+
* @param privateKey - Private key in hex format
|
|
47
|
+
* @returns Public key ID (128 characters, no 04 prefix)
|
|
48
|
+
*/
|
|
49
|
+
export declare function getPublicKeyId(privateKey: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Get DAG address from a public key
|
|
52
|
+
*
|
|
53
|
+
* @param publicKey - Public key in hex format (with or without 04 prefix)
|
|
54
|
+
* @returns DAG address string
|
|
55
|
+
*/
|
|
56
|
+
export declare function getAddress(publicKey: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Validate that a private key is correctly formatted
|
|
59
|
+
*
|
|
60
|
+
* @param privateKey - Private key to validate
|
|
61
|
+
* @returns true if valid hex string of correct length
|
|
62
|
+
*/
|
|
63
|
+
export declare function isValidPrivateKey(privateKey: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Validate that a public key is correctly formatted
|
|
66
|
+
*
|
|
67
|
+
* @param publicKey - Public key to validate
|
|
68
|
+
* @returns true if valid hex string of correct length
|
|
69
|
+
*/
|
|
70
|
+
export declare function isValidPublicKey(publicKey: string): boolean;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wallet and Key Management Utilities
|
|
4
|
+
*
|
|
5
|
+
* Functions for generating and managing cryptographic keys.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isValidPublicKey = exports.isValidPrivateKey = exports.getAddress = exports.getPublicKeyId = exports.getPublicKeyHex = exports.keyPairFromPrivateKey = exports.generateKeyPair = void 0;
|
|
9
|
+
const dag4_1 = require("@stardust-collective/dag4");
|
|
10
|
+
/**
|
|
11
|
+
* Generate a new random key pair
|
|
12
|
+
*
|
|
13
|
+
* @returns KeyPair with private key, public key, and DAG address
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const keyPair = generateKeyPair();
|
|
18
|
+
* console.log(keyPair.address); // DAG address
|
|
19
|
+
* console.log(keyPair.privateKey); // 64 char hex
|
|
20
|
+
* console.log(keyPair.publicKey); // 130 char hex (with 04 prefix)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function generateKeyPair() {
|
|
24
|
+
const privateKey = dag4_1.dag4.keyStore.generatePrivateKey();
|
|
25
|
+
return keyPairFromPrivateKey(privateKey);
|
|
26
|
+
}
|
|
27
|
+
exports.generateKeyPair = generateKeyPair;
|
|
28
|
+
/**
|
|
29
|
+
* Derive a key pair from an existing private key
|
|
30
|
+
*
|
|
31
|
+
* @param privateKey - Private key in hex format (64 characters)
|
|
32
|
+
* @returns KeyPair with private key, public key, and DAG address
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const keyPair = keyPairFromPrivateKey(existingPrivateKey);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function keyPairFromPrivateKey(privateKey) {
|
|
40
|
+
// Get uncompressed public key (with 04 prefix)
|
|
41
|
+
const publicKey = dag4_1.dag4.keyStore.getPublicKeyFromPrivate(privateKey, false);
|
|
42
|
+
// Derive DAG address
|
|
43
|
+
const address = dag4_1.dag4.keyStore.getDagAddressFromPublicKey(publicKey);
|
|
44
|
+
return {
|
|
45
|
+
privateKey,
|
|
46
|
+
publicKey: normalizePublicKey(publicKey),
|
|
47
|
+
address,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.keyPairFromPrivateKey = keyPairFromPrivateKey;
|
|
51
|
+
/**
|
|
52
|
+
* Get the public key hex from a private key
|
|
53
|
+
*
|
|
54
|
+
* @param privateKey - Private key in hex format
|
|
55
|
+
* @param compressed - If true, returns compressed public key (33 bytes)
|
|
56
|
+
* @returns Public key in hex format
|
|
57
|
+
*/
|
|
58
|
+
function getPublicKeyHex(privateKey, compressed = false) {
|
|
59
|
+
return dag4_1.dag4.keyStore.getPublicKeyFromPrivate(privateKey, compressed);
|
|
60
|
+
}
|
|
61
|
+
exports.getPublicKeyHex = getPublicKeyHex;
|
|
62
|
+
/**
|
|
63
|
+
* Get the public key ID (without 04 prefix) from a private key
|
|
64
|
+
*
|
|
65
|
+
* This format is used in SignatureProof.id
|
|
66
|
+
*
|
|
67
|
+
* @param privateKey - Private key in hex format
|
|
68
|
+
* @returns Public key ID (128 characters, no 04 prefix)
|
|
69
|
+
*/
|
|
70
|
+
function getPublicKeyId(privateKey) {
|
|
71
|
+
const publicKey = dag4_1.dag4.keyStore.getPublicKeyFromPrivate(privateKey, false);
|
|
72
|
+
// Remove 04 prefix if present
|
|
73
|
+
if (publicKey.length === 130 && publicKey.startsWith('04')) {
|
|
74
|
+
return publicKey.substring(2);
|
|
75
|
+
}
|
|
76
|
+
return publicKey;
|
|
77
|
+
}
|
|
78
|
+
exports.getPublicKeyId = getPublicKeyId;
|
|
79
|
+
/**
|
|
80
|
+
* Get DAG address from a public key
|
|
81
|
+
*
|
|
82
|
+
* @param publicKey - Public key in hex format (with or without 04 prefix)
|
|
83
|
+
* @returns DAG address string
|
|
84
|
+
*/
|
|
85
|
+
function getAddress(publicKey) {
|
|
86
|
+
const normalizedKey = normalizePublicKey(publicKey);
|
|
87
|
+
return dag4_1.dag4.keyStore.getDagAddressFromPublicKey(normalizedKey);
|
|
88
|
+
}
|
|
89
|
+
exports.getAddress = getAddress;
|
|
90
|
+
/**
|
|
91
|
+
* Validate that a private key is correctly formatted
|
|
92
|
+
*
|
|
93
|
+
* @param privateKey - Private key to validate
|
|
94
|
+
* @returns true if valid hex string of correct length
|
|
95
|
+
*/
|
|
96
|
+
function isValidPrivateKey(privateKey) {
|
|
97
|
+
if (typeof privateKey !== 'string')
|
|
98
|
+
return false;
|
|
99
|
+
if (privateKey.length !== 64)
|
|
100
|
+
return false;
|
|
101
|
+
return /^[0-9a-fA-F]+$/.test(privateKey);
|
|
102
|
+
}
|
|
103
|
+
exports.isValidPrivateKey = isValidPrivateKey;
|
|
104
|
+
/**
|
|
105
|
+
* Validate that a public key is correctly formatted
|
|
106
|
+
*
|
|
107
|
+
* @param publicKey - Public key to validate
|
|
108
|
+
* @returns true if valid hex string of correct length
|
|
109
|
+
*/
|
|
110
|
+
function isValidPublicKey(publicKey) {
|
|
111
|
+
if (typeof publicKey !== 'string')
|
|
112
|
+
return false;
|
|
113
|
+
// With 04 prefix: 130 chars, without: 128 chars
|
|
114
|
+
if (publicKey.length !== 128 && publicKey.length !== 130)
|
|
115
|
+
return false;
|
|
116
|
+
return /^[0-9a-fA-F]+$/.test(publicKey);
|
|
117
|
+
}
|
|
118
|
+
exports.isValidPublicKey = isValidPublicKey;
|
|
119
|
+
/**
|
|
120
|
+
* Normalize public key to include 04 prefix
|
|
121
|
+
*/
|
|
122
|
+
function normalizePublicKey(publicKey) {
|
|
123
|
+
if (publicKey.length === 128) {
|
|
124
|
+
return '04' + publicKey;
|
|
125
|
+
}
|
|
126
|
+
return publicKey;
|
|
127
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ottochain SDK
|
|
3
|
+
*
|
|
4
|
+
* Domain-specific types and clients for the ottochain metagraph.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export * as proto from '../generated/index.js';
|
|
9
|
+
export type { FiberOrdinal, SnapshotOrdinal, StateId, Address, HashValue, JsonLogicValue, JsonLogicExpression, FiberStatus, AccessControlPolicy, StateMachineDefinition, EmittedEvent, EventReceipt, OracleInvocation, FiberLogEntry, StateMachineFiberRecord, ScriptFiberRecord, FiberRecord, FiberCommit, OnChain, CalculatedState, CreateStateMachine, TransitionStateMachine, ArchiveStateMachine, CreateScript, InvokeScript, OttochainMessage, } from './types.js';
|
|
10
|
+
export type { CurrencySnapshotResponse } from './snapshot.js';
|
|
11
|
+
export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
|
|
12
|
+
export type { Checkpoint, MetagraphClientConfig } from './metagraph-client.js';
|
|
13
|
+
export { MetagraphClient } from './metagraph-client.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ottochain SDK
|
|
4
|
+
*
|
|
5
|
+
* Domain-specific types and clients for the ottochain metagraph.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.MetagraphClient = exports.extractOnChainState = exports.getScriptInvocations = exports.getEventReceipts = exports.getLogsForFiber = exports.getLatestOnChainState = exports.getSnapshotOnChainState = exports.decodeOnChainState = exports.proto = void 0;
|
|
34
|
+
// Re-export generated protobuf types
|
|
35
|
+
exports.proto = __importStar(require("../generated/index.js"));
|
|
36
|
+
var snapshot_js_1 = require("./snapshot.js");
|
|
37
|
+
Object.defineProperty(exports, "decodeOnChainState", { enumerable: true, get: function () { return snapshot_js_1.decodeOnChainState; } });
|
|
38
|
+
Object.defineProperty(exports, "getSnapshotOnChainState", { enumerable: true, get: function () { return snapshot_js_1.getSnapshotOnChainState; } });
|
|
39
|
+
Object.defineProperty(exports, "getLatestOnChainState", { enumerable: true, get: function () { return snapshot_js_1.getLatestOnChainState; } });
|
|
40
|
+
Object.defineProperty(exports, "getLogsForFiber", { enumerable: true, get: function () { return snapshot_js_1.getLogsForFiber; } });
|
|
41
|
+
Object.defineProperty(exports, "getEventReceipts", { enumerable: true, get: function () { return snapshot_js_1.getEventReceipts; } });
|
|
42
|
+
Object.defineProperty(exports, "getScriptInvocations", { enumerable: true, get: function () { return snapshot_js_1.getScriptInvocations; } });
|
|
43
|
+
Object.defineProperty(exports, "extractOnChainState", { enumerable: true, get: function () { return snapshot_js_1.extractOnChainState; } });
|
|
44
|
+
var metagraph_client_js_1 = require("./metagraph-client.js");
|
|
45
|
+
Object.defineProperty(exports, "MetagraphClient", { enumerable: true, get: function () { return metagraph_client_js_1.MetagraphClient; } });
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ottochain Metagraph Client
|
|
3
|
+
*
|
|
4
|
+
* Client for interacting with ottochain ML0 custom routes (/v1 prefix)
|
|
5
|
+
* and framework snapshot endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/ML0CustomRoutes.scala
|
|
8
|
+
* @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { OnChain, CalculatedState, StateMachineFiberRecord, ScriptFiberRecord, EventReceipt, OracleInvocation, FiberStatus } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Checkpoint response from the metagraph (ordinal + calculated state).
|
|
14
|
+
*/
|
|
15
|
+
export interface Checkpoint {
|
|
16
|
+
ordinal: number;
|
|
17
|
+
state: CalculatedState;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for the MetagraphClient.
|
|
21
|
+
*/
|
|
22
|
+
export interface MetagraphClientConfig {
|
|
23
|
+
/** ML0 node base URL (e.g., 'http://localhost:9200') */
|
|
24
|
+
ml0Url: string;
|
|
25
|
+
/** DL1 node base URL for data submission (e.g., 'http://localhost:9400') */
|
|
26
|
+
dl1Url?: string;
|
|
27
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Client for ottochain metagraph operations.
|
|
32
|
+
*
|
|
33
|
+
* Provides typed access to all ML0 custom routes (under /data-application/v1/)
|
|
34
|
+
* and framework snapshot endpoints.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = new MetagraphClient({
|
|
39
|
+
* ml0Url: 'http://localhost:9200',
|
|
40
|
+
* dl1Url: 'http://localhost:9400',
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Query on-chain state
|
|
44
|
+
* const onChain = await client.getOnChain();
|
|
45
|
+
*
|
|
46
|
+
* // Get all active state machines
|
|
47
|
+
* const machines = await client.getStateMachines('Active');
|
|
48
|
+
*
|
|
49
|
+
* // Get event receipts for a fiber
|
|
50
|
+
* const events = await client.getStateMachineEvents(fiberId);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class MetagraphClient {
|
|
54
|
+
private ml0;
|
|
55
|
+
private dl1?;
|
|
56
|
+
constructor(config: MetagraphClientConfig);
|
|
57
|
+
/**
|
|
58
|
+
* Get the current on-chain state (directly from L0 context).
|
|
59
|
+
*/
|
|
60
|
+
getOnChain(): Promise<OnChain>;
|
|
61
|
+
/**
|
|
62
|
+
* Get the latest checkpoint (ordinal + calculated state).
|
|
63
|
+
*/
|
|
64
|
+
getCheckpoint(): Promise<Checkpoint>;
|
|
65
|
+
/**
|
|
66
|
+
* Get all state machines, optionally filtered by status.
|
|
67
|
+
*/
|
|
68
|
+
getStateMachines(status?: FiberStatus): Promise<Record<string, StateMachineFiberRecord>>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a single state machine by fiber ID.
|
|
71
|
+
*/
|
|
72
|
+
getStateMachine(fiberId: string): Promise<StateMachineFiberRecord | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Get event receipts for a state machine from the current ordinal's logs.
|
|
75
|
+
*/
|
|
76
|
+
getStateMachineEvents(fiberId: string): Promise<EventReceipt[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Get all script oracles, optionally filtered by status.
|
|
79
|
+
*/
|
|
80
|
+
getScripts(status?: FiberStatus): Promise<Record<string, ScriptFiberRecord>>;
|
|
81
|
+
/**
|
|
82
|
+
* Get a single script oracle by fiber ID.
|
|
83
|
+
*/
|
|
84
|
+
getScript(scriptId: string): Promise<ScriptFiberRecord | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Get oracle invocations from the current ordinal's logs.
|
|
87
|
+
*/
|
|
88
|
+
getScriptInvocations(scriptId: string): Promise<OracleInvocation[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Get the latest snapshot and decode its on-chain state.
|
|
91
|
+
*/
|
|
92
|
+
getLatestSnapshotOnChainState(): Promise<OnChain | null>;
|
|
93
|
+
/**
|
|
94
|
+
* Get a snapshot by ordinal and decode its on-chain state.
|
|
95
|
+
*/
|
|
96
|
+
getSnapshotOnChainState(ordinal: number): Promise<OnChain | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Get the latest snapshot ordinal.
|
|
99
|
+
*/
|
|
100
|
+
getLatestOrdinal(): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Submit a signed data update to the DL1 node.
|
|
103
|
+
* The POST /data endpoint is framework-provided (no /v1 prefix).
|
|
104
|
+
*
|
|
105
|
+
* @param signedData - Signed OttochainMessage
|
|
106
|
+
* @returns Response hash
|
|
107
|
+
*/
|
|
108
|
+
postData<T>(signedData: T): Promise<{
|
|
109
|
+
hash: string;
|
|
110
|
+
}>;
|
|
111
|
+
}
|