@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,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hashing Utilities
|
|
4
|
+
*
|
|
5
|
+
* SHA-256 and SHA-512 hashing for the Constellation signature protocol.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.hashData = exports.computeDigest = exports.hashBytes = exports.hash = void 0;
|
|
9
|
+
const js_sha256_1 = require("js-sha256");
|
|
10
|
+
const js_sha512_1 = require("js-sha512");
|
|
11
|
+
const binary_js_1 = require("./binary.js");
|
|
12
|
+
/**
|
|
13
|
+
* Compute SHA-256 hash of canonical JSON data
|
|
14
|
+
*
|
|
15
|
+
* @param data - Any JSON-serializable object
|
|
16
|
+
* @returns Hash object with hex string and raw bytes
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const hashResult = hash({ action: 'test' });
|
|
21
|
+
* console.log(hashResult.value); // 64-char hex string
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function hash(data) {
|
|
25
|
+
const bytes = (0, binary_js_1.toBytes)(data, false);
|
|
26
|
+
return hashBytes(bytes);
|
|
27
|
+
}
|
|
28
|
+
exports.hash = hash;
|
|
29
|
+
/**
|
|
30
|
+
* Compute SHA-256 hash of raw bytes
|
|
31
|
+
*
|
|
32
|
+
* @param bytes - Input bytes
|
|
33
|
+
* @returns Hash object with hex string and raw bytes
|
|
34
|
+
*/
|
|
35
|
+
function hashBytes(bytes) {
|
|
36
|
+
const hashArray = js_sha256_1.sha256.array(bytes);
|
|
37
|
+
const hashUint8 = new Uint8Array(hashArray);
|
|
38
|
+
const hashHex = js_sha256_1.sha256.hex(bytes);
|
|
39
|
+
return {
|
|
40
|
+
value: hashHex,
|
|
41
|
+
bytes: hashUint8,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.hashBytes = hashBytes;
|
|
45
|
+
/**
|
|
46
|
+
* Compute the full signing digest according to Constellation protocol
|
|
47
|
+
*
|
|
48
|
+
* Protocol:
|
|
49
|
+
* 1. Serialize data to binary (with optional DataUpdate prefix)
|
|
50
|
+
* 2. Compute SHA-256 hash
|
|
51
|
+
* 3. Convert hash to hex string
|
|
52
|
+
* 4. Treat hex string as UTF-8 bytes (NOT hex decode)
|
|
53
|
+
* 5. Compute SHA-512 of those bytes
|
|
54
|
+
* 6. Truncate to 32 bytes for secp256k1 signing
|
|
55
|
+
*
|
|
56
|
+
* @param data - Any JSON-serializable object
|
|
57
|
+
* @param isDataUpdate - Whether to apply DataUpdate encoding
|
|
58
|
+
* @returns 32-byte digest ready for ECDSA signing
|
|
59
|
+
*/
|
|
60
|
+
function computeDigest(data, isDataUpdate = false) {
|
|
61
|
+
// Step 1: Serialize to binary
|
|
62
|
+
const dataBytes = (0, binary_js_1.toBytes)(data, isDataUpdate);
|
|
63
|
+
// Step 2: SHA-256 hash
|
|
64
|
+
const sha256Hash = hashBytes(dataBytes);
|
|
65
|
+
// Step 3-4: Hex string as UTF-8 bytes (critical: NOT hex decode)
|
|
66
|
+
const hexAsUtf8 = new TextEncoder().encode(sha256Hash.value);
|
|
67
|
+
// Step 5: SHA-512
|
|
68
|
+
const sha512Hash = js_sha512_1.sha512.array(hexAsUtf8);
|
|
69
|
+
// Step 6: Truncate to 32 bytes
|
|
70
|
+
return new Uint8Array(sha512Hash.slice(0, 32));
|
|
71
|
+
}
|
|
72
|
+
exports.computeDigest = computeDigest;
|
|
73
|
+
/**
|
|
74
|
+
* Compute SHA-256 hash of data with optional DataUpdate encoding
|
|
75
|
+
*
|
|
76
|
+
* @param data - Any JSON-serializable object
|
|
77
|
+
* @param isDataUpdate - Whether to apply DataUpdate encoding
|
|
78
|
+
* @returns Hash object
|
|
79
|
+
*/
|
|
80
|
+
function hashData(data, isDataUpdate = false) {
|
|
81
|
+
const bytes = (0, binary_js_1.toBytes)(data, isDataUpdate);
|
|
82
|
+
return hashBytes(bytes);
|
|
83
|
+
}
|
|
84
|
+
exports.hashData = hashData;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Metakit SDK
|
|
4
|
+
*
|
|
5
|
+
* Reusable signing, encoding, and network operations for Constellation metagraphs.
|
|
6
|
+
* This module is framework-level functionality, independent of any specific metagraph domain.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.NetworkError = exports.HttpClient = exports.DataL1Client = exports.CurrencyL1Client = exports.unitsToToken = exports.tokenToUnits = exports.isValidDagAddress = exports.getTransactionReference = exports.hashCurrencyTransaction = exports.encodeCurrencyTransaction = exports.verifyCurrencyTransaction = exports.signCurrencyTransaction = exports.createCurrencyTransactionBatch = exports.createCurrencyTransaction = exports.TOKEN_DECIMALS = exports.isValidPublicKey = exports.isValidPrivateKey = exports.getAddress = exports.getPublicKeyId = exports.getPublicKeyHex = exports.keyPairFromPrivateKey = exports.generateKeyPair = exports.batchSign = exports.addSignature = exports.createSignedObject = exports.verifySignature = exports.verifyHash = exports.verify = exports.signHash = exports.signDataUpdate = exports.sign = exports.decodeDataUpdate = exports.computeDigest = exports.hashData = exports.hashBytes = exports.hash = exports.encodeDataUpdate = exports.toBytes = exports.canonicalize = exports.CONSTELLATION_PREFIX = exports.ALGORITHM = void 0;
|
|
12
|
+
var types_js_1 = require("./types.js");
|
|
13
|
+
Object.defineProperty(exports, "ALGORITHM", { enumerable: true, get: function () { return types_js_1.ALGORITHM; } });
|
|
14
|
+
Object.defineProperty(exports, "CONSTELLATION_PREFIX", { enumerable: true, get: function () { return types_js_1.CONSTELLATION_PREFIX; } });
|
|
15
|
+
// Canonicalization
|
|
16
|
+
var canonicalize_js_1 = require("./canonicalize.js");
|
|
17
|
+
Object.defineProperty(exports, "canonicalize", { enumerable: true, get: function () { return canonicalize_js_1.canonicalize; } });
|
|
18
|
+
// Binary encoding
|
|
19
|
+
var binary_js_1 = require("./binary.js");
|
|
20
|
+
Object.defineProperty(exports, "toBytes", { enumerable: true, get: function () { return binary_js_1.toBytes; } });
|
|
21
|
+
Object.defineProperty(exports, "encodeDataUpdate", { enumerable: true, get: function () { return binary_js_1.encodeDataUpdate; } });
|
|
22
|
+
// Hashing
|
|
23
|
+
var hash_js_1 = require("./hash.js");
|
|
24
|
+
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return hash_js_1.hash; } });
|
|
25
|
+
Object.defineProperty(exports, "hashBytes", { enumerable: true, get: function () { return hash_js_1.hashBytes; } });
|
|
26
|
+
Object.defineProperty(exports, "hashData", { enumerable: true, get: function () { return hash_js_1.hashData; } });
|
|
27
|
+
Object.defineProperty(exports, "computeDigest", { enumerable: true, get: function () { return hash_js_1.computeDigest; } });
|
|
28
|
+
// Codec utilities
|
|
29
|
+
var codec_js_1 = require("./codec.js");
|
|
30
|
+
Object.defineProperty(exports, "decodeDataUpdate", { enumerable: true, get: function () { return codec_js_1.decodeDataUpdate; } });
|
|
31
|
+
// Signing
|
|
32
|
+
var sign_js_1 = require("./sign.js");
|
|
33
|
+
Object.defineProperty(exports, "sign", { enumerable: true, get: function () { return sign_js_1.sign; } });
|
|
34
|
+
Object.defineProperty(exports, "signDataUpdate", { enumerable: true, get: function () { return sign_js_1.signDataUpdate; } });
|
|
35
|
+
Object.defineProperty(exports, "signHash", { enumerable: true, get: function () { return sign_js_1.signHash; } });
|
|
36
|
+
// Verification
|
|
37
|
+
var verify_js_1 = require("./verify.js");
|
|
38
|
+
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verify_js_1.verify; } });
|
|
39
|
+
Object.defineProperty(exports, "verifyHash", { enumerable: true, get: function () { return verify_js_1.verifyHash; } });
|
|
40
|
+
Object.defineProperty(exports, "verifySignature", { enumerable: true, get: function () { return verify_js_1.verifySignature; } });
|
|
41
|
+
// High-level API
|
|
42
|
+
var signed_object_js_1 = require("./signed-object.js");
|
|
43
|
+
Object.defineProperty(exports, "createSignedObject", { enumerable: true, get: function () { return signed_object_js_1.createSignedObject; } });
|
|
44
|
+
Object.defineProperty(exports, "addSignature", { enumerable: true, get: function () { return signed_object_js_1.addSignature; } });
|
|
45
|
+
Object.defineProperty(exports, "batchSign", { enumerable: true, get: function () { return signed_object_js_1.batchSign; } });
|
|
46
|
+
// Wallet utilities
|
|
47
|
+
var wallet_js_1 = require("./wallet.js");
|
|
48
|
+
Object.defineProperty(exports, "generateKeyPair", { enumerable: true, get: function () { return wallet_js_1.generateKeyPair; } });
|
|
49
|
+
Object.defineProperty(exports, "keyPairFromPrivateKey", { enumerable: true, get: function () { return wallet_js_1.keyPairFromPrivateKey; } });
|
|
50
|
+
Object.defineProperty(exports, "getPublicKeyHex", { enumerable: true, get: function () { return wallet_js_1.getPublicKeyHex; } });
|
|
51
|
+
Object.defineProperty(exports, "getPublicKeyId", { enumerable: true, get: function () { return wallet_js_1.getPublicKeyId; } });
|
|
52
|
+
Object.defineProperty(exports, "getAddress", { enumerable: true, get: function () { return wallet_js_1.getAddress; } });
|
|
53
|
+
Object.defineProperty(exports, "isValidPrivateKey", { enumerable: true, get: function () { return wallet_js_1.isValidPrivateKey; } });
|
|
54
|
+
Object.defineProperty(exports, "isValidPublicKey", { enumerable: true, get: function () { return wallet_js_1.isValidPublicKey; } });
|
|
55
|
+
var currency_types_js_1 = require("./currency-types.js");
|
|
56
|
+
Object.defineProperty(exports, "TOKEN_DECIMALS", { enumerable: true, get: function () { return currency_types_js_1.TOKEN_DECIMALS; } });
|
|
57
|
+
// Currency transaction operations
|
|
58
|
+
var currency_transaction_js_1 = require("./currency-transaction.js");
|
|
59
|
+
Object.defineProperty(exports, "createCurrencyTransaction", { enumerable: true, get: function () { return currency_transaction_js_1.createCurrencyTransaction; } });
|
|
60
|
+
Object.defineProperty(exports, "createCurrencyTransactionBatch", { enumerable: true, get: function () { return currency_transaction_js_1.createCurrencyTransactionBatch; } });
|
|
61
|
+
Object.defineProperty(exports, "signCurrencyTransaction", { enumerable: true, get: function () { return currency_transaction_js_1.signCurrencyTransaction; } });
|
|
62
|
+
Object.defineProperty(exports, "verifyCurrencyTransaction", { enumerable: true, get: function () { return currency_transaction_js_1.verifyCurrencyTransaction; } });
|
|
63
|
+
Object.defineProperty(exports, "encodeCurrencyTransaction", { enumerable: true, get: function () { return currency_transaction_js_1.encodeCurrencyTransaction; } });
|
|
64
|
+
Object.defineProperty(exports, "hashCurrencyTransaction", { enumerable: true, get: function () { return currency_transaction_js_1.hashCurrencyTransaction; } });
|
|
65
|
+
Object.defineProperty(exports, "getTransactionReference", { enumerable: true, get: function () { return currency_transaction_js_1.getTransactionReference; } });
|
|
66
|
+
Object.defineProperty(exports, "isValidDagAddress", { enumerable: true, get: function () { return currency_transaction_js_1.isValidDagAddress; } });
|
|
67
|
+
Object.defineProperty(exports, "tokenToUnits", { enumerable: true, get: function () { return currency_transaction_js_1.tokenToUnits; } });
|
|
68
|
+
Object.defineProperty(exports, "unitsToToken", { enumerable: true, get: function () { return currency_transaction_js_1.unitsToToken; } });
|
|
69
|
+
// Network operations
|
|
70
|
+
var index_js_1 = require("./network/index.js");
|
|
71
|
+
Object.defineProperty(exports, "CurrencyL1Client", { enumerable: true, get: function () { return index_js_1.CurrencyL1Client; } });
|
|
72
|
+
Object.defineProperty(exports, "DataL1Client", { enumerable: true, get: function () { return index_js_1.DataL1Client; } });
|
|
73
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return index_js_1.HttpClient; } });
|
|
74
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return index_js_1.NetworkError; } });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base HTTP client for network operations
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.HttpClient = void 0;
|
|
9
|
+
const types_js_1 = require("./types.js");
|
|
10
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
11
|
+
/**
|
|
12
|
+
* Simple HTTP client using native fetch
|
|
13
|
+
*/
|
|
14
|
+
class HttpClient {
|
|
15
|
+
constructor(baseUrl, timeout = DEFAULT_TIMEOUT) {
|
|
16
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
17
|
+
this.defaultTimeout = timeout;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Make a GET request
|
|
21
|
+
*/
|
|
22
|
+
async get(path, options = {}) {
|
|
23
|
+
return this.request('GET', path, undefined, options);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Make a POST request
|
|
27
|
+
*/
|
|
28
|
+
async post(path, body, options = {}) {
|
|
29
|
+
return this.request('POST', path, body, options);
|
|
30
|
+
}
|
|
31
|
+
async request(method, path, body, options = {}) {
|
|
32
|
+
const url = `${this.baseUrl}${path}`;
|
|
33
|
+
const timeout = options.timeout ?? this.defaultTimeout;
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
36
|
+
try {
|
|
37
|
+
const headers = {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
Accept: 'application/json',
|
|
40
|
+
...options.headers,
|
|
41
|
+
};
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method,
|
|
44
|
+
headers,
|
|
45
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
46
|
+
signal: controller.signal,
|
|
47
|
+
});
|
|
48
|
+
clearTimeout(timeoutId);
|
|
49
|
+
const text = await response.text();
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new types_js_1.NetworkError(`HTTP ${response.status}: ${response.statusText}`, response.status, text);
|
|
52
|
+
}
|
|
53
|
+
if (!text) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return text;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
clearTimeout(timeoutId);
|
|
65
|
+
if (error instanceof types_js_1.NetworkError) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
if (error.name === 'AbortError') {
|
|
70
|
+
throw new types_js_1.NetworkError(`Request timeout after ${timeout}ms`);
|
|
71
|
+
}
|
|
72
|
+
throw new types_js_1.NetworkError(error.message);
|
|
73
|
+
}
|
|
74
|
+
throw new types_js_1.NetworkError('Unknown network error');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency L1 client for submitting and querying transactions
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CurrencyL1Client = void 0;
|
|
9
|
+
const client_js_1 = require("./client.js");
|
|
10
|
+
const types_js_1 = require("./types.js");
|
|
11
|
+
/**
|
|
12
|
+
* Client for interacting with Currency L1 nodes
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const client = new CurrencyL1Client({ l1Url: 'http://localhost:9010' });
|
|
17
|
+
*
|
|
18
|
+
* // Get last reference for an address
|
|
19
|
+
* const lastRef = await client.getLastReference('DAG...');
|
|
20
|
+
*
|
|
21
|
+
* // Submit a transaction
|
|
22
|
+
* const result = await client.postTransaction(signedTx);
|
|
23
|
+
*
|
|
24
|
+
* // Check transaction status
|
|
25
|
+
* const pending = await client.getPendingTransaction(result.hash);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class CurrencyL1Client {
|
|
29
|
+
/**
|
|
30
|
+
* Create a new CurrencyL1Client
|
|
31
|
+
*
|
|
32
|
+
* @param config - Network configuration with l1Url
|
|
33
|
+
* @throws Error if l1Url is not provided
|
|
34
|
+
*/
|
|
35
|
+
constructor(config) {
|
|
36
|
+
if (!config.l1Url) {
|
|
37
|
+
throw new Error('l1Url is required for CurrencyL1Client');
|
|
38
|
+
}
|
|
39
|
+
this.client = new client_js_1.HttpClient(config.l1Url, config.timeout);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the last accepted transaction reference for an address
|
|
43
|
+
*
|
|
44
|
+
* This is needed to create a new transaction that chains from
|
|
45
|
+
* the address's most recent transaction.
|
|
46
|
+
*
|
|
47
|
+
* @param address - DAG address to query
|
|
48
|
+
* @param options - Request options
|
|
49
|
+
* @returns Transaction reference with hash and ordinal
|
|
50
|
+
*/
|
|
51
|
+
async getLastReference(address, options) {
|
|
52
|
+
return this.client.get(`/transactions/last-reference/${address}`, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Submit a signed currency transaction to the L1 network
|
|
56
|
+
*
|
|
57
|
+
* @param transaction - Signed currency transaction
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @returns Response containing the transaction hash
|
|
60
|
+
*/
|
|
61
|
+
async postTransaction(transaction, options) {
|
|
62
|
+
return this.client.post('/transactions', transaction, options);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get a pending transaction by hash
|
|
66
|
+
*
|
|
67
|
+
* Use this to poll for transaction status after submission.
|
|
68
|
+
* Returns null if the transaction is not found (already confirmed or invalid).
|
|
69
|
+
*
|
|
70
|
+
* @param hash - Transaction hash
|
|
71
|
+
* @param options - Request options
|
|
72
|
+
* @returns Pending transaction details or null if not found
|
|
73
|
+
*/
|
|
74
|
+
async getPendingTransaction(hash, options) {
|
|
75
|
+
try {
|
|
76
|
+
return await this.client.get(`/transactions/${hash}`, options);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (error instanceof types_js_1.NetworkError && error.statusCode === 404) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check the health/availability of the L1 node
|
|
87
|
+
*
|
|
88
|
+
* @param options - Request options
|
|
89
|
+
* @returns True if the node is healthy
|
|
90
|
+
*/
|
|
91
|
+
async checkHealth(options) {
|
|
92
|
+
try {
|
|
93
|
+
await this.client.get('/cluster/info', options);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.CurrencyL1Client = CurrencyL1Client;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Data L1 client for submitting data transactions to metagraphs
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DataL1Client = void 0;
|
|
9
|
+
const client_js_1 = require("./client.js");
|
|
10
|
+
/**
|
|
11
|
+
* Client for interacting with Data L1 nodes (metagraphs)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = new DataL1Client({ dataL1Url: 'http://localhost:8080' });
|
|
16
|
+
*
|
|
17
|
+
* // Estimate fee for data submission
|
|
18
|
+
* const feeInfo = await client.estimateFee(signedData);
|
|
19
|
+
*
|
|
20
|
+
* // Submit data
|
|
21
|
+
* const result = await client.postData(signedData);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class DataL1Client {
|
|
25
|
+
/**
|
|
26
|
+
* Create a new DataL1Client
|
|
27
|
+
*
|
|
28
|
+
* @param config - Network configuration with dataL1Url
|
|
29
|
+
* @throws Error if dataL1Url is not provided
|
|
30
|
+
*/
|
|
31
|
+
constructor(config) {
|
|
32
|
+
if (!config.dataL1Url) {
|
|
33
|
+
throw new Error('dataL1Url is required for DataL1Client');
|
|
34
|
+
}
|
|
35
|
+
this.client = new client_js_1.HttpClient(config.dataL1Url, config.timeout);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Estimate the fee for submitting data
|
|
39
|
+
*
|
|
40
|
+
* Some metagraphs charge fees for data submissions.
|
|
41
|
+
* Call this before postData to know the required fee.
|
|
42
|
+
*
|
|
43
|
+
* @param data - Signed data object to estimate fee for
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @returns Fee estimate with amount and destination address
|
|
46
|
+
*/
|
|
47
|
+
async estimateFee(data, options) {
|
|
48
|
+
return this.client.post('/data/estimate-fee', data, options);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Submit signed data to the Data L1 node
|
|
52
|
+
*
|
|
53
|
+
* @param data - Signed data object to submit
|
|
54
|
+
* @param options - Request options
|
|
55
|
+
* @returns Response containing the data hash
|
|
56
|
+
*/
|
|
57
|
+
async postData(data, options) {
|
|
58
|
+
return this.client.post('/data', data, options);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check the health/availability of the Data L1 node
|
|
62
|
+
*
|
|
63
|
+
* @param options - Request options
|
|
64
|
+
* @returns True if the node is healthy
|
|
65
|
+
*/
|
|
66
|
+
async checkHealth(options) {
|
|
67
|
+
try {
|
|
68
|
+
await this.client.get('/cluster/info', options);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.DataL1Client = DataL1Client;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Network operations for L1 node interactions
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.NetworkError = exports.HttpClient = exports.DataL1Client = exports.CurrencyL1Client = void 0;
|
|
9
|
+
var currency_l1_client_js_1 = require("./currency-l1-client.js");
|
|
10
|
+
Object.defineProperty(exports, "CurrencyL1Client", { enumerable: true, get: function () { return currency_l1_client_js_1.CurrencyL1Client; } });
|
|
11
|
+
var data_l1_client_js_1 = require("./data-l1-client.js");
|
|
12
|
+
Object.defineProperty(exports, "DataL1Client", { enumerable: true, get: function () { return data_l1_client_js_1.DataL1Client; } });
|
|
13
|
+
var client_js_1 = require("./client.js");
|
|
14
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_js_1.HttpClient; } });
|
|
15
|
+
var types_js_1 = require("./types.js");
|
|
16
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return types_js_1.NetworkError; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Network types for L1 client operations
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.NetworkError = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Network error with status code and response details
|
|
11
|
+
*/
|
|
12
|
+
class NetworkError extends Error {
|
|
13
|
+
constructor(message, statusCode, responseBody) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'NetworkError';
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
this.responseBody = responseBody;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.NetworkError = NetworkError;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Signing Functions
|
|
4
|
+
*
|
|
5
|
+
* ECDSA signing using secp256k1 curve via dag4js.
|
|
6
|
+
* Implements the Constellation signature protocol.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.signHash = exports.signDataUpdate = exports.sign = void 0;
|
|
10
|
+
const dag4_1 = require("@stardust-collective/dag4");
|
|
11
|
+
const js_sha256_1 = require("js-sha256");
|
|
12
|
+
const canonicalize_js_1 = require("./canonicalize.js");
|
|
13
|
+
/**
|
|
14
|
+
* Sign data using the regular Constellation protocol (non-DataUpdate)
|
|
15
|
+
*
|
|
16
|
+
* Protocol:
|
|
17
|
+
* 1. Canonicalize JSON (RFC 8785)
|
|
18
|
+
* 2. SHA-256 hash the canonical JSON string
|
|
19
|
+
* 3. Sign using dag4.keyStore.sign
|
|
20
|
+
*
|
|
21
|
+
* @param data - Any JSON-serializable object
|
|
22
|
+
* @param privateKey - Private key in hex format
|
|
23
|
+
* @returns SignatureProof with public key ID and signature
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const proof = await sign({ action: 'test' }, privateKeyHex);
|
|
28
|
+
* console.log(proof.id); // public key (128 chars)
|
|
29
|
+
* console.log(proof.signature); // DER signature
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async function sign(data, privateKey) {
|
|
33
|
+
// Step 1: Canonicalize JSON (RFC 8785)
|
|
34
|
+
const canonicalJson = (0, canonicalize_js_1.canonicalize)(data);
|
|
35
|
+
// Step 2-3: UTF-8 encode and SHA-256 hash (sha256 handles UTF-8 encoding internally)
|
|
36
|
+
// Returns 64-character hex string
|
|
37
|
+
const hashHex = (0, js_sha256_1.sha256)(canonicalJson);
|
|
38
|
+
// Step 4-6: dag4.keyStore.sign internally:
|
|
39
|
+
// 4. Treats hashHex as UTF-8 bytes
|
|
40
|
+
// 5. SHA-512 hashes those bytes, truncates to 32 bytes
|
|
41
|
+
// 6. Signs with ECDSA secp256k1
|
|
42
|
+
const signature = await dag4_1.dag4.keyStore.sign(privateKey, hashHex);
|
|
43
|
+
// Get public key ID (without 04 prefix)
|
|
44
|
+
const publicKey = dag4_1.dag4.keyStore.getPublicKeyFromPrivate(privateKey, false);
|
|
45
|
+
const id = normalizePublicKeyId(publicKey);
|
|
46
|
+
return { id, signature };
|
|
47
|
+
}
|
|
48
|
+
exports.sign = sign;
|
|
49
|
+
/**
|
|
50
|
+
* Sign data as a DataUpdate (with Constellation prefix)
|
|
51
|
+
*
|
|
52
|
+
* Protocol:
|
|
53
|
+
* 1. Canonicalize JSON (RFC 8785)
|
|
54
|
+
* 2. Base64 encode the canonical JSON
|
|
55
|
+
* 3. Sign using dag4.keyStore.dataSign (adds Constellation prefix internally)
|
|
56
|
+
*
|
|
57
|
+
* @param data - Any JSON-serializable object
|
|
58
|
+
* @param privateKey - Private key in hex format
|
|
59
|
+
* @returns SignatureProof
|
|
60
|
+
*/
|
|
61
|
+
async function signDataUpdate(data, privateKey) {
|
|
62
|
+
// Step 1: Canonicalize JSON
|
|
63
|
+
const canonicalJson = (0, canonicalize_js_1.canonicalize)(data);
|
|
64
|
+
// Step 2: Base64 encode for dataSign
|
|
65
|
+
const base64String = Buffer.from(canonicalJson, 'utf-8').toString('base64');
|
|
66
|
+
// Step 3: Sign using dag4's dataSign (handles Constellation prefix internally)
|
|
67
|
+
const signature = await dag4_1.dag4.keyStore.dataSign(privateKey, base64String);
|
|
68
|
+
// Get public key ID
|
|
69
|
+
const publicKey = dag4_1.dag4.keyStore.getPublicKeyFromPrivate(privateKey, false);
|
|
70
|
+
const id = normalizePublicKeyId(publicKey);
|
|
71
|
+
return { id, signature };
|
|
72
|
+
}
|
|
73
|
+
exports.signDataUpdate = signDataUpdate;
|
|
74
|
+
/**
|
|
75
|
+
* Sign a pre-computed SHA-256 hash
|
|
76
|
+
*
|
|
77
|
+
* This is the low-level signing function. Use `sign()` or `signDataUpdate()`
|
|
78
|
+
* for most use cases.
|
|
79
|
+
*
|
|
80
|
+
* Protocol (performed by dag4.keyStore.sign):
|
|
81
|
+
* 1. Treat hashHex as UTF-8 bytes (64 ASCII characters = 64 bytes)
|
|
82
|
+
* 2. SHA-512 hash those bytes (produces 64 bytes)
|
|
83
|
+
* 3. Truncate to first 32 bytes (for secp256k1 curve order)
|
|
84
|
+
* 4. Sign with ECDSA secp256k1
|
|
85
|
+
* 5. Return DER-encoded signature
|
|
86
|
+
*
|
|
87
|
+
* @param hashHex - SHA-256 hash as 64-character hex string
|
|
88
|
+
* @param privateKey - Private key in hex format (64 characters)
|
|
89
|
+
* @returns DER-encoded signature in hex format
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Compute your own hash
|
|
94
|
+
* const hashHex = sha256(myData);
|
|
95
|
+
* const signature = await signHash(hashHex, privateKey);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
async function signHash(hashHex, privateKey) {
|
|
99
|
+
// dag4.keyStore.sign performs:
|
|
100
|
+
// 1. SHA-512 of hashHex (treating 64 hex chars as UTF-8 bytes)
|
|
101
|
+
// 2. Truncation to 32 bytes (handled internally by crypto library)
|
|
102
|
+
// 3. ECDSA signing with secp256k1
|
|
103
|
+
return dag4_1.dag4.keyStore.sign(privateKey, hashHex);
|
|
104
|
+
}
|
|
105
|
+
exports.signHash = signHash;
|
|
106
|
+
/**
|
|
107
|
+
* Normalize public key to ID format (without 04 prefix, 128 chars)
|
|
108
|
+
*/
|
|
109
|
+
function normalizePublicKeyId(publicKey) {
|
|
110
|
+
// If 130 chars (with 04 prefix), remove prefix
|
|
111
|
+
if (publicKey.length === 130 && publicKey.startsWith('04')) {
|
|
112
|
+
return publicKey.substring(2);
|
|
113
|
+
}
|
|
114
|
+
// If 128 chars (without prefix), return as-is
|
|
115
|
+
if (publicKey.length === 128) {
|
|
116
|
+
return publicKey;
|
|
117
|
+
}
|
|
118
|
+
// Otherwise return as-is and let validation catch issues
|
|
119
|
+
return publicKey;
|
|
120
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* High-Level Signed Object API
|
|
4
|
+
*
|
|
5
|
+
* Convenience functions for creating and managing signed objects.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.batchSign = exports.addSignature = exports.createSignedObject = void 0;
|
|
9
|
+
const sign_js_1 = require("./sign.js");
|
|
10
|
+
/**
|
|
11
|
+
* Create a signed object with a single signature
|
|
12
|
+
*
|
|
13
|
+
* @param value - Any JSON-serializable object
|
|
14
|
+
* @param privateKey - Private key in hex format
|
|
15
|
+
* @param options - Signing options
|
|
16
|
+
* @returns Signed object ready for submission
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Sign a regular data object
|
|
21
|
+
* const signed = await createSignedObject(myData, privateKey);
|
|
22
|
+
*
|
|
23
|
+
* // Sign as DataUpdate for L1 submission
|
|
24
|
+
* const signedUpdate = await createSignedObject(myData, privateKey, { isDataUpdate: true });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function createSignedObject(value, privateKey, options = {}) {
|
|
28
|
+
const { isDataUpdate = false } = options;
|
|
29
|
+
const proof = isDataUpdate
|
|
30
|
+
? await (0, sign_js_1.signDataUpdate)(value, privateKey)
|
|
31
|
+
: await (0, sign_js_1.sign)(value, privateKey);
|
|
32
|
+
return {
|
|
33
|
+
value,
|
|
34
|
+
proofs: [proof],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.createSignedObject = createSignedObject;
|
|
38
|
+
/**
|
|
39
|
+
* Add an additional signature to an existing signed object
|
|
40
|
+
*
|
|
41
|
+
* This allows building multi-signature objects where multiple parties
|
|
42
|
+
* need to sign the same data.
|
|
43
|
+
*
|
|
44
|
+
* @param signed - Existing signed object
|
|
45
|
+
* @param privateKey - Private key in hex format
|
|
46
|
+
* @param options - Signing options (must match original signing)
|
|
47
|
+
* @returns New signed object with additional proof
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // First party signs
|
|
52
|
+
* let signed = await createSignedObject(data, party1Key);
|
|
53
|
+
*
|
|
54
|
+
* // Second party adds signature
|
|
55
|
+
* signed = await addSignature(signed, party2Key);
|
|
56
|
+
*
|
|
57
|
+
* // Now has 2 proofs
|
|
58
|
+
* console.log(signed.proofs.length); // 2
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async function addSignature(signed, privateKey, options = {}) {
|
|
62
|
+
const { isDataUpdate = false } = options;
|
|
63
|
+
const newProof = isDataUpdate
|
|
64
|
+
? await (0, sign_js_1.signDataUpdate)(signed.value, privateKey)
|
|
65
|
+
: await (0, sign_js_1.sign)(signed.value, privateKey);
|
|
66
|
+
return {
|
|
67
|
+
value: signed.value,
|
|
68
|
+
proofs: [...signed.proofs, newProof],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
exports.addSignature = addSignature;
|
|
72
|
+
/**
|
|
73
|
+
* Create a signed object with multiple signatures at once
|
|
74
|
+
*
|
|
75
|
+
* Useful when you have access to multiple private keys and want
|
|
76
|
+
* to create a multi-sig object in one operation.
|
|
77
|
+
*
|
|
78
|
+
* @param value - Any JSON-serializable object
|
|
79
|
+
* @param privateKeys - Array of private keys in hex format
|
|
80
|
+
* @param options - Signing options
|
|
81
|
+
* @returns Signed object with multiple proofs
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const signed = await batchSign(data, [key1, key2, key3]);
|
|
86
|
+
* console.log(signed.proofs.length); // 3
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
async function batchSign(value, privateKeys, options = {}) {
|
|
90
|
+
if (privateKeys.length === 0) {
|
|
91
|
+
throw new Error('At least one private key is required');
|
|
92
|
+
}
|
|
93
|
+
const { isDataUpdate = false } = options;
|
|
94
|
+
const proofs = await Promise.all(privateKeys.map((key) => (isDataUpdate ? (0, sign_js_1.signDataUpdate)(value, key) : (0, sign_js_1.sign)(value, key))));
|
|
95
|
+
return {
|
|
96
|
+
value,
|
|
97
|
+
proofs,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.batchSign = batchSign;
|