@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,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core type definitions for the Ottochain SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CONSTELLATION_PREFIX = exports.ALGORITHM = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Supported signature algorithm
|
|
9
|
+
*/
|
|
10
|
+
exports.ALGORITHM = 'SECP256K1_RFC8785_V1';
|
|
11
|
+
/**
|
|
12
|
+
* Constellation prefix for DataUpdate signing
|
|
13
|
+
*/
|
|
14
|
+
exports.CONSTELLATION_PREFIX = '\x19Constellation Signed Data:\n';
|
|
@@ -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,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,47 @@
|
|
|
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 (for binary encoding)
|
|
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; } });
|
|
46
|
+
// Note: Governance and Corporate types are now in src/apps/
|
|
47
|
+
// Import from '@ottochain/sdk/apps' instead
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ottochain Metagraph Client
|
|
4
|
+
*
|
|
5
|
+
* Client for interacting with ottochain ML0 custom routes (/v1 prefix)
|
|
6
|
+
* and framework snapshot endpoints.
|
|
7
|
+
*
|
|
8
|
+
* @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/ML0CustomRoutes.scala
|
|
9
|
+
* @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.MetagraphClient = void 0;
|
|
14
|
+
const client_js_1 = require("../metakit/network/client.js");
|
|
15
|
+
const types_js_1 = require("../metakit/network/types.js");
|
|
16
|
+
const snapshot_js_1 = require("./snapshot.js");
|
|
17
|
+
/**
|
|
18
|
+
* Client for ottochain metagraph operations.
|
|
19
|
+
*
|
|
20
|
+
* Provides typed access to all ML0 custom routes (under /data-application/v1/)
|
|
21
|
+
* and framework snapshot endpoints.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const client = new MetagraphClient({
|
|
26
|
+
* ml0Url: 'http://localhost:9200',
|
|
27
|
+
* dl1Url: 'http://localhost:9400',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Query on-chain state
|
|
31
|
+
* const onChain = await client.getOnChain();
|
|
32
|
+
*
|
|
33
|
+
* // Get all active state machines
|
|
34
|
+
* const machines = await client.getStateMachines('Active');
|
|
35
|
+
*
|
|
36
|
+
* // Get event receipts for a fiber
|
|
37
|
+
* const events = await client.getStateMachineEvents(fiberId);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class MetagraphClient {
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.ml0 = new client_js_1.HttpClient(config.ml0Url, config.timeout);
|
|
43
|
+
if (config.dl1Url) {
|
|
44
|
+
this.dl1 = new client_js_1.HttpClient(config.dl1Url, config.timeout);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// -------------------------------------------------------------------------
|
|
48
|
+
// Custom routes (ML0 /data-application/v1/*)
|
|
49
|
+
// -------------------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Get the current on-chain state (directly from L0 context).
|
|
52
|
+
*/
|
|
53
|
+
async getOnChain() {
|
|
54
|
+
return this.ml0.get('/data-application/v1/onchain');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the latest checkpoint (ordinal + calculated state).
|
|
58
|
+
*/
|
|
59
|
+
async getCheckpoint() {
|
|
60
|
+
return this.ml0.get('/data-application/v1/checkpoint');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get all state machines, optionally filtered by status.
|
|
64
|
+
*/
|
|
65
|
+
async getStateMachines(status) {
|
|
66
|
+
const query = status ? `?status=${status}` : '';
|
|
67
|
+
return this.ml0.get(`/data-application/v1/state-machines${query}`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get a single state machine by fiber ID.
|
|
71
|
+
*/
|
|
72
|
+
async getStateMachine(fiberId) {
|
|
73
|
+
try {
|
|
74
|
+
return await this.ml0.get(`/data-application/v1/state-machines/${fiberId}`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof types_js_1.NetworkError && error.statusCode === 404) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get event receipts for a state machine from the current ordinal's logs.
|
|
85
|
+
*/
|
|
86
|
+
async getStateMachineEvents(fiberId) {
|
|
87
|
+
return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/events`);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get all script oracles, optionally filtered by status.
|
|
91
|
+
*/
|
|
92
|
+
async getScripts(status) {
|
|
93
|
+
const query = status ? `?status=${status}` : '';
|
|
94
|
+
return this.ml0.get(`/data-application/v1/oracles${query}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a single script oracle by fiber ID.
|
|
98
|
+
*/
|
|
99
|
+
async getScript(scriptId) {
|
|
100
|
+
try {
|
|
101
|
+
return await this.ml0.get(`/data-application/v1/oracles/${scriptId}`);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof types_js_1.NetworkError && error.statusCode === 404) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get oracle invocations from the current ordinal's logs.
|
|
112
|
+
*/
|
|
113
|
+
async getScriptInvocations(scriptId) {
|
|
114
|
+
return this.ml0.get(`/data-application/v1/oracles/${scriptId}/invocations`);
|
|
115
|
+
}
|
|
116
|
+
// -------------------------------------------------------------------------
|
|
117
|
+
// Framework snapshot endpoints (ML0 /snapshots/*)
|
|
118
|
+
// -------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* Get the latest snapshot and decode its on-chain state.
|
|
121
|
+
*/
|
|
122
|
+
async getLatestSnapshotOnChainState() {
|
|
123
|
+
const snapshot = await this.ml0.get('/snapshots/latest');
|
|
124
|
+
return (0, snapshot_js_1.extractOnChainState)(snapshot);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a snapshot by ordinal and decode its on-chain state.
|
|
128
|
+
*/
|
|
129
|
+
async getSnapshotOnChainState(ordinal) {
|
|
130
|
+
const snapshot = await this.ml0.get(`/snapshots/${ordinal}`);
|
|
131
|
+
return (0, snapshot_js_1.extractOnChainState)(snapshot);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the latest snapshot ordinal.
|
|
135
|
+
*/
|
|
136
|
+
async getLatestOrdinal() {
|
|
137
|
+
const snapshot = await this.ml0.get('/snapshots/latest');
|
|
138
|
+
return snapshot.value.ordinal;
|
|
139
|
+
}
|
|
140
|
+
// -------------------------------------------------------------------------
|
|
141
|
+
// DL1 data submission (framework POST /data)
|
|
142
|
+
// -------------------------------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* Submit a signed data update to the DL1 node.
|
|
145
|
+
* The POST /data endpoint is framework-provided (no /v1 prefix).
|
|
146
|
+
*
|
|
147
|
+
* @param signedData - Signed OttochainMessage
|
|
148
|
+
* @returns Response hash
|
|
149
|
+
*/
|
|
150
|
+
async postData(signedData) {
|
|
151
|
+
if (!this.dl1) {
|
|
152
|
+
throw new Error('dl1Url is required for postData');
|
|
153
|
+
}
|
|
154
|
+
return this.dl1.post('/data', signedData);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.MetagraphClient = MetagraphClient;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Snapshot decoder for ottochain on-chain state
|
|
4
|
+
*
|
|
5
|
+
* Fetches currency incremental snapshots from metagraph L0 and decodes the
|
|
6
|
+
* on-chain state from the DataApplicationPart's binary payload.
|
|
7
|
+
*
|
|
8
|
+
* The on-chain state is serialized using JsonBinaryCodec (canonical JSON → UTF-8 bytes).
|
|
9
|
+
*
|
|
10
|
+
* @see modules/models/src/main/scala/xyz/kd5ujc/schema/OnChain.scala
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getScriptInvocations = exports.getEventReceipts = exports.getLogsForFiber = exports.extractOnChainState = exports.getLatestOnChainState = exports.getSnapshotOnChainState = exports.decodeOnChainState = void 0;
|
|
15
|
+
const client_js_1 = require("../metakit/network/client.js");
|
|
16
|
+
/**
|
|
17
|
+
* Decode on-chain state from binary (JsonBinaryCodec format).
|
|
18
|
+
*
|
|
19
|
+
* JsonBinaryCodec serialization is: canonical JSON → UTF-8 bytes.
|
|
20
|
+
* So decoding is simply: UTF-8 bytes → JSON.parse.
|
|
21
|
+
*
|
|
22
|
+
* @param bytes - UTF-8 encoded canonical JSON bytes
|
|
23
|
+
* @returns Decoded OnChain state
|
|
24
|
+
*/
|
|
25
|
+
function decodeOnChainState(bytes) {
|
|
26
|
+
const json = new TextDecoder().decode(bytes);
|
|
27
|
+
return JSON.parse(json);
|
|
28
|
+
}
|
|
29
|
+
exports.decodeOnChainState = decodeOnChainState;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch and decode the on-chain state from a specific snapshot ordinal.
|
|
32
|
+
*
|
|
33
|
+
* @param ml0BaseUrl - Metagraph L0 node base URL (e.g., 'http://localhost:9200')
|
|
34
|
+
* @param ordinal - Snapshot ordinal number
|
|
35
|
+
* @returns Decoded OnChain state, or null if no data application part
|
|
36
|
+
*/
|
|
37
|
+
async function getSnapshotOnChainState(ml0BaseUrl, ordinal) {
|
|
38
|
+
const client = new client_js_1.HttpClient(ml0BaseUrl);
|
|
39
|
+
const snapshot = await client.get(`/snapshots/${ordinal}`);
|
|
40
|
+
return extractOnChainState(snapshot);
|
|
41
|
+
}
|
|
42
|
+
exports.getSnapshotOnChainState = getSnapshotOnChainState;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch and decode the on-chain state from the latest snapshot.
|
|
45
|
+
*
|
|
46
|
+
* @param ml0BaseUrl - Metagraph L0 node base URL (e.g., 'http://localhost:9200')
|
|
47
|
+
* @returns Decoded OnChain state, or null if no data application part
|
|
48
|
+
*/
|
|
49
|
+
async function getLatestOnChainState(ml0BaseUrl) {
|
|
50
|
+
const client = new client_js_1.HttpClient(ml0BaseUrl);
|
|
51
|
+
const snapshot = await client.get('/snapshots/latest');
|
|
52
|
+
return extractOnChainState(snapshot);
|
|
53
|
+
}
|
|
54
|
+
exports.getLatestOnChainState = getLatestOnChainState;
|
|
55
|
+
/**
|
|
56
|
+
* Extract and decode on-chain state from a snapshot response.
|
|
57
|
+
*/
|
|
58
|
+
function extractOnChainState(snapshot) {
|
|
59
|
+
const dataPart = snapshot.value?.dataApplication;
|
|
60
|
+
if (!dataPart?.onChainState) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const bytes = new Uint8Array(dataPart.onChainState);
|
|
64
|
+
return decodeOnChainState(bytes);
|
|
65
|
+
}
|
|
66
|
+
exports.extractOnChainState = extractOnChainState;
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Log filtering helpers
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
/**
|
|
71
|
+
* Get all log entries for a specific fiber from on-chain state.
|
|
72
|
+
*
|
|
73
|
+
* @param onChain - Decoded on-chain state
|
|
74
|
+
* @param fiberId - Fiber UUID to filter by
|
|
75
|
+
* @returns Array of log entries for the fiber, or empty array
|
|
76
|
+
*/
|
|
77
|
+
function getLogsForFiber(onChain, fiberId) {
|
|
78
|
+
return onChain.latestLogs[fiberId] ?? [];
|
|
79
|
+
}
|
|
80
|
+
exports.getLogsForFiber = getLogsForFiber;
|
|
81
|
+
/**
|
|
82
|
+
* Get EventReceipt log entries for a specific fiber.
|
|
83
|
+
*
|
|
84
|
+
* EventReceipts are distinguished from OracleInvocations by the presence
|
|
85
|
+
* of the `eventName` field.
|
|
86
|
+
*
|
|
87
|
+
* @param onChain - Decoded on-chain state
|
|
88
|
+
* @param fiberId - Fiber UUID to filter by
|
|
89
|
+
* @returns Array of EventReceipt entries
|
|
90
|
+
*/
|
|
91
|
+
function getEventReceipts(onChain, fiberId) {
|
|
92
|
+
return getLogsForFiber(onChain, fiberId)
|
|
93
|
+
.filter((entry) => 'eventName' in entry && 'success' in entry);
|
|
94
|
+
}
|
|
95
|
+
exports.getEventReceipts = getEventReceipts;
|
|
96
|
+
/**
|
|
97
|
+
* Get OracleInvocation log entries for a specific fiber.
|
|
98
|
+
*
|
|
99
|
+
* OracleInvocations are distinguished from EventReceipts by the presence
|
|
100
|
+
* of the `method` field.
|
|
101
|
+
*
|
|
102
|
+
* @param onChain - Decoded on-chain state
|
|
103
|
+
* @param fiberId - Fiber UUID to filter by
|
|
104
|
+
* @returns Array of OracleInvocation entries
|
|
105
|
+
*/
|
|
106
|
+
function getScriptInvocations(onChain, fiberId) {
|
|
107
|
+
return getLogsForFiber(onChain, fiberId)
|
|
108
|
+
.filter((entry) => 'method' in entry && 'result' in entry);
|
|
109
|
+
}
|
|
110
|
+
exports.getScriptInvocations = getScriptInvocations;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ottochain-specific type definitions
|
|
4
|
+
*
|
|
5
|
+
* TypeScript interfaces matching the wire format from the Scala metagraph.
|
|
6
|
+
* The JSON Logic engine stores state as plain JSON - no wrapper objects.
|
|
7
|
+
*
|
|
8
|
+
* @see modules/models/src/main/scala/xyz/kd5ujc/schema/
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|