@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,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OttoChain Type Aliases
|
|
4
|
+
*
|
|
5
|
+
* Semantic type aliases for common primitive types.
|
|
6
|
+
* These match the wire format used by the metagraph's JSON Logic engine.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isValidFiberId = exports.isValidAddress = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Validate a DAG address format.
|
|
14
|
+
*/
|
|
15
|
+
function isValidAddress(value) {
|
|
16
|
+
return /^DAG[0-9a-zA-Z]+$/.test(value);
|
|
17
|
+
}
|
|
18
|
+
exports.isValidAddress = isValidAddress;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a UUID format.
|
|
21
|
+
*/
|
|
22
|
+
function isValidFiberId(value) {
|
|
23
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
24
|
+
}
|
|
25
|
+
exports.isValidFiberId = isValidFiberId;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Input Validation with Zod Schemas
|
|
4
|
+
*
|
|
5
|
+
* Provides runtime validation for SDK types using Zod.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = void 0;
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const errors_js_1 = require("./errors.js");
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Primitive Schemas
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Schema for a hex string of specific length
|
|
18
|
+
*/
|
|
19
|
+
const hexString = (length) => {
|
|
20
|
+
let schema = zod_1.z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
|
|
21
|
+
if (length !== undefined) {
|
|
22
|
+
schema = schema.length(length, `Must be exactly ${length} characters`);
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Schema for a DAG address
|
|
28
|
+
*/
|
|
29
|
+
exports.DagAddressSchema = zod_1.z
|
|
30
|
+
.string()
|
|
31
|
+
.regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Core Type Schemas
|
|
34
|
+
// ============================================================================
|
|
35
|
+
/**
|
|
36
|
+
* Schema for a private key (64-character hex string)
|
|
37
|
+
*/
|
|
38
|
+
exports.PrivateKeySchema = hexString(64).describe('Private key in hex format (64 characters)');
|
|
39
|
+
/**
|
|
40
|
+
* Schema for a public key (128 or 130 character hex string)
|
|
41
|
+
*/
|
|
42
|
+
exports.PublicKeySchema = zod_1.z
|
|
43
|
+
.string()
|
|
44
|
+
.regex(/^(04)?[0-9a-fA-F]{128}$/, 'Must be a valid public key (128 or 130 hex chars)')
|
|
45
|
+
.describe('Public key in hex format (with optional 04 prefix)');
|
|
46
|
+
/**
|
|
47
|
+
* Schema for a KeyPair
|
|
48
|
+
*/
|
|
49
|
+
exports.KeyPairSchema = zod_1.z.object({
|
|
50
|
+
/** Private key in hex format */
|
|
51
|
+
privateKey: exports.PrivateKeySchema,
|
|
52
|
+
/** Public key in hex format (uncompressed, with 04 prefix) */
|
|
53
|
+
publicKey: exports.PublicKeySchema,
|
|
54
|
+
/** DAG address derived from the public key */
|
|
55
|
+
address: exports.DagAddressSchema,
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Schema for a SignatureProof
|
|
59
|
+
*/
|
|
60
|
+
exports.SignatureProofSchema = zod_1.z.object({
|
|
61
|
+
/** Public key hex (uncompressed, without 04 prefix) - 128 characters */
|
|
62
|
+
id: hexString(128),
|
|
63
|
+
/** DER-encoded ECDSA signature in hex format */
|
|
64
|
+
signature: hexString(),
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Schema for a Signed object (generic)
|
|
68
|
+
*/
|
|
69
|
+
const SignedSchema = (valueSchema) => zod_1.z.object({
|
|
70
|
+
value: valueSchema,
|
|
71
|
+
proofs: zod_1.z.array(exports.SignatureProofSchema).min(1, 'At least one proof is required'),
|
|
72
|
+
});
|
|
73
|
+
exports.SignedSchema = SignedSchema;
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Transaction Schemas
|
|
76
|
+
// ============================================================================
|
|
77
|
+
/**
|
|
78
|
+
* Schema for TransactionReference
|
|
79
|
+
*/
|
|
80
|
+
exports.TransactionReferenceSchema = zod_1.z.object({
|
|
81
|
+
ordinal: zod_1.z.number().int().min(0),
|
|
82
|
+
hash: zod_1.z.string().min(1),
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Schema for CurrencyTransactionValue
|
|
86
|
+
*/
|
|
87
|
+
exports.CurrencyTransactionValueSchema = zod_1.z.object({
|
|
88
|
+
source: exports.DagAddressSchema,
|
|
89
|
+
destination: exports.DagAddressSchema,
|
|
90
|
+
amount: zod_1.z.number().int().positive('Amount must be positive'),
|
|
91
|
+
fee: zod_1.z.number().int().min(0).default(0),
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Schema for CurrencyTransaction
|
|
95
|
+
*/
|
|
96
|
+
exports.CurrencyTransactionSchema = zod_1.z.object({
|
|
97
|
+
value: exports.CurrencyTransactionValueSchema,
|
|
98
|
+
parent: exports.TransactionReferenceSchema,
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Schema for TransferParams
|
|
102
|
+
*/
|
|
103
|
+
exports.TransferParamsSchema = zod_1.z.object({
|
|
104
|
+
from: exports.DagAddressSchema,
|
|
105
|
+
to: exports.DagAddressSchema,
|
|
106
|
+
amount: zod_1.z.number().positive('Amount must be positive'),
|
|
107
|
+
fee: zod_1.z.number().min(0).optional().default(0),
|
|
108
|
+
});
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// Identity Schemas
|
|
111
|
+
// ============================================================================
|
|
112
|
+
/**
|
|
113
|
+
* Schema for AgentIdentity registration
|
|
114
|
+
*/
|
|
115
|
+
exports.AgentIdentityRegistrationSchema = zod_1.z.object({
|
|
116
|
+
/** Public key in hex format */
|
|
117
|
+
publicKey: exports.PublicKeySchema,
|
|
118
|
+
/** Display name for the agent */
|
|
119
|
+
displayName: zod_1.z.string().min(1).max(64),
|
|
120
|
+
/** Initial reputation (default: 10) */
|
|
121
|
+
reputation: zod_1.z.number().int().min(0).optional().default(10),
|
|
122
|
+
});
|
|
123
|
+
/**
|
|
124
|
+
* Schema for PlatformLink
|
|
125
|
+
*/
|
|
126
|
+
exports.PlatformLinkSchema = zod_1.z.object({
|
|
127
|
+
platform: zod_1.z.enum(['DISCORD', 'TELEGRAM', 'TWITTER', 'GITHUB', 'CUSTOM']),
|
|
128
|
+
platformUserId: zod_1.z.string().min(1),
|
|
129
|
+
platformUsername: zod_1.z.string().min(1),
|
|
130
|
+
verified: zod_1.z.boolean().optional().default(false),
|
|
131
|
+
});
|
|
132
|
+
// ============================================================================
|
|
133
|
+
// Contract Schemas
|
|
134
|
+
// ============================================================================
|
|
135
|
+
/**
|
|
136
|
+
* Schema for contract terms (flexible structure)
|
|
137
|
+
*/
|
|
138
|
+
exports.ContractTermsSchema = zod_1.z.record(zod_1.z.unknown());
|
|
139
|
+
/**
|
|
140
|
+
* Schema for ProposeContractRequest
|
|
141
|
+
*/
|
|
142
|
+
exports.ProposeContractRequestSchema = zod_1.z.object({
|
|
143
|
+
/** Proposer's DAG address */
|
|
144
|
+
proposer: exports.DagAddressSchema,
|
|
145
|
+
/** Counterparty's DAG address */
|
|
146
|
+
counterparty: exports.DagAddressSchema,
|
|
147
|
+
/** Contract terms */
|
|
148
|
+
terms: exports.ContractTermsSchema,
|
|
149
|
+
/** Human-readable description */
|
|
150
|
+
description: zod_1.z.string().min(1).max(1000),
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* Schema for AcceptContractRequest
|
|
154
|
+
*/
|
|
155
|
+
exports.AcceptContractRequestSchema = zod_1.z.object({
|
|
156
|
+
/** Contract ID to accept */
|
|
157
|
+
contractId: zod_1.z.string().min(1),
|
|
158
|
+
/** Acceptor's DAG address */
|
|
159
|
+
acceptor: exports.DagAddressSchema,
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* Schema for CompleteContractRequest
|
|
163
|
+
*/
|
|
164
|
+
exports.CompleteContractRequestSchema = zod_1.z.object({
|
|
165
|
+
/** Contract ID to complete */
|
|
166
|
+
contractId: zod_1.z.string().min(1),
|
|
167
|
+
/** Completer's DAG address */
|
|
168
|
+
completer: exports.DagAddressSchema,
|
|
169
|
+
/** Proof of completion */
|
|
170
|
+
proof: zod_1.z.string().min(1),
|
|
171
|
+
});
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Validation Helpers
|
|
174
|
+
// ============================================================================
|
|
175
|
+
/**
|
|
176
|
+
* Validate data against a Zod schema
|
|
177
|
+
*
|
|
178
|
+
* @param schema - Zod schema to validate against
|
|
179
|
+
* @param data - Data to validate
|
|
180
|
+
* @param fieldName - Optional field name for error context
|
|
181
|
+
* @returns Validated and typed data
|
|
182
|
+
* @throws {ValidationError} If validation fails
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const keyPair = validate(KeyPairSchema, inputData, 'keyPair');
|
|
187
|
+
* // keyPair is now typed as ValidatedKeyPair
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function validate(schema, data, fieldName) {
|
|
191
|
+
const result = schema.safeParse(data);
|
|
192
|
+
if (!result.success) {
|
|
193
|
+
const issues = result.error.issues;
|
|
194
|
+
const firstIssue = issues[0];
|
|
195
|
+
// Build a helpful error message
|
|
196
|
+
const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : fieldName || 'input';
|
|
197
|
+
const message = `Validation failed for '${path}': ${firstIssue.message}`;
|
|
198
|
+
throw new errors_js_1.ValidationError(message, {
|
|
199
|
+
field: path,
|
|
200
|
+
value: data,
|
|
201
|
+
details: {
|
|
202
|
+
issues: issues.map((issue) => ({
|
|
203
|
+
path: issue.path.join('.'),
|
|
204
|
+
message: issue.message,
|
|
205
|
+
code: issue.code,
|
|
206
|
+
})),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return result.data;
|
|
211
|
+
}
|
|
212
|
+
exports.validate = validate;
|
|
213
|
+
/**
|
|
214
|
+
* Validate a private key
|
|
215
|
+
*
|
|
216
|
+
* @param privateKey - Private key to validate
|
|
217
|
+
* @returns Validated private key
|
|
218
|
+
* @throws {ValidationError} If validation fails
|
|
219
|
+
*/
|
|
220
|
+
function validatePrivateKey(privateKey) {
|
|
221
|
+
return validate(exports.PrivateKeySchema, privateKey, 'privateKey');
|
|
222
|
+
}
|
|
223
|
+
exports.validatePrivateKey = validatePrivateKey;
|
|
224
|
+
/**
|
|
225
|
+
* Validate a public key
|
|
226
|
+
*
|
|
227
|
+
* @param publicKey - Public key to validate
|
|
228
|
+
* @returns Validated public key
|
|
229
|
+
* @throws {ValidationError} If validation fails
|
|
230
|
+
*/
|
|
231
|
+
function validatePublicKey(publicKey) {
|
|
232
|
+
return validate(exports.PublicKeySchema, publicKey, 'publicKey');
|
|
233
|
+
}
|
|
234
|
+
exports.validatePublicKey = validatePublicKey;
|
|
235
|
+
/**
|
|
236
|
+
* Validate a DAG address
|
|
237
|
+
*
|
|
238
|
+
* @param address - Address to validate
|
|
239
|
+
* @returns Validated address
|
|
240
|
+
* @throws {ValidationError} If validation fails
|
|
241
|
+
*/
|
|
242
|
+
function validateAddress(address) {
|
|
243
|
+
return validate(exports.DagAddressSchema, address, 'address');
|
|
244
|
+
}
|
|
245
|
+
exports.validateAddress = validateAddress;
|
|
246
|
+
/**
|
|
247
|
+
* Validate a KeyPair
|
|
248
|
+
*
|
|
249
|
+
* @param keyPair - KeyPair to validate
|
|
250
|
+
* @returns Validated KeyPair
|
|
251
|
+
* @throws {ValidationError} If validation fails
|
|
252
|
+
*/
|
|
253
|
+
function validateKeyPair(keyPair) {
|
|
254
|
+
return validate(exports.KeyPairSchema, keyPair, 'keyPair');
|
|
255
|
+
}
|
|
256
|
+
exports.validateKeyPair = validateKeyPair;
|
|
257
|
+
/**
|
|
258
|
+
* Safe validation that returns a result object instead of throwing
|
|
259
|
+
*
|
|
260
|
+
* @param schema - Zod schema to validate against
|
|
261
|
+
* @param data - Data to validate
|
|
262
|
+
* @returns Object with success status and data or error
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const result = safeParse(KeyPairSchema, inputData);
|
|
267
|
+
* if (result.success) {
|
|
268
|
+
* console.log(result.data.address);
|
|
269
|
+
* } else {
|
|
270
|
+
* console.log(result.error.message);
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
function safeParse(schema, data) {
|
|
275
|
+
const result = schema.safeParse(data);
|
|
276
|
+
if (result.success) {
|
|
277
|
+
return { success: true, data: result.data };
|
|
278
|
+
}
|
|
279
|
+
const issues = result.error.issues;
|
|
280
|
+
const firstIssue = issues[0];
|
|
281
|
+
const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : 'input';
|
|
282
|
+
const message = `Validation failed for '${path}': ${firstIssue.message}`;
|
|
283
|
+
return {
|
|
284
|
+
success: false,
|
|
285
|
+
error: new errors_js_1.ValidationError(message, {
|
|
286
|
+
field: path,
|
|
287
|
+
value: data,
|
|
288
|
+
details: {
|
|
289
|
+
issues: issues.map((issue) => ({
|
|
290
|
+
path: issue.path.join('.'),
|
|
291
|
+
message: issue.message,
|
|
292
|
+
code: issue.code,
|
|
293
|
+
})),
|
|
294
|
+
},
|
|
295
|
+
}),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
exports.safeParse = safeParse;
|
|
299
|
+
/**
|
|
300
|
+
* Assert that a condition is true, throwing ValidationError if not
|
|
301
|
+
*
|
|
302
|
+
* @param condition - Condition to check
|
|
303
|
+
* @param message - Error message if condition is false
|
|
304
|
+
* @param field - Optional field name for context
|
|
305
|
+
* @throws {ValidationError} If condition is false
|
|
306
|
+
*/
|
|
307
|
+
function assert(condition, message, field) {
|
|
308
|
+
if (!condition) {
|
|
309
|
+
throw new errors_js_1.ValidationError(message, { field });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
exports.assert = assert;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error Classes for OttoChain SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error handling with error codes and causes.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Error codes for OttoChain SDK errors
|
|
10
|
+
*/
|
|
11
|
+
export declare enum ErrorCode {
|
|
12
|
+
/** Unknown or unclassified error */
|
|
13
|
+
UNKNOWN = "UNKNOWN",
|
|
14
|
+
/** Network/HTTP connection failure */
|
|
15
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
16
|
+
/** Request timeout */
|
|
17
|
+
NETWORK_TIMEOUT = "NETWORK_TIMEOUT",
|
|
18
|
+
/** Input validation failed */
|
|
19
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
20
|
+
/** Invalid private key format */
|
|
21
|
+
INVALID_PRIVATE_KEY = "INVALID_PRIVATE_KEY",
|
|
22
|
+
/** Invalid public key format */
|
|
23
|
+
INVALID_PUBLIC_KEY = "INVALID_PUBLIC_KEY",
|
|
24
|
+
/** Invalid DAG address format */
|
|
25
|
+
INVALID_ADDRESS = "INVALID_ADDRESS",
|
|
26
|
+
/** Signature creation failed */
|
|
27
|
+
SIGNING_ERROR = "SIGNING_ERROR",
|
|
28
|
+
/** Signature verification failed */
|
|
29
|
+
VERIFICATION_ERROR = "VERIFICATION_ERROR",
|
|
30
|
+
/** Transaction rejected by network */
|
|
31
|
+
TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
|
|
32
|
+
/** Transaction not found */
|
|
33
|
+
TRANSACTION_NOT_FOUND = "TRANSACTION_NOT_FOUND",
|
|
34
|
+
/** Invalid transaction format */
|
|
35
|
+
INVALID_TRANSACTION = "INVALID_TRANSACTION"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Base error class for all OttoChain SDK errors
|
|
39
|
+
*
|
|
40
|
+
* Provides consistent error structure with:
|
|
41
|
+
* - Error code for programmatic handling
|
|
42
|
+
* - Human-readable message
|
|
43
|
+
* - Optional cause for error chaining
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* try {
|
|
48
|
+
* await signTransaction(data, invalidKey);
|
|
49
|
+
* } catch (error) {
|
|
50
|
+
* if (error instanceof OttoChainError) {
|
|
51
|
+
* console.log(error.code); // 'INVALID_PRIVATE_KEY'
|
|
52
|
+
* console.log(error.message); // 'Invalid private key format'
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class OttoChainError extends Error {
|
|
58
|
+
/** Error code for programmatic handling */
|
|
59
|
+
readonly code: ErrorCode;
|
|
60
|
+
/** Original error that caused this error */
|
|
61
|
+
readonly cause?: Error;
|
|
62
|
+
constructor(code: ErrorCode, message: string, cause?: Error);
|
|
63
|
+
/**
|
|
64
|
+
* Create a string representation of the error
|
|
65
|
+
*/
|
|
66
|
+
toString(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Convert error to a plain object for logging/serialization
|
|
69
|
+
*/
|
|
70
|
+
toJSON(): Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown when network operations fail
|
|
74
|
+
*
|
|
75
|
+
* Covers HTTP failures, connection errors, and timeouts.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* try {
|
|
80
|
+
* await client.postTransaction(signed);
|
|
81
|
+
* } catch (error) {
|
|
82
|
+
* if (error instanceof NetworkError) {
|
|
83
|
+
* console.log(error.statusCode); // 503
|
|
84
|
+
* console.log(error.responseBody); // '{"error": "Service unavailable"}'
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare class NetworkError extends OttoChainError {
|
|
90
|
+
/** HTTP status code if applicable */
|
|
91
|
+
readonly statusCode?: number;
|
|
92
|
+
/** Response body if available */
|
|
93
|
+
readonly responseBody?: string;
|
|
94
|
+
constructor(message: string, statusCode?: number, responseBody?: string, cause?: Error);
|
|
95
|
+
/**
|
|
96
|
+
* Create a timeout error
|
|
97
|
+
*/
|
|
98
|
+
static timeout(timeoutMs: number): NetworkError;
|
|
99
|
+
toJSON(): Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Error thrown when input validation fails
|
|
103
|
+
*
|
|
104
|
+
* Used when function parameters don't meet expected format or constraints.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* try {
|
|
109
|
+
* const keyPair = keyPairFromPrivateKey('invalid');
|
|
110
|
+
* } catch (error) {
|
|
111
|
+
* if (error instanceof ValidationError) {
|
|
112
|
+
* console.log(error.field); // 'privateKey'
|
|
113
|
+
* console.log(error.value); // 'invalid'
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare class ValidationError extends OttoChainError {
|
|
119
|
+
/** Field that failed validation */
|
|
120
|
+
readonly field?: string;
|
|
121
|
+
/** Value that failed validation (sanitized) */
|
|
122
|
+
readonly value?: unknown;
|
|
123
|
+
/** Validation details/constraints */
|
|
124
|
+
readonly details?: Record<string, unknown>;
|
|
125
|
+
constructor(message: string, options?: {
|
|
126
|
+
field?: string;
|
|
127
|
+
value?: unknown;
|
|
128
|
+
details?: Record<string, unknown>;
|
|
129
|
+
cause?: Error;
|
|
130
|
+
});
|
|
131
|
+
toJSON(): Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Error thrown when cryptographic signing operations fail
|
|
135
|
+
*
|
|
136
|
+
* Covers key derivation, signature creation, and related crypto operations.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* try {
|
|
141
|
+
* const signature = await signHash(hash, privateKey);
|
|
142
|
+
* } catch (error) {
|
|
143
|
+
* if (error instanceof SigningError) {
|
|
144
|
+
* console.log(error.operation); // 'sign'
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare class SigningError extends OttoChainError {
|
|
150
|
+
/** The operation that failed */
|
|
151
|
+
readonly operation?: string;
|
|
152
|
+
constructor(message: string, options?: {
|
|
153
|
+
operation?: string;
|
|
154
|
+
cause?: Error;
|
|
155
|
+
});
|
|
156
|
+
toJSON(): Record<string, unknown>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Error thrown when transaction operations fail
|
|
160
|
+
*
|
|
161
|
+
* Used when transactions are rejected, not found, or invalid.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* try {
|
|
166
|
+
* await client.postTransaction(signed);
|
|
167
|
+
* } catch (error) {
|
|
168
|
+
* if (error instanceof TransactionError) {
|
|
169
|
+
* console.log(error.transactionHash); // 'abc123...'
|
|
170
|
+
* console.log(error.rejectionReason); // 'Insufficient balance'
|
|
171
|
+
* }
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare class TransactionError extends OttoChainError {
|
|
176
|
+
/** Transaction hash if available */
|
|
177
|
+
readonly transactionHash?: string;
|
|
178
|
+
/** Reason for rejection if available */
|
|
179
|
+
readonly rejectionReason?: string;
|
|
180
|
+
constructor(code: ErrorCode, message: string, options?: {
|
|
181
|
+
transactionHash?: string;
|
|
182
|
+
rejectionReason?: string;
|
|
183
|
+
cause?: Error;
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* Create a transaction rejected error
|
|
187
|
+
*/
|
|
188
|
+
static rejected(reason: string, transactionHash?: string): TransactionError;
|
|
189
|
+
/**
|
|
190
|
+
* Create a transaction not found error
|
|
191
|
+
*/
|
|
192
|
+
static notFound(transactionHash: string): TransactionError;
|
|
193
|
+
/**
|
|
194
|
+
* Create an invalid transaction error
|
|
195
|
+
*/
|
|
196
|
+
static invalid(message: string, cause?: Error): TransactionError;
|
|
197
|
+
toJSON(): Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Check if an error is an OttoChain error with a specific code
|
|
201
|
+
*
|
|
202
|
+
* @param error - Error to check
|
|
203
|
+
* @param code - Error code to match
|
|
204
|
+
* @returns True if error matches the code
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* if (isErrorCode(error, ErrorCode.NETWORK_TIMEOUT)) {
|
|
209
|
+
* // Retry the request
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export declare function isErrorCode(error: unknown, code: ErrorCode): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Wrap an unknown error in an OttoChainError
|
|
216
|
+
*
|
|
217
|
+
* @param error - Error to wrap
|
|
218
|
+
* @param defaultMessage - Default message if error has no message
|
|
219
|
+
* @returns OttoChainError wrapping the original error
|
|
220
|
+
*/
|
|
221
|
+
export declare function wrapError(error: unknown, defaultMessage?: string): OttoChainError;
|