@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,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Oracles Application Types
|
|
4
|
+
*
|
|
5
|
+
* Constants, types, and utilities for the Oracle system on OttoChain.
|
|
6
|
+
* Oracles provide truth resolution for markets and disputes.
|
|
7
|
+
*
|
|
8
|
+
* Core types (OracleState, Oracle, etc.) are exported from proto-generated
|
|
9
|
+
* types in index.ts.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.isResolutionType = exports.isSlashingReason = exports.isOracleState = exports.calculateOracleReward = exports.calculateSelectionScore = exports.calculateStakeAfterSlash = exports.calculateSlashAmount = exports.SLASHING_CONDITIONS = exports.qualifiesForHighValue = exports.calculateWeightedReputation = exports.calculateReputation = exports.REPUTATION_DELTAS = exports.canAcceptAssignment = exports.isTerminalOracleState = exports.ORACLE_TRANSITIONS = exports.SLASHING_PERCENTAGES = exports.DEFAULT_ORACLE_CONFIG = exports.SlashingReason = exports.ResolutionType = void 0;
|
|
15
|
+
const oracle_pb_js_1 = require("../../generated/ottochain/apps/oracles/v1/oracle_pb.js");
|
|
16
|
+
/**
|
|
17
|
+
* Types of oracle resolutions
|
|
18
|
+
*/
|
|
19
|
+
var ResolutionType;
|
|
20
|
+
(function (ResolutionType) {
|
|
21
|
+
ResolutionType[ResolutionType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
22
|
+
/** Binary yes/no outcome */
|
|
23
|
+
ResolutionType[ResolutionType["BINARY"] = 1] = "BINARY";
|
|
24
|
+
/** One of multiple predefined outcomes */
|
|
25
|
+
ResolutionType[ResolutionType["MULTI_CHOICE"] = 2] = "MULTI_CHOICE";
|
|
26
|
+
/** Numeric value (e.g., price) */
|
|
27
|
+
ResolutionType[ResolutionType["NUMERIC"] = 3] = "NUMERIC";
|
|
28
|
+
/** Free-form attestation */
|
|
29
|
+
ResolutionType[ResolutionType["ATTESTATION"] = 4] = "ATTESTATION";
|
|
30
|
+
})(ResolutionType || (exports.ResolutionType = ResolutionType = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Reasons for slashing oracle stake
|
|
33
|
+
*/
|
|
34
|
+
var SlashingReason;
|
|
35
|
+
(function (SlashingReason) {
|
|
36
|
+
SlashingReason[SlashingReason["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
37
|
+
/** Failed to submit resolution in time */
|
|
38
|
+
SlashingReason[SlashingReason["TIMEOUT"] = 1] = "TIMEOUT";
|
|
39
|
+
/** Resolution overturned by dispute */
|
|
40
|
+
SlashingReason[SlashingReason["INCORRECT_RESOLUTION"] = 2] = "INCORRECT_RESOLUTION";
|
|
41
|
+
/** Evidence of collusion or manipulation */
|
|
42
|
+
SlashingReason[SlashingReason["COLLUSION"] = 3] = "COLLUSION";
|
|
43
|
+
/** Violation of oracle protocol */
|
|
44
|
+
SlashingReason[SlashingReason["PROTOCOL_VIOLATION"] = 4] = "PROTOCOL_VIOLATION";
|
|
45
|
+
})(SlashingReason || (exports.SlashingReason = SlashingReason = {}));
|
|
46
|
+
/**
|
|
47
|
+
* Default oracle configuration
|
|
48
|
+
*/
|
|
49
|
+
exports.DEFAULT_ORACLE_CONFIG = {
|
|
50
|
+
minStake: 10000n,
|
|
51
|
+
timeoutSlashPercent: 0.05,
|
|
52
|
+
incorrectSlashPercent: 0.25,
|
|
53
|
+
collusionSlashPercent: 1.0,
|
|
54
|
+
violationSlashPercent: 0.10,
|
|
55
|
+
cooldownEpochs: 48,
|
|
56
|
+
baseReputation: 50,
|
|
57
|
+
highValueThreshold: 100,
|
|
58
|
+
resolutionWindowEpochs: 12,
|
|
59
|
+
challengeWindowEpochs: 6,
|
|
60
|
+
oracleRewardPercent: 0.01,
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Slashing percentages by reason
|
|
64
|
+
*/
|
|
65
|
+
exports.SLASHING_PERCENTAGES = {
|
|
66
|
+
[SlashingReason.UNSPECIFIED]: 0,
|
|
67
|
+
[SlashingReason.TIMEOUT]: exports.DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
|
|
68
|
+
[SlashingReason.INCORRECT_RESOLUTION]: exports.DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
|
|
69
|
+
[SlashingReason.COLLUSION]: exports.DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
|
|
70
|
+
[SlashingReason.PROTOCOL_VIOLATION]: exports.DEFAULT_ORACLE_CONFIG.violationSlashPercent,
|
|
71
|
+
};
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// State Machine Transitions
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
/**
|
|
76
|
+
* Valid transitions for each oracle state (aligned with proto OracleState enum)
|
|
77
|
+
*/
|
|
78
|
+
exports.ORACLE_TRANSITIONS = {
|
|
79
|
+
[oracle_pb_js_1.OracleState.UNSPECIFIED]: [],
|
|
80
|
+
[oracle_pb_js_1.OracleState.UNREGISTERED]: ['register'],
|
|
81
|
+
[oracle_pb_js_1.OracleState.REGISTERED]: ['activate', 'withdraw'],
|
|
82
|
+
[oracle_pb_js_1.OracleState.ACTIVE]: ['add_stake', 'record_resolution', 'slash', 'withdraw'],
|
|
83
|
+
[oracle_pb_js_1.OracleState.SLASHED]: ['reactivate', 'withdraw'],
|
|
84
|
+
[oracle_pb_js_1.OracleState.WITHDRAWN]: [], // Terminal state
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Check if an oracle state is terminal
|
|
88
|
+
*/
|
|
89
|
+
function isTerminalOracleState(state) {
|
|
90
|
+
return state === oracle_pb_js_1.OracleState.WITHDRAWN;
|
|
91
|
+
}
|
|
92
|
+
exports.isTerminalOracleState = isTerminalOracleState;
|
|
93
|
+
/**
|
|
94
|
+
* Check if an oracle can accept new assignments
|
|
95
|
+
*/
|
|
96
|
+
function canAcceptAssignment(state) {
|
|
97
|
+
return state === oracle_pb_js_1.OracleState.ACTIVE;
|
|
98
|
+
}
|
|
99
|
+
exports.canAcceptAssignment = canAcceptAssignment;
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Reputation Calculations
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
/**
|
|
104
|
+
* Reputation update factors
|
|
105
|
+
*/
|
|
106
|
+
exports.REPUTATION_DELTAS = {
|
|
107
|
+
/** Successfully resolved market without challenge */
|
|
108
|
+
successfulResolution: 5,
|
|
109
|
+
/** Resolution upheld after challenge */
|
|
110
|
+
upheldChallenge: 10,
|
|
111
|
+
/** Resolution overturned (negative) */
|
|
112
|
+
overturnedResolution: -25,
|
|
113
|
+
/** Timeout on assigned market (negative) */
|
|
114
|
+
timeout: -15,
|
|
115
|
+
/** Collusion detected (negative) */
|
|
116
|
+
collusion: -100,
|
|
117
|
+
/** Protocol violation (negative) */
|
|
118
|
+
violation: -20,
|
|
119
|
+
/** Bonus for high-value market resolution */
|
|
120
|
+
highValueBonus: 3,
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Calculate new reputation after an event
|
|
124
|
+
*
|
|
125
|
+
* @param currentReputation - Current reputation score
|
|
126
|
+
* @param delta - Reputation change (positive or negative)
|
|
127
|
+
* @param minReputation - Minimum reputation floor (default 0)
|
|
128
|
+
* @returns New reputation score
|
|
129
|
+
*/
|
|
130
|
+
function calculateReputation(currentReputation, delta, minReputation = 0) {
|
|
131
|
+
return Math.max(minReputation, currentReputation + delta);
|
|
132
|
+
}
|
|
133
|
+
exports.calculateReputation = calculateReputation;
|
|
134
|
+
/**
|
|
135
|
+
* Calculate weighted reputation considering history
|
|
136
|
+
*
|
|
137
|
+
* @param baseReputation - Current base reputation
|
|
138
|
+
* @param successCount - Number of successful resolutions
|
|
139
|
+
* @param failureCount - Number of failed/overturned resolutions
|
|
140
|
+
* @returns Weighted reputation score
|
|
141
|
+
*/
|
|
142
|
+
function calculateWeightedReputation(baseReputation, successCount, failureCount) {
|
|
143
|
+
const totalAttempts = successCount + failureCount;
|
|
144
|
+
if (totalAttempts === 0)
|
|
145
|
+
return baseReputation;
|
|
146
|
+
const successRate = successCount / totalAttempts;
|
|
147
|
+
const experienceMultiplier = Math.min(1 + Math.log10(totalAttempts + 1) * 0.2, 1.5);
|
|
148
|
+
return Math.round(baseReputation * successRate * experienceMultiplier);
|
|
149
|
+
}
|
|
150
|
+
exports.calculateWeightedReputation = calculateWeightedReputation;
|
|
151
|
+
/**
|
|
152
|
+
* Check if oracle qualifies for high-value markets
|
|
153
|
+
*/
|
|
154
|
+
function qualifiesForHighValue(reputation, stake, threshold = exports.DEFAULT_ORACLE_CONFIG.highValueThreshold, minStakeMultiplier = 5) {
|
|
155
|
+
return (reputation >= threshold &&
|
|
156
|
+
stake >= exports.DEFAULT_ORACLE_CONFIG.minStake * BigInt(minStakeMultiplier));
|
|
157
|
+
}
|
|
158
|
+
exports.qualifiesForHighValue = qualifiesForHighValue;
|
|
159
|
+
/**
|
|
160
|
+
* Predefined slashing conditions
|
|
161
|
+
*/
|
|
162
|
+
exports.SLASHING_CONDITIONS = {
|
|
163
|
+
[SlashingReason.UNSPECIFIED]: {
|
|
164
|
+
reason: SlashingReason.UNSPECIFIED,
|
|
165
|
+
slashPercent: 0,
|
|
166
|
+
description: 'No slashing',
|
|
167
|
+
appealable: false,
|
|
168
|
+
suspensionEpochs: 0,
|
|
169
|
+
},
|
|
170
|
+
[SlashingReason.TIMEOUT]: {
|
|
171
|
+
reason: SlashingReason.TIMEOUT,
|
|
172
|
+
slashPercent: exports.DEFAULT_ORACLE_CONFIG.timeoutSlashPercent,
|
|
173
|
+
description: 'Failed to submit resolution within deadline',
|
|
174
|
+
appealable: true,
|
|
175
|
+
suspensionEpochs: 12,
|
|
176
|
+
},
|
|
177
|
+
[SlashingReason.INCORRECT_RESOLUTION]: {
|
|
178
|
+
reason: SlashingReason.INCORRECT_RESOLUTION,
|
|
179
|
+
slashPercent: exports.DEFAULT_ORACLE_CONFIG.incorrectSlashPercent,
|
|
180
|
+
description: 'Resolution overturned by dispute process',
|
|
181
|
+
appealable: true,
|
|
182
|
+
suspensionEpochs: 48,
|
|
183
|
+
},
|
|
184
|
+
[SlashingReason.COLLUSION]: {
|
|
185
|
+
reason: SlashingReason.COLLUSION,
|
|
186
|
+
slashPercent: exports.DEFAULT_ORACLE_CONFIG.collusionSlashPercent,
|
|
187
|
+
description: 'Evidence of collusion or market manipulation',
|
|
188
|
+
appealable: false,
|
|
189
|
+
suspensionEpochs: -1, // Permanent
|
|
190
|
+
},
|
|
191
|
+
[SlashingReason.PROTOCOL_VIOLATION]: {
|
|
192
|
+
reason: SlashingReason.PROTOCOL_VIOLATION,
|
|
193
|
+
slashPercent: exports.DEFAULT_ORACLE_CONFIG.violationSlashPercent,
|
|
194
|
+
description: 'Violation of oracle operating protocol',
|
|
195
|
+
appealable: true,
|
|
196
|
+
suspensionEpochs: 24,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Calculate slash amount for a given stake and reason
|
|
201
|
+
*
|
|
202
|
+
* @param stake - Oracle's current stake
|
|
203
|
+
* @param reason - Reason for slashing
|
|
204
|
+
* @returns Amount to be slashed
|
|
205
|
+
*/
|
|
206
|
+
function calculateSlashAmount(stake, reason) {
|
|
207
|
+
const condition = exports.SLASHING_CONDITIONS[reason];
|
|
208
|
+
return (stake * BigInt(Math.floor(condition.slashPercent * 10000))) / 10000n;
|
|
209
|
+
}
|
|
210
|
+
exports.calculateSlashAmount = calculateSlashAmount;
|
|
211
|
+
/**
|
|
212
|
+
* Calculate remaining stake after slashing
|
|
213
|
+
*/
|
|
214
|
+
function calculateStakeAfterSlash(stake, reason) {
|
|
215
|
+
return stake - calculateSlashAmount(stake, reason);
|
|
216
|
+
}
|
|
217
|
+
exports.calculateStakeAfterSlash = calculateStakeAfterSlash;
|
|
218
|
+
/**
|
|
219
|
+
* Calculate oracle selection score
|
|
220
|
+
* Higher score = more likely to be selected
|
|
221
|
+
*
|
|
222
|
+
* @param candidate - Oracle candidate details
|
|
223
|
+
* @param marketValue - Value of market to resolve (affects weight for high-value markets)
|
|
224
|
+
* @returns Selection score
|
|
225
|
+
*/
|
|
226
|
+
function calculateSelectionScore(candidate, marketValue = 0n) {
|
|
227
|
+
const reputationWeight = 0.4;
|
|
228
|
+
const stakeWeight = 0.3;
|
|
229
|
+
const successWeight = 0.2;
|
|
230
|
+
const loadWeight = 0.1;
|
|
231
|
+
// Normalize stake to 0-100 range (assuming 1M max)
|
|
232
|
+
const normalizedStake = Math.min(Number(candidate.stake / 10000n), 100);
|
|
233
|
+
// Load penalty (fewer active = better)
|
|
234
|
+
const loadScore = Math.max(0, 100 - candidate.activeAssignments * 20);
|
|
235
|
+
// High-value market bonus for qualified oracles
|
|
236
|
+
const highValueBonus = marketValue > 100000n &&
|
|
237
|
+
qualifiesForHighValue(candidate.reputation, candidate.stake) ? 10 : 0;
|
|
238
|
+
return (candidate.reputation * reputationWeight +
|
|
239
|
+
normalizedStake * stakeWeight +
|
|
240
|
+
candidate.successRate * 100 * successWeight +
|
|
241
|
+
loadScore * loadWeight +
|
|
242
|
+
highValueBonus);
|
|
243
|
+
}
|
|
244
|
+
exports.calculateSelectionScore = calculateSelectionScore;
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// Reward Calculations
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
/**
|
|
249
|
+
* Calculate oracle reward for successful resolution
|
|
250
|
+
*
|
|
251
|
+
* @param marketFees - Total fees collected from market
|
|
252
|
+
* @param rewardPercent - Oracle's reward percentage (default from config)
|
|
253
|
+
* @returns Oracle reward amount
|
|
254
|
+
*/
|
|
255
|
+
function calculateOracleReward(marketFees, rewardPercent = exports.DEFAULT_ORACLE_CONFIG.oracleRewardPercent) {
|
|
256
|
+
return (marketFees * BigInt(Math.floor(rewardPercent * 10000))) / 10000n;
|
|
257
|
+
}
|
|
258
|
+
exports.calculateOracleReward = calculateOracleReward;
|
|
259
|
+
// ---------------------------------------------------------------------------
|
|
260
|
+
// Type Guards
|
|
261
|
+
// ---------------------------------------------------------------------------
|
|
262
|
+
/**
|
|
263
|
+
* Check if a value is a valid OracleState
|
|
264
|
+
*/
|
|
265
|
+
function isOracleState(value) {
|
|
266
|
+
return typeof value === 'number' && value in oracle_pb_js_1.OracleState;
|
|
267
|
+
}
|
|
268
|
+
exports.isOracleState = isOracleState;
|
|
269
|
+
/**
|
|
270
|
+
* Check if a value is a valid SlashingReason
|
|
271
|
+
*/
|
|
272
|
+
function isSlashingReason(value) {
|
|
273
|
+
return typeof value === 'number' && value in SlashingReason;
|
|
274
|
+
}
|
|
275
|
+
exports.isSlashingReason = isSlashingReason;
|
|
276
|
+
/**
|
|
277
|
+
* Check if a value is a valid ResolutionType
|
|
278
|
+
*/
|
|
279
|
+
function isResolutionType(value) {
|
|
280
|
+
return typeof value === 'number' && value in ResolutionType;
|
|
281
|
+
}
|
|
282
|
+
exports.isResolutionType = isResolutionType;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom Error Classes for OttoChain SDK
|
|
4
|
+
*
|
|
5
|
+
* Provides structured error handling with error codes and causes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.wrapError = exports.isErrorCode = exports.TransactionError = exports.SigningError = exports.ValidationError = exports.NetworkError = exports.OttoChainError = exports.ErrorCode = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Error codes for OttoChain SDK errors
|
|
13
|
+
*/
|
|
14
|
+
var ErrorCode;
|
|
15
|
+
(function (ErrorCode) {
|
|
16
|
+
/** Unknown or unclassified error */
|
|
17
|
+
ErrorCode["UNKNOWN"] = "UNKNOWN";
|
|
18
|
+
/** Network/HTTP connection failure */
|
|
19
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
20
|
+
/** Request timeout */
|
|
21
|
+
ErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
|
|
22
|
+
/** Input validation failed */
|
|
23
|
+
ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
24
|
+
/** Invalid private key format */
|
|
25
|
+
ErrorCode["INVALID_PRIVATE_KEY"] = "INVALID_PRIVATE_KEY";
|
|
26
|
+
/** Invalid public key format */
|
|
27
|
+
ErrorCode["INVALID_PUBLIC_KEY"] = "INVALID_PUBLIC_KEY";
|
|
28
|
+
/** Invalid DAG address format */
|
|
29
|
+
ErrorCode["INVALID_ADDRESS"] = "INVALID_ADDRESS";
|
|
30
|
+
/** Signature creation failed */
|
|
31
|
+
ErrorCode["SIGNING_ERROR"] = "SIGNING_ERROR";
|
|
32
|
+
/** Signature verification failed */
|
|
33
|
+
ErrorCode["VERIFICATION_ERROR"] = "VERIFICATION_ERROR";
|
|
34
|
+
/** Transaction rejected by network */
|
|
35
|
+
ErrorCode["TRANSACTION_REJECTED"] = "TRANSACTION_REJECTED";
|
|
36
|
+
/** Transaction not found */
|
|
37
|
+
ErrorCode["TRANSACTION_NOT_FOUND"] = "TRANSACTION_NOT_FOUND";
|
|
38
|
+
/** Invalid transaction format */
|
|
39
|
+
ErrorCode["INVALID_TRANSACTION"] = "INVALID_TRANSACTION";
|
|
40
|
+
})(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
|
|
41
|
+
/**
|
|
42
|
+
* Base error class for all OttoChain SDK errors
|
|
43
|
+
*
|
|
44
|
+
* Provides consistent error structure with:
|
|
45
|
+
* - Error code for programmatic handling
|
|
46
|
+
* - Human-readable message
|
|
47
|
+
* - Optional cause for error chaining
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* try {
|
|
52
|
+
* await signTransaction(data, invalidKey);
|
|
53
|
+
* } catch (error) {
|
|
54
|
+
* if (error instanceof OttoChainError) {
|
|
55
|
+
* console.log(error.code); // 'INVALID_PRIVATE_KEY'
|
|
56
|
+
* console.log(error.message); // 'Invalid private key format'
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
class OttoChainError extends Error {
|
|
62
|
+
constructor(code, message, cause) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = 'OttoChainError';
|
|
65
|
+
this.code = code;
|
|
66
|
+
this.cause = cause;
|
|
67
|
+
// Maintains proper stack trace for where error was thrown (V8 engines)
|
|
68
|
+
if (Error.captureStackTrace) {
|
|
69
|
+
Error.captureStackTrace(this, this.constructor);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a string representation of the error
|
|
74
|
+
*/
|
|
75
|
+
toString() {
|
|
76
|
+
let result = `${this.name} [${this.code}]: ${this.message}`;
|
|
77
|
+
if (this.cause) {
|
|
78
|
+
result += `\nCaused by: ${this.cause.message}`;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert error to a plain object for logging/serialization
|
|
84
|
+
*/
|
|
85
|
+
toJSON() {
|
|
86
|
+
return {
|
|
87
|
+
name: this.name,
|
|
88
|
+
code: this.code,
|
|
89
|
+
message: this.message,
|
|
90
|
+
cause: this.cause?.message,
|
|
91
|
+
stack: this.stack,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.OttoChainError = OttoChainError;
|
|
96
|
+
/**
|
|
97
|
+
* Error thrown when network operations fail
|
|
98
|
+
*
|
|
99
|
+
* Covers HTTP failures, connection errors, and timeouts.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* try {
|
|
104
|
+
* await client.postTransaction(signed);
|
|
105
|
+
* } catch (error) {
|
|
106
|
+
* if (error instanceof NetworkError) {
|
|
107
|
+
* console.log(error.statusCode); // 503
|
|
108
|
+
* console.log(error.responseBody); // '{"error": "Service unavailable"}'
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
class NetworkError extends OttoChainError {
|
|
114
|
+
constructor(message, statusCode, responseBody, cause) {
|
|
115
|
+
const code = statusCode === undefined ? ErrorCode.NETWORK_ERROR : ErrorCode.NETWORK_ERROR;
|
|
116
|
+
super(code, message, cause);
|
|
117
|
+
this.name = 'NetworkError';
|
|
118
|
+
this.statusCode = statusCode;
|
|
119
|
+
this.responseBody = responseBody;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a timeout error
|
|
123
|
+
*/
|
|
124
|
+
static timeout(timeoutMs) {
|
|
125
|
+
const error = new NetworkError(`Request timed out after ${timeoutMs}ms`);
|
|
126
|
+
error.code = ErrorCode.NETWORK_TIMEOUT;
|
|
127
|
+
return error;
|
|
128
|
+
}
|
|
129
|
+
toJSON() {
|
|
130
|
+
return {
|
|
131
|
+
...super.toJSON(),
|
|
132
|
+
statusCode: this.statusCode,
|
|
133
|
+
responseBody: this.responseBody,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.NetworkError = NetworkError;
|
|
138
|
+
/**
|
|
139
|
+
* Error thrown when input validation fails
|
|
140
|
+
*
|
|
141
|
+
* Used when function parameters don't meet expected format or constraints.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* try {
|
|
146
|
+
* const keyPair = keyPairFromPrivateKey('invalid');
|
|
147
|
+
* } catch (error) {
|
|
148
|
+
* if (error instanceof ValidationError) {
|
|
149
|
+
* console.log(error.field); // 'privateKey'
|
|
150
|
+
* console.log(error.value); // 'invalid'
|
|
151
|
+
* }
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
class ValidationError extends OttoChainError {
|
|
156
|
+
constructor(message, options) {
|
|
157
|
+
super(ErrorCode.VALIDATION_ERROR, message, options?.cause);
|
|
158
|
+
this.name = 'ValidationError';
|
|
159
|
+
this.field = options?.field;
|
|
160
|
+
this.value = options?.value;
|
|
161
|
+
this.details = options?.details;
|
|
162
|
+
}
|
|
163
|
+
toJSON() {
|
|
164
|
+
return {
|
|
165
|
+
...super.toJSON(),
|
|
166
|
+
field: this.field,
|
|
167
|
+
value: this.value,
|
|
168
|
+
details: this.details,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.ValidationError = ValidationError;
|
|
173
|
+
/**
|
|
174
|
+
* Error thrown when cryptographic signing operations fail
|
|
175
|
+
*
|
|
176
|
+
* Covers key derivation, signature creation, and related crypto operations.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* try {
|
|
181
|
+
* const signature = await signHash(hash, privateKey);
|
|
182
|
+
* } catch (error) {
|
|
183
|
+
* if (error instanceof SigningError) {
|
|
184
|
+
* console.log(error.operation); // 'sign'
|
|
185
|
+
* }
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
class SigningError extends OttoChainError {
|
|
190
|
+
constructor(message, options) {
|
|
191
|
+
super(ErrorCode.SIGNING_ERROR, message, options?.cause);
|
|
192
|
+
this.name = 'SigningError';
|
|
193
|
+
this.operation = options?.operation;
|
|
194
|
+
}
|
|
195
|
+
toJSON() {
|
|
196
|
+
return {
|
|
197
|
+
...super.toJSON(),
|
|
198
|
+
operation: this.operation,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.SigningError = SigningError;
|
|
203
|
+
/**
|
|
204
|
+
* Error thrown when transaction operations fail
|
|
205
|
+
*
|
|
206
|
+
* Used when transactions are rejected, not found, or invalid.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* try {
|
|
211
|
+
* await client.postTransaction(signed);
|
|
212
|
+
* } catch (error) {
|
|
213
|
+
* if (error instanceof TransactionError) {
|
|
214
|
+
* console.log(error.transactionHash); // 'abc123...'
|
|
215
|
+
* console.log(error.rejectionReason); // 'Insufficient balance'
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
class TransactionError extends OttoChainError {
|
|
221
|
+
constructor(code, message, options) {
|
|
222
|
+
super(code, message, options?.cause);
|
|
223
|
+
this.name = 'TransactionError';
|
|
224
|
+
this.transactionHash = options?.transactionHash;
|
|
225
|
+
this.rejectionReason = options?.rejectionReason;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a transaction rejected error
|
|
229
|
+
*/
|
|
230
|
+
static rejected(reason, transactionHash) {
|
|
231
|
+
return new TransactionError(ErrorCode.TRANSACTION_REJECTED, `Transaction rejected: ${reason}`, {
|
|
232
|
+
transactionHash,
|
|
233
|
+
rejectionReason: reason,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a transaction not found error
|
|
238
|
+
*/
|
|
239
|
+
static notFound(transactionHash) {
|
|
240
|
+
return new TransactionError(ErrorCode.TRANSACTION_NOT_FOUND, `Transaction not found: ${transactionHash}`, {
|
|
241
|
+
transactionHash,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create an invalid transaction error
|
|
246
|
+
*/
|
|
247
|
+
static invalid(message, cause) {
|
|
248
|
+
return new TransactionError(ErrorCode.INVALID_TRANSACTION, message, { cause });
|
|
249
|
+
}
|
|
250
|
+
toJSON() {
|
|
251
|
+
return {
|
|
252
|
+
...super.toJSON(),
|
|
253
|
+
transactionHash: this.transactionHash,
|
|
254
|
+
rejectionReason: this.rejectionReason,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.TransactionError = TransactionError;
|
|
259
|
+
/**
|
|
260
|
+
* Check if an error is an OttoChain error with a specific code
|
|
261
|
+
*
|
|
262
|
+
* @param error - Error to check
|
|
263
|
+
* @param code - Error code to match
|
|
264
|
+
* @returns True if error matches the code
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* if (isErrorCode(error, ErrorCode.NETWORK_TIMEOUT)) {
|
|
269
|
+
* // Retry the request
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
function isErrorCode(error, code) {
|
|
274
|
+
return error instanceof OttoChainError && error.code === code;
|
|
275
|
+
}
|
|
276
|
+
exports.isErrorCode = isErrorCode;
|
|
277
|
+
/**
|
|
278
|
+
* Wrap an unknown error in an OttoChainError
|
|
279
|
+
*
|
|
280
|
+
* @param error - Error to wrap
|
|
281
|
+
* @param defaultMessage - Default message if error has no message
|
|
282
|
+
* @returns OttoChainError wrapping the original error
|
|
283
|
+
*/
|
|
284
|
+
function wrapError(error, defaultMessage = 'An error occurred') {
|
|
285
|
+
if (error instanceof OttoChainError) {
|
|
286
|
+
return error;
|
|
287
|
+
}
|
|
288
|
+
if (error instanceof Error) {
|
|
289
|
+
return new OttoChainError(ErrorCode.UNKNOWN, error.message || defaultMessage, error);
|
|
290
|
+
}
|
|
291
|
+
return new OttoChainError(ErrorCode.UNKNOWN, String(error) || defaultMessage);
|
|
292
|
+
}
|
|
293
|
+
exports.wrapError = wrapError;
|