crypto-aio 0.2.0 → 1.0.0-rc.1

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.
Files changed (162) hide show
  1. package/CHANGELOG.md +70 -2
  2. package/README.md +16 -10
  3. package/dist/adapters/avalanche/driver.d.ts +4 -0
  4. package/dist/adapters/avalanche/driver.js.map +1 -1
  5. package/dist/adapters/avalanche/sdk.d.ts +15 -0
  6. package/dist/adapters/avalanche/sdk.js.map +1 -1
  7. package/dist/adapters/evm/plugin.d.ts +1 -0
  8. package/dist/adapters/evm/plugin.js.map +1 -1
  9. package/dist/adapters/ton/network.d.ts +1 -0
  10. package/dist/adapters/ton/network.js +1 -0
  11. package/dist/adapters/ton/network.js.map +1 -1
  12. package/dist/adapters/ton/types.d.ts +1 -0
  13. package/dist/adapters/ton/types.js.map +1 -1
  14. package/dist/adapters/tron/decode.js +3 -2
  15. package/dist/adapters/tron/decode.js.map +1 -1
  16. package/dist/adapters/tron/http.d.ts +6 -0
  17. package/dist/adapters/tron/http.js +9 -0
  18. package/dist/adapters/tron/http.js.map +1 -1
  19. package/dist/adapters/tron/network.d.ts +4 -0
  20. package/dist/adapters/tron/network.js +4 -0
  21. package/dist/adapters/tron/network.js.map +1 -1
  22. package/dist/adapters/tron/proofs.js +6 -2
  23. package/dist/adapters/tron/proofs.js.map +1 -1
  24. package/dist/adapters/tron/reader.js +1 -1
  25. package/dist/adapters/tron/reader.js.map +1 -1
  26. package/dist/adapters/utxo/driver.d.ts +4 -0
  27. package/dist/adapters/utxo/driver.js.map +1 -1
  28. package/dist/adapters/utxo/esplora.d.ts +6 -0
  29. package/dist/adapters/utxo/esplora.js +20 -3
  30. package/dist/adapters/utxo/esplora.js.map +1 -1
  31. package/dist/adapters/utxo/types.d.ts +1 -0
  32. package/dist/adapters/utxo/types.js.map +1 -1
  33. package/dist/core/blockchain/handle.d.ts +6 -1
  34. package/dist/core/blockchain/handle.js +1 -1
  35. package/dist/core/blockchain/handle.js.map +1 -1
  36. package/dist/core/config/types.d.ts +64 -0
  37. package/dist/core/config/types.js.map +1 -1
  38. package/dist/core/container/container.d.ts +3 -0
  39. package/dist/core/container/container.js.map +1 -1
  40. package/dist/core/container/pool.js +12 -0
  41. package/dist/core/container/pool.js.map +1 -1
  42. package/dist/core/driver/types.d.ts +124 -7
  43. package/dist/core/driver/types.js.map +1 -1
  44. package/dist/core/errors/codes.d.ts +3 -0
  45. package/dist/core/errors/codes.js.map +1 -1
  46. package/dist/core/errors/error.d.ts +26 -0
  47. package/dist/core/errors/error.js +20 -0
  48. package/dist/core/errors/error.js.map +1 -1
  49. package/dist/core/events/logger.d.ts +17 -1
  50. package/dist/core/events/logger.js +5 -1
  51. package/dist/core/events/logger.js.map +1 -1
  52. package/dist/core/events/types.d.ts +26 -1
  53. package/dist/core/events/types.js.map +1 -1
  54. package/dist/core/lifecycle/engine.d.ts +5 -0
  55. package/dist/core/lifecycle/engine.js.map +1 -1
  56. package/dist/core/lifecycle/monitor.d.ts +6 -0
  57. package/dist/core/lifecycle/monitor.js.map +1 -1
  58. package/dist/core/lifecycle/views.d.ts +5 -0
  59. package/dist/core/lifecycle/views.js.map +1 -1
  60. package/dist/core/lifecycle/workers.d.ts +1 -0
  61. package/dist/core/lifecycle/workers.js.map +1 -1
  62. package/dist/core/model/address.d.ts +4 -0
  63. package/dist/core/model/address.js.map +1 -1
  64. package/dist/core/model/amount.d.ts +5 -0
  65. package/dist/core/model/amount.js.map +1 -1
  66. package/dist/core/model/asset.d.ts +11 -0
  67. package/dist/core/model/asset.js +2 -0
  68. package/dist/core/model/asset.js.map +1 -1
  69. package/dist/core/model/capability.d.ts +6 -0
  70. package/dist/core/model/capability.js +4 -0
  71. package/dist/core/model/capability.js.map +1 -1
  72. package/dist/core/model/chain.d.ts +19 -0
  73. package/dist/core/model/chain.js +1 -0
  74. package/dist/core/model/chain.js.map +1 -1
  75. package/dist/core/model/fee.d.ts +24 -1
  76. package/dist/core/model/fee.js.map +1 -1
  77. package/dist/core/model/ids.d.ts +10 -7
  78. package/dist/core/model/ids.js +1 -0
  79. package/dist/core/model/ids.js.map +1 -1
  80. package/dist/core/model/intent.d.ts +13 -0
  81. package/dist/core/model/intent.js.map +1 -1
  82. package/dist/core/model/ordering.d.ts +5 -0
  83. package/dist/core/model/ordering.js.map +1 -1
  84. package/dist/core/model/transaction.d.ts +39 -0
  85. package/dist/core/model/transaction.js.map +1 -1
  86. package/dist/core/observe/scanner.d.ts +10 -1
  87. package/dist/core/observe/scanner.js +6 -0
  88. package/dist/core/observe/scanner.js.map +1 -1
  89. package/dist/core/registry/assets.d.ts +5 -0
  90. package/dist/core/registry/assets.js.map +1 -1
  91. package/dist/core/registry/plugin.d.ts +6 -1
  92. package/dist/core/registry/plugin.js.map +1 -1
  93. package/dist/core/registry/providers.d.ts +5 -0
  94. package/dist/core/registry/providers.js.map +1 -1
  95. package/dist/core/registry/schemes.d.ts +7 -0
  96. package/dist/core/registry/schemes.js.map +1 -1
  97. package/dist/core/secret/redact.d.ts +9 -0
  98. package/dist/core/secret/redact.js +9 -0
  99. package/dist/core/secret/redact.js.map +1 -1
  100. package/dist/core/secret/secret.d.ts +4 -0
  101. package/dist/core/secret/secret.js +4 -0
  102. package/dist/core/secret/secret.js.map +1 -1
  103. package/dist/core/signing/callback.d.ts +5 -0
  104. package/dist/core/signing/callback.js.map +1 -1
  105. package/dist/core/signing/hd.d.ts +4 -0
  106. package/dist/core/signing/hd.js.map +1 -1
  107. package/dist/core/signing/local.d.ts +17 -0
  108. package/dist/core/signing/local.js +5 -0
  109. package/dist/core/signing/local.js.map +1 -1
  110. package/dist/core/signing/types.d.ts +35 -1
  111. package/dist/core/signing/types.js.map +1 -1
  112. package/dist/core/store/format.d.ts +3 -3
  113. package/dist/core/store/format.js +18 -8
  114. package/dist/core/store/format.js.map +1 -1
  115. package/dist/core/store/memory.d.ts +11 -0
  116. package/dist/core/store/memory.js +11 -0
  117. package/dist/core/store/memory.js.map +1 -1
  118. package/dist/core/store/types.d.ts +164 -3
  119. package/dist/core/store/types.js +4 -0
  120. package/dist/core/store/types.js.map +1 -1
  121. package/dist/core/transport/http-transport.js +33 -13
  122. package/dist/core/transport/http-transport.js.map +1 -1
  123. package/dist/core/transport/types.d.ts +70 -0
  124. package/dist/core/transport/types.js.map +1 -1
  125. package/dist/core/util/clock.d.ts +6 -0
  126. package/dist/core/util/clock.js.map +1 -1
  127. package/dist/core/util/json.d.ts +6 -0
  128. package/dist/core/util/json.js +21 -8
  129. package/dist/core/util/json.js.map +1 -1
  130. package/dist/testing/contracts/api.d.ts +1 -0
  131. package/dist/testing/contracts/api.js +1 -0
  132. package/dist/testing/contracts/api.js.map +1 -1
  133. package/dist/testing/contracts/cursors.d.ts +5 -0
  134. package/dist/testing/contracts/cursors.js +4 -0
  135. package/dist/testing/contracts/cursors.js.map +1 -1
  136. package/dist/testing/contracts/locks.d.ts +6 -0
  137. package/dist/testing/contracts/locks.js +5 -0
  138. package/dist/testing/contracts/locks.js.map +1 -1
  139. package/dist/testing/contracts/operations.d.ts +11 -0
  140. package/dist/testing/contracts/operations.js +10 -0
  141. package/dist/testing/contracts/operations.js.map +1 -1
  142. package/dist/testing/contracts/sequences.d.ts +5 -0
  143. package/dist/testing/contracts/sequences.js +4 -0
  144. package/dist/testing/contracts/sequences.js.map +1 -1
  145. package/dist/testing/env.d.ts +11 -0
  146. package/dist/testing/env.js +1 -0
  147. package/dist/testing/env.js.map +1 -1
  148. package/dist/testing/fake-chain.d.ts +32 -0
  149. package/dist/testing/fake-chain.js +11 -0
  150. package/dist/testing/fake-chain.js.map +1 -1
  151. package/dist/testing/fake-driver.d.ts +2 -0
  152. package/dist/testing/fake-driver.js.map +1 -1
  153. package/dist/testing/fake-fetch.d.ts +6 -0
  154. package/dist/testing/fake-fetch.js +2 -0
  155. package/dist/testing/fake-fetch.js.map +1 -1
  156. package/dist/testing/fake-plugin.d.ts +2 -0
  157. package/dist/testing/fake-plugin.js +2 -0
  158. package/dist/testing/fake-plugin.js.map +1 -1
  159. package/dist/testing/faulty-store.d.ts +2 -0
  160. package/dist/testing/faulty-store.js +1 -0
  161. package/dist/testing/faulty-store.js.map +1 -1
  162. package/package.json +5 -5
@@ -5,12 +5,21 @@ exports.createError = createError;
5
5
  exports.isCryptoAioError = isCryptoAioError;
6
6
  exports.withContext = withContext;
7
7
  const codes_1 = require("./codes");
8
+ /**
9
+ * Every failure the library reports. Match on `code` and `category`, and on the `details`
10
+ * and `context` fields the Errors reference lists; message texts are not covered by
11
+ * semver.
12
+ */
8
13
  class CryptoAioError extends Error {
9
14
  code;
10
15
  category;
16
+ /** Whether the same call may succeed if made again. */
11
17
  retryable;
18
+ /** Whether the call may have reached the chain, so its effect is unknown. */
12
19
  ambiguous;
20
+ /** Redacted ids of where it happened, such as `operationId`. */
13
21
  context;
22
+ /** Code-specific facts, such as `required` and `available` for `INSUFFICIENT_FUNDS`. */
14
23
  details;
15
24
  constructor(code, message, options = {}) {
16
25
  super(message, options.cause === undefined ? undefined : { cause: options.cause });
@@ -24,6 +33,7 @@ class CryptoAioError extends Error {
24
33
  if (options.details)
25
34
  this.details = Object.freeze({ ...options.details });
26
35
  }
36
+ /** The error as plain data, without its stack or cause. */
27
37
  toJSON() {
28
38
  return {
29
39
  name: this.name,
@@ -38,48 +48,56 @@ class CryptoAioError extends Error {
38
48
  }
39
49
  }
40
50
  exports.CryptoAioError = CryptoAioError;
51
+ /** A configuration that cannot work: an invalid option, a missing SDK package, an incompatible selection. */
41
52
  class ConfigError extends CryptoAioError {
42
53
  constructor(code, message, options) {
43
54
  super(code, message, options);
44
55
  }
45
56
  }
46
57
  exports.ConfigError = ConfigError;
58
+ /** An operation the selected chain, network or library does not support. */
47
59
  class UnsupportedCapabilityError extends CryptoAioError {
48
60
  constructor(code, message, options) {
49
61
  super(code, message, options);
50
62
  }
51
63
  }
52
64
  exports.UnsupportedCapabilityError = UnsupportedCapabilityError;
65
+ /** An input that is not valid: an address, an amount, an asset or an intent. */
53
66
  class ValidationError extends CryptoAioError {
54
67
  constructor(code, message, options) {
55
68
  super(code, message, options);
56
69
  }
57
70
  }
58
71
  exports.ValidationError = ValidationError;
72
+ /** A failure of the endpoints: unavailable, rate-limited, misconfigured, inconsistent, or a definitive refusal. */
59
73
  class ProviderError extends CryptoAioError {
60
74
  constructor(code, message, options) {
61
75
  super(code, message, options);
62
76
  }
63
77
  }
64
78
  exports.ProviderError = ProviderError;
79
+ /** An answer of the chain about a transaction: funds, nonce, fee, refusal, revert, expiry, replacement. */
65
80
  class ChainError extends CryptoAioError {
66
81
  constructor(code, message, options) {
67
82
  super(code, message, options);
68
83
  }
69
84
  }
70
85
  exports.ChainError = ChainError;
86
+ /** A failure to sign: no signer, a failed or mismatched signature, a policy veto, a key that cannot be exported. */
71
87
  class SigningError extends CryptoAioError {
72
88
  constructor(code, message, options) {
73
89
  super(code, message, options);
74
90
  }
75
91
  }
76
92
  exports.SigningError = SigningError;
93
+ /** A conflict with stored state: idempotency, fencing, versions, transitions, leases, record formats. */
77
94
  class StateError extends CryptoAioError {
78
95
  constructor(code, message, options) {
79
96
  super(code, message, options);
80
97
  }
81
98
  }
82
99
  exports.StateError = StateError;
100
+ /** A call that ran out of time. */
83
101
  class TimeoutError extends CryptoAioError {
84
102
  constructor(code, message, options) {
85
103
  super(code, message, options);
@@ -96,10 +114,12 @@ const BY_CATEGORY = {
96
114
  state: StateError,
97
115
  timeout: TimeoutError,
98
116
  };
117
+ /** An error of `code`'s class. */
99
118
  function createError(code, message, options) {
100
119
  const Ctor = BY_CATEGORY[codes_1.ERROR_CODES[code].category];
101
120
  return new Ctor(code, message, options);
102
121
  }
122
+ /** Whether `value` is a `CryptoAioError`, of `code` when given. */
103
123
  function isCryptoAioError(value, code) {
104
124
  return value instanceof CryptoAioError && (code === undefined || value.code === code);
105
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/core/errors/error.ts"],"names":[],"mappings":";;;AA0IA,kCAOC;AAED,4C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AAE;QAC/C,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE;QACzC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;QACjD,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;KAClD,CAAC,CAAC;IACH,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE;YACnC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { ERROR_CODES, type CodesOf, type ErrorCategory, type ErrorCode } from './codes';\n\nexport type { CodesOf, ErrorCategory, ErrorCode } from './codes';\n\nexport type ErrorContextValue = string | number | boolean | undefined;\nexport type ErrorContext = Readonly<Record<string, ErrorContextValue>>;\n\nexport interface CryptoAioErrorOptions {\n readonly cause?: unknown;\n readonly context?: ErrorContext;\n readonly details?: Readonly<Record<string, unknown>>;\n readonly retryable?: boolean;\n readonly ambiguous?: boolean;\n}\n\nexport interface SerializedError {\n readonly name: string;\n readonly code: ErrorCode;\n readonly category: ErrorCategory;\n readonly message: string;\n readonly retryable: boolean;\n readonly ambiguous: boolean;\n readonly context: ErrorContext;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\nexport class CryptoAioError extends Error {\n readonly code: ErrorCode;\n readonly category: ErrorCategory;\n readonly retryable: boolean;\n readonly ambiguous: boolean;\n readonly context: ErrorContext;\n readonly details?: Readonly<Record<string, unknown>>;\n\n constructor(code: ErrorCode, message: string, options: CryptoAioErrorOptions = {}) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = new.target.name;\n const definition = ERROR_CODES[code];\n this.code = code;\n this.category = definition.category;\n this.retryable = options.retryable ?? definition.retryable;\n this.ambiguous = options.ambiguous ?? false;\n this.context = Object.freeze({ ...options.context });\n if (options.details) this.details = Object.freeze({ ...options.details });\n }\n\n toJSON(): SerializedError {\n return {\n name: this.name,\n code: this.code,\n category: this.category,\n message: this.message,\n retryable: this.retryable,\n ambiguous: this.ambiguous,\n context: this.context,\n ...(this.details ? { details: this.details } : {}),\n };\n }\n}\n\nexport class ConfigError extends CryptoAioError {\n constructor(code: CodesOf<'config'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\nexport class UnsupportedCapabilityError extends CryptoAioError {\n constructor(\n code: CodesOf<'unsupported'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\nexport class ValidationError extends CryptoAioError {\n constructor(\n code: CodesOf<'validation'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\nexport class ProviderError extends CryptoAioError {\n constructor(\n code: CodesOf<'provider'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\nexport class ChainError extends CryptoAioError {\n constructor(code: CodesOf<'chain'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\nexport class SigningError extends CryptoAioError {\n constructor(\n code: CodesOf<'signing'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\nexport class StateError extends CryptoAioError {\n constructor(code: CodesOf<'state'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\nexport class TimeoutError extends CryptoAioError {\n constructor(\n code: CodesOf<'timeout'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n\ntype AnyErrorConstructor = new (\n code: ErrorCode,\n message: string,\n options?: CryptoAioErrorOptions,\n) => CryptoAioError;\n\nconst BY_CATEGORY: Record<ErrorCategory, AnyErrorConstructor> = {\n config: ConfigError as AnyErrorConstructor,\n unsupported: UnsupportedCapabilityError as AnyErrorConstructor,\n validation: ValidationError as AnyErrorConstructor,\n provider: ProviderError as AnyErrorConstructor,\n chain: ChainError as AnyErrorConstructor,\n signing: SigningError as AnyErrorConstructor,\n state: StateError as AnyErrorConstructor,\n timeout: TimeoutError as AnyErrorConstructor,\n};\n\nexport function createError(\n code: ErrorCode,\n message: string,\n options?: CryptoAioErrorOptions,\n): CryptoAioError {\n const Ctor = BY_CATEGORY[ERROR_CODES[code].category];\n return new Ctor(code, message, options);\n}\n\nexport function isCryptoAioError(\n value: unknown,\n code?: ErrorCode,\n): value is CryptoAioError {\n return value instanceof CryptoAioError && (code === undefined || value.code === code);\n}\n\n/**\n * Returns a copy of `error` (same class, same stack) with merged context, and optional flag\n * and `details` overrides. The copy keeps the stack of the error it reports.\n */\nexport function withContext(\n error: CryptoAioError,\n context: ErrorContext,\n overrides: {\n readonly ambiguous?: boolean;\n readonly retryable?: boolean;\n readonly details?: Readonly<Record<string, unknown>>;\n } = {},\n): CryptoAioError {\n const Ctor = error.constructor as AnyErrorConstructor;\n const details = overrides.details ?? error.details;\n const copy = new Ctor(error.code, error.message, {\n cause: error.cause,\n context: { ...error.context, ...context },\n ...(details ? { details } : {}),\n retryable: overrides.retryable ?? error.retryable,\n ambiguous: overrides.ambiguous ?? error.ambiguous,\n });\n if (error.stack !== undefined) {\n Object.defineProperty(copy, 'stack', {\n value: error.stack,\n writable: true,\n configurable: true,\n });\n }\n return copy;\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/core/errors/error.ts"],"names":[],"mappings":";;;AAmKA,kCAOC;AAGD,4CAKC;AAMD,kCA0BC;AAlND,mCAAwF;AAgCxF;;;;GAIG;AACH,MAAa,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAY;IAChB,QAAQ,CAAgB;IACjC,uDAAu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K,CAAC,OAAO,CAAC;IACnD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE;QAC/C,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE;QACzC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;QACjD,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;KAClD,CAAC,CAAC;IACH,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE;YACnC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { ERROR_CODES, type CodesOf, type ErrorCategory, type ErrorCode } from './codes';\n\nexport type { CodesOf, ErrorCategory, ErrorCode } from './codes';\n\n/** One value of an error's `context`. */\nexport type ErrorContextValue = string | number | boolean | undefined;\n/** Redacted identifiers of where an error happened, such as `operationId` or `endpointId`. */\nexport type ErrorContext = Readonly<Record<string, ErrorContextValue>>;\n\n/** What an error is made with, besides its code and message. */\nexport interface CryptoAioErrorOptions {\n readonly cause?: unknown;\n readonly context?: ErrorContext;\n readonly details?: Readonly<Record<string, unknown>>;\n /** Overrides the code's default `retryable` flag. */\n readonly retryable?: boolean;\n /** Whether the call may have reached the chain (default `false`). */\n readonly ambiguous?: boolean;\n}\n\n/** An error as JSON (`toJSON()`), as an Operation stores it. */\nexport interface SerializedError {\n readonly name: string;\n readonly code: ErrorCode;\n readonly category: ErrorCategory;\n readonly message: string;\n readonly retryable: boolean;\n readonly ambiguous: boolean;\n readonly context: ErrorContext;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Every failure the library reports. Match on `code` and `category`, and on the `details`\n * and `context` fields the Errors reference lists; message texts are not covered by\n * semver.\n */\nexport class CryptoAioError extends Error {\n readonly code: ErrorCode;\n readonly category: ErrorCategory;\n /** Whether the same call may succeed if made again. */\n readonly retryable: boolean;\n /** Whether the call may have reached the chain, so its effect is unknown. */\n readonly ambiguous: boolean;\n /** Redacted ids of where it happened, such as `operationId`. */\n readonly context: ErrorContext;\n /** Code-specific facts, such as `required` and `available` for `INSUFFICIENT_FUNDS`. */\n readonly details?: Readonly<Record<string, unknown>>;\n\n constructor(code: ErrorCode, message: string, options: CryptoAioErrorOptions = {}) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = new.target.name;\n const definition = ERROR_CODES[code];\n this.code = code;\n this.category = definition.category;\n this.retryable = options.retryable ?? definition.retryable;\n this.ambiguous = options.ambiguous ?? false;\n this.context = Object.freeze({ ...options.context });\n if (options.details) this.details = Object.freeze({ ...options.details });\n }\n\n /** The error as plain data, without its stack or cause. */\n toJSON(): SerializedError {\n return {\n name: this.name,\n code: this.code,\n category: this.category,\n message: this.message,\n retryable: this.retryable,\n ambiguous: this.ambiguous,\n context: this.context,\n ...(this.details ? { details: this.details } : {}),\n };\n }\n}\n\n/** A configuration that cannot work: an invalid option, a missing SDK package, an incompatible selection. */\nexport class ConfigError extends CryptoAioError {\n constructor(code: CodesOf<'config'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\n/** An operation the selected chain, network or library does not support. */\nexport class UnsupportedCapabilityError extends CryptoAioError {\n constructor(\n code: CodesOf<'unsupported'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n/** An input that is not valid: an address, an amount, an asset or an intent. */\nexport class ValidationError extends CryptoAioError {\n constructor(\n code: CodesOf<'validation'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n/** A failure of the endpoints: unavailable, rate-limited, misconfigured, inconsistent, or a definitive refusal. */\nexport class ProviderError extends CryptoAioError {\n constructor(\n code: CodesOf<'provider'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n/** An answer of the chain about a transaction: funds, nonce, fee, refusal, revert, expiry, replacement. */\nexport class ChainError extends CryptoAioError {\n constructor(code: CodesOf<'chain'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\n/** A failure to sign: no signer, a failed or mismatched signature, a policy veto, a key that cannot be exported. */\nexport class SigningError extends CryptoAioError {\n constructor(\n code: CodesOf<'signing'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n/** A conflict with stored state: idempotency, fencing, versions, transitions, leases, record formats. */\nexport class StateError extends CryptoAioError {\n constructor(code: CodesOf<'state'>, message: string, options?: CryptoAioErrorOptions) {\n super(code, message, options);\n }\n}\n/** A call that ran out of time. */\nexport class TimeoutError extends CryptoAioError {\n constructor(\n code: CodesOf<'timeout'>,\n message: string,\n options?: CryptoAioErrorOptions,\n ) {\n super(code, message, options);\n }\n}\n\ntype AnyErrorConstructor = new (\n code: ErrorCode,\n message: string,\n options?: CryptoAioErrorOptions,\n) => CryptoAioError;\n\nconst BY_CATEGORY: Record<ErrorCategory, AnyErrorConstructor> = {\n config: ConfigError as AnyErrorConstructor,\n unsupported: UnsupportedCapabilityError as AnyErrorConstructor,\n validation: ValidationError as AnyErrorConstructor,\n provider: ProviderError as AnyErrorConstructor,\n chain: ChainError as AnyErrorConstructor,\n signing: SigningError as AnyErrorConstructor,\n state: StateError as AnyErrorConstructor,\n timeout: TimeoutError as AnyErrorConstructor,\n};\n\n/** An error of `code`'s class. */\nexport function createError(\n code: ErrorCode,\n message: string,\n options?: CryptoAioErrorOptions,\n): CryptoAioError {\n const Ctor = BY_CATEGORY[ERROR_CODES[code].category];\n return new Ctor(code, message, options);\n}\n\n/** Whether `value` is a `CryptoAioError`, of `code` when given. */\nexport function isCryptoAioError(\n value: unknown,\n code?: ErrorCode,\n): value is CryptoAioError {\n return value instanceof CryptoAioError && (code === undefined || value.code === code);\n}\n\n/**\n * Returns a copy of `error` (same class, same stack) with merged context, and optional flag\n * and `details` overrides. The copy keeps the stack of the error it reports.\n */\nexport function withContext(\n error: CryptoAioError,\n context: ErrorContext,\n overrides: {\n readonly ambiguous?: boolean;\n readonly retryable?: boolean;\n readonly details?: Readonly<Record<string, unknown>>;\n } = {},\n): CryptoAioError {\n const Ctor = error.constructor as AnyErrorConstructor;\n const details = overrides.details ?? error.details;\n const copy = new Ctor(error.code, error.message, {\n cause: error.cause,\n context: { ...error.context, ...context },\n ...(details ? { details } : {}),\n retryable: overrides.retryable ?? error.retryable,\n ambiguous: overrides.ambiguous ?? error.ambiguous,\n });\n if (error.stack !== undefined) {\n Object.defineProperty(copy, 'stack', {\n value: error.stack,\n writable: true,\n configurable: true,\n });\n }\n return copy;\n}\n"]}
@@ -1,13 +1,29 @@
1
+ /** A log entry's severity. */
1
2
  export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ /** A log entry's structured fields. */
2
4
  export type LogFields = Readonly<Record<string, unknown>>;
5
+ /**
6
+ * Where the library logs (`AioOptions.logger`). A port you may implement: it never gains a
7
+ * required member in a 1.x release. `createLogger` builds one that redacts before writing;
8
+ * one of your own should redact too, since fields can carry endpoint URLs.
9
+ */
3
10
  export interface Logger {
4
11
  debug(message: string, fields?: LogFields): void;
5
12
  info(message: string, fields?: LogFields): void;
6
13
  warn(message: string, fields?: LogFields): void;
7
14
  error(message: string, fields?: LogFields): void;
15
+ /** A logger for a sub-namespace, such as `transport`. */
8
16
  child(namespace: string): Logger;
9
17
  }
18
+ /**
19
+ * Writes one redacted entry, for `createLogger`. A port you may implement: it never gains
20
+ * a required parameter in a 1.x release.
21
+ */
10
22
  export type LogWriter = (level: LogLevel, namespace: string, message: string, fields?: Record<string, unknown>) => void;
11
- /** Structured logger; fields are always redacted before they reach the writer. */
23
+ /**
24
+ * Structured logger; fields are always redacted before they reach the writer. The default
25
+ * writer logs through `debug` under `<namespace>:<level>`.
26
+ */
12
27
  export declare function createLogger(namespace?: string, write?: LogWriter): Logger;
28
+ /** A logger that drops everything. */
13
29
  export declare const noopLogger: Logger;
@@ -20,7 +20,10 @@ const debugWriter = (level, namespace, message, fields) => {
20
20
  else
21
21
  log('%s', message);
22
22
  };
23
- /** Structured logger; fields are always redacted before they reach the writer. */
23
+ /**
24
+ * Structured logger; fields are always redacted before they reach the writer. The default
25
+ * writer logs through `debug` under `<namespace>:<level>`.
26
+ */
24
27
  function createLogger(namespace = 'crypto-aio', write = debugWriter) {
25
28
  const emit = (level) => (message, fields) => write(level, namespace, (0, redact_1.redactText)(message), fields ? (0, redact_1.redactDeep)(fields) : undefined);
26
29
  return {
@@ -32,6 +35,7 @@ function createLogger(namespace = 'crypto-aio', write = debugWriter) {
32
35
  };
33
36
  }
34
37
  const noop = () => undefined;
38
+ /** A logger that drops everything. */
35
39
  exports.noopLogger = {
36
40
  debug: noop,
37
41
  info: noop,
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/core/events/logger.ts"],"names":[],"mappings":";;;;;;AAmCA,oCAkBC;AArDD,kDAAgC;AAChC,6CAA0D;AAoB1D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;AAE1D,MAAM,WAAW,GAAc,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,IAAI,GAAG,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC;IACrC,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,IAAA,eAAW,EAAC,IAAI,CAAC,CAAC;QACxB,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;;QACvE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,kFAAkF;AAClF,SAAgB,YAAY,CAC1B,SAAS,GAAG,YAAY,EACxB,QAAmB,WAAW;IAE9B,MAAM,IAAI,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC,OAAe,EAAE,MAAkB,EAAE,EAAE,CACxE,KAAK,CACH,KAAK,EACL,SAAS,EACT,IAAA,mBAAU,EAAC,OAAO,CAAC,EACnB,MAAM,CAAC,CAAC,CAAE,IAAA,mBAAU,EAAC,MAAM,CAA6B,CAAC,CAAC,CAAC,SAAS,CACrE,CAAC;IACJ,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;QACpB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;QACpB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,SAAS,IAAI,KAAK,EAAE,EAAE,KAAK,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AAEtB,QAAA,UAAU,GAAW;IAChC,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,GAAG,EAAE,CAAC,kBAAU;CACxB,CAAC","sourcesContent":["import createDebug from 'debug';\nimport { redactDeep, redactText } from '../secret/redact';\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\nexport type LogFields = Readonly<Record<string, unknown>>;\n\nexport interface Logger {\n debug(message: string, fields?: LogFields): void;\n info(message: string, fields?: LogFields): void;\n warn(message: string, fields?: LogFields): void;\n error(message: string, fields?: LogFields): void;\n child(namespace: string): Logger;\n}\n\nexport type LogWriter = (\n level: LogLevel,\n namespace: string,\n message: string,\n fields?: Record<string, unknown>,\n) => void;\n\nconst debuggers = new Map<string, createDebug.Debugger>();\n\nconst debugWriter: LogWriter = (level, namespace, message, fields) => {\n const name = `${namespace}:${level}`;\n let log = debuggers.get(name);\n if (!log) {\n log = createDebug(name);\n debuggers.set(name, log);\n }\n if (fields && Object.keys(fields).length > 0) log('%s %o', message, fields);\n else log('%s', message);\n};\n\n/** Structured logger; fields are always redacted before they reach the writer. */\nexport function createLogger(\n namespace = 'crypto-aio',\n write: LogWriter = debugWriter,\n): Logger {\n const emit = (level: LogLevel) => (message: string, fields?: LogFields) =>\n write(\n level,\n namespace,\n redactText(message),\n fields ? (redactDeep(fields) as Record<string, unknown>) : undefined,\n );\n return {\n debug: emit('debug'),\n info: emit('info'),\n warn: emit('warn'),\n error: emit('error'),\n child: (child) => createLogger(`${namespace}:${child}`, write),\n };\n}\n\nconst noop = (): void => undefined;\n\nexport const noopLogger: Logger = {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n child: () => noopLogger,\n};\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/core/events/logger.ts"],"names":[],"mappings":";;;;;;AAkDA,oCAkBC;AApED,kDAAgC;AAChC,6CAA0D;AAgC1D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;AAE1D,MAAM,WAAW,GAAc,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,IAAI,GAAG,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC;IACrC,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAA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AAG,EAAE,CAAC,kBAAU;CACxB,CAAC","sourcesContent":["import createDebug from 'debug';\nimport { redactDeep, redactText } from '../secret/redact';\n\n/** A log entry's severity. */\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n/** A log entry's structured fields. */\nexport type LogFields = Readonly<Record<string, unknown>>;\n\n/**\n * Where the library logs (`AioOptions.logger`). A port you may implement: it never gains a\n * required member in a 1.x release. `createLogger` builds one that redacts before writing;\n * one of your own should redact too, since fields can carry endpoint URLs.\n */\nexport interface Logger {\n debug(message: string, fields?: LogFields): void;\n info(message: string, fields?: LogFields): void;\n warn(message: string, fields?: LogFields): void;\n error(message: string, fields?: LogFields): void;\n /** A logger for a sub-namespace, such as `transport`. */\n child(namespace: string): Logger;\n}\n\n/**\n * Writes one redacted entry, for `createLogger`. A port you may implement: it never gains\n * a required parameter in a 1.x release.\n */\nexport type LogWriter = (\n level: LogLevel,\n namespace: string,\n message: string,\n fields?: Record<string, unknown>,\n) => void;\n\nconst debuggers = new Map<string, createDebug.Debugger>();\n\nconst debugWriter: LogWriter = (level, namespace, message, fields) => {\n const name = `${namespace}:${level}`;\n let log = debuggers.get(name);\n if (!log) {\n log = createDebug(name);\n debuggers.set(name, log);\n }\n if (fields && Object.keys(fields).length > 0) log('%s %o', message, fields);\n else log('%s', message);\n};\n\n/**\n * Structured logger; fields are always redacted before they reach the writer. The default\n * writer logs through `debug` under `<namespace>:<level>`.\n */\nexport function createLogger(\n namespace = 'crypto-aio',\n write: LogWriter = debugWriter,\n): Logger {\n const emit = (level: LogLevel) => (message: string, fields?: LogFields) =>\n write(\n level,\n namespace,\n redactText(message),\n fields ? (redactDeep(fields) as Record<string, unknown>) : undefined,\n );\n return {\n debug: emit('debug'),\n info: emit('info'),\n warn: emit('warn'),\n error: emit('error'),\n child: (child) => createLogger(`${namespace}:${child}`, write),\n };\n}\n\nconst noop = (): void => undefined;\n\n/** A logger that drops everything. */\nexport const noopLogger: Logger = {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n child: () => noopLogger,\n};\n"]}
@@ -1,13 +1,18 @@
1
1
  import type { Evidence, TxState } from '../model/transaction';
2
2
  import type { OperationState } from '../store/types';
3
- /** Every payload is operational-class data only (no addresses, amounts, raw txs or URLs). */
3
+ /**
4
+ * Every event and its payload. Every payload is operational-class data only (no addresses,
5
+ * amounts, raw txs or URLs). A minor release may add events and optional payload fields.
6
+ */
4
7
  export interface AioEvents {
8
+ /** A request is about to go to an endpoint; `method` is an RPC method or a route template. */
5
9
  'rpc.request': {
6
10
  transportId: string;
7
11
  endpointId: string;
8
12
  method: string;
9
13
  attempt: number;
10
14
  };
15
+ /** An endpoint answered. */
11
16
  'rpc.response': {
12
17
  transportId: string;
13
18
  endpointId: string;
@@ -15,6 +20,7 @@ export interface AioEvents {
15
20
  latencyMs: number;
16
21
  bytes: number;
17
22
  };
23
+ /** A request to an endpoint failed. */
18
24
  'rpc.error': {
19
25
  transportId: string;
20
26
  endpointId: string;
@@ -23,6 +29,11 @@ export interface AioEvents {
23
29
  code: string;
24
30
  retryable: boolean;
25
31
  };
32
+ /**
33
+ * After every completed health refresh, once per endpoint, with its state: a periodic
34
+ * gauge, not a change event. Never emitted for an endpoint whose state is `unknown` or
35
+ * `half-open`.
36
+ */
26
37
  'provider.health': {
27
38
  transportId: string;
28
39
  endpointId: string;
@@ -30,17 +41,20 @@ export interface AioEvents {
30
41
  height?: string;
31
42
  lag?: string;
32
43
  };
44
+ /** An endpoint answered another network's identity than expected; it is disabled. */
33
45
  'provider.misconfigured': {
34
46
  transportId: string;
35
47
  endpointId: string;
36
48
  expected: string;
37
49
  actual: string;
38
50
  };
51
+ /** Endpoints of a quorum read disagreed; the read decided nothing. */
39
52
  'provider.inconsistent': {
40
53
  transportId: string;
41
54
  method: string;
42
55
  endpointIds: readonly string[];
43
56
  };
57
+ /** An Operation moved from one state to another (`from` is `null` when it was created). */
44
58
  'operation.state': {
45
59
  namespace: string;
46
60
  operationId: string;
@@ -50,11 +64,13 @@ export interface AioEvents {
50
64
  to: OperationState;
51
65
  code?: string;
52
66
  };
67
+ /** An Operation stalled and waits for its caller's remedy; `code` says why. */
53
68
  'operation.stalled': {
54
69
  namespace: string;
55
70
  operationId: string;
56
71
  code: string;
57
72
  };
73
+ /** An Attempt's observed state or evidence changed. */
58
74
  'attempt.state': {
59
75
  namespace: string;
60
76
  operationId: string;
@@ -62,12 +78,14 @@ export interface AioEvents {
62
78
  state: TxState;
63
79
  evidence: Evidence;
64
80
  };
81
+ /** A block that held a transfer's transaction left the chain. */
65
82
  'tx.reorged': {
66
83
  namespace: string;
67
84
  operationId?: string;
68
85
  attemptId?: string;
69
86
  previousBlockHash: string;
70
87
  };
88
+ /** A nonce or seqno was reserved for an Operation. */
71
89
  'nonce.allocated': {
72
90
  namespace: string;
73
91
  chain: string;
@@ -91,12 +109,14 @@ export interface AioEvents {
91
109
  expected: string;
92
110
  blockingOperationId?: string;
93
111
  };
112
+ /** A signer was asked for `requests` signatures. */
94
113
  'signer.requested': {
95
114
  namespace: string;
96
115
  operationId: string;
97
116
  signerId: string;
98
117
  requests: number;
99
118
  };
119
+ /** A signer answered: signed, pending (with a ticket), or with an error. */
100
120
  'signer.completed': {
101
121
  namespace: string;
102
122
  operationId: string;
@@ -104,17 +124,20 @@ export interface AioEvents {
104
124
  status: 'signed' | 'pending' | 'error';
105
125
  latencyMs: number;
106
126
  };
127
+ /** A scanner delivered a block. */
107
128
  'scanner.block': {
108
129
  namespace: string;
109
130
  cursorKey: string;
110
131
  height: string;
111
132
  };
133
+ /** A scanner rolled back to `toHeight` after a reorg, removing `removed` blocks. */
112
134
  'scanner.rollback': {
113
135
  namespace: string;
114
136
  cursorKey: string;
115
137
  toHeight: string;
116
138
  removed: number;
117
139
  };
140
+ /** `recover()` left an Operation that needs its caller; `reason` is a code. */
118
141
  'recovery.skipped': {
119
142
  namespace: string;
120
143
  operationId: string;
@@ -122,7 +145,9 @@ export interface AioEvents {
122
145
  reason: string;
123
146
  };
124
147
  }
148
+ /** The name of an event. */
125
149
  export type AioEventName = keyof AioEvents;
150
+ /** An event as a listener gets it: its payload, with its `type` and the time `at` it fired. */
126
151
  export type AioEvent<E extends AioEventName = AioEventName> = {
127
152
  [K in E]: AioEvents[K] & {
128
153
  readonly type: K;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Evidence, TxState } from '../model/transaction';\nimport type { OperationState } from '../store/types';\n\n/** Every payload is operational-class data only (no addresses, amounts, raw txs or URLs). */\nexport interface AioEvents {\n 'rpc.request': {\n transportId: string;\n endpointId: string;\n method: string;\n attempt: number;\n };\n 'rpc.response': {\n transportId: string;\n endpointId: string;\n method: string;\n latencyMs: number;\n bytes: number;\n };\n 'rpc.error': {\n transportId: string;\n endpointId: string;\n method: string;\n latencyMs: number;\n code: string;\n retryable: boolean;\n };\n 'provider.health': {\n transportId: string;\n endpointId: string;\n state: 'healthy' | 'lagging' | 'open' | 'disabled';\n height?: string;\n lag?: string;\n };\n 'provider.misconfigured': {\n transportId: string;\n endpointId: string;\n expected: string;\n actual: string;\n };\n 'provider.inconsistent': {\n transportId: string;\n method: string;\n endpointIds: readonly string[];\n };\n 'operation.state': {\n namespace: string;\n operationId: string;\n chain: string;\n network: string;\n from: OperationState | null;\n to: OperationState;\n code?: string;\n };\n 'operation.stalled': { namespace: string; operationId: string; code: string };\n 'attempt.state': {\n namespace: string;\n operationId: string;\n attemptId: string;\n state: TxState;\n evidence: Evidence;\n };\n 'tx.reorged': {\n namespace: string;\n operationId?: string;\n attemptId?: string;\n previousBlockHash: string;\n };\n 'nonce.allocated': {\n namespace: string;\n chain: string;\n network: string;\n operationId: string;\n /** The nonce or seqno: an operational identifier, never UTXO inputs. */\n value: string;\n };\n /**\n * A submitted Operation has waited past the grace period while the chain's pending nonce\n * (`expected`) is below its own. At-least-once: a monitor reports each (Operation,\n * expected) once, but that memory is per process and bounded, so the same gap is reported\n * again after a restart, by another process, or once it was forgotten.\n */\n 'nonce.gap': {\n namespace: string;\n chain: string;\n network: string;\n operationId: string;\n /** The chain's pending nonce: an operational identifier. */\n expected: string;\n blockingOperationId?: string;\n };\n 'signer.requested': {\n namespace: string;\n operationId: string;\n signerId: string;\n requests: number;\n };\n 'signer.completed': {\n namespace: string;\n operationId: string;\n signerId: string;\n status: 'signed' | 'pending' | 'error';\n latencyMs: number;\n };\n 'scanner.block': { namespace: string; cursorKey: string; height: string };\n 'scanner.rollback': {\n namespace: string;\n cursorKey: string;\n toHeight: string;\n removed: number;\n };\n 'recovery.skipped': {\n namespace: string;\n operationId: string;\n state: OperationState;\n reason: string;\n };\n}\n\nexport type AioEventName = keyof AioEvents;\n\nexport type AioEvent<E extends AioEventName = AioEventName> = {\n [K in E]: AioEvents[K] & { readonly type: K; readonly at: number };\n}[E];\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Evidence, TxState } from '../model/transaction';\nimport type { OperationState } from '../store/types';\n\n/**\n * Every event and its payload. Every payload is operational-class data only (no addresses,\n * amounts, raw txs or URLs). A minor release may add events and optional payload fields.\n */\nexport interface AioEvents {\n /** A request is about to go to an endpoint; `method` is an RPC method or a route template. */\n 'rpc.request': {\n transportId: string;\n endpointId: string;\n method: string;\n attempt: number;\n };\n /** An endpoint answered. */\n 'rpc.response': {\n transportId: string;\n endpointId: string;\n method: string;\n latencyMs: number;\n bytes: number;\n };\n /** A request to an endpoint failed. */\n 'rpc.error': {\n transportId: string;\n endpointId: string;\n method: string;\n latencyMs: number;\n code: string;\n retryable: boolean;\n };\n /**\n * After every completed health refresh, once per endpoint, with its state: a periodic\n * gauge, not a change event. Never emitted for an endpoint whose state is `unknown` or\n * `half-open`.\n */\n 'provider.health': {\n transportId: string;\n endpointId: string;\n state: 'healthy' | 'lagging' | 'open' | 'disabled';\n height?: string;\n lag?: string;\n };\n /** An endpoint answered another network's identity than expected; it is disabled. */\n 'provider.misconfigured': {\n transportId: string;\n endpointId: string;\n expected: string;\n actual: string;\n };\n /** Endpoints of a quorum read disagreed; the read decided nothing. */\n 'provider.inconsistent': {\n transportId: string;\n method: string;\n endpointIds: readonly string[];\n };\n /** An Operation moved from one state to another (`from` is `null` when it was created). */\n 'operation.state': {\n namespace: string;\n operationId: string;\n chain: string;\n network: string;\n from: OperationState | null;\n to: OperationState;\n code?: string;\n };\n /** An Operation stalled and waits for its caller's remedy; `code` says why. */\n 'operation.stalled': { namespace: string; operationId: string; code: string };\n /** An Attempt's observed state or evidence changed. */\n 'attempt.state': {\n namespace: string;\n operationId: string;\n attemptId: string;\n state: TxState;\n evidence: Evidence;\n };\n /** A block that held a transfer's transaction left the chain. */\n 'tx.reorged': {\n namespace: string;\n operationId?: string;\n attemptId?: string;\n previousBlockHash: string;\n };\n /** A nonce or seqno was reserved for an Operation. */\n 'nonce.allocated': {\n namespace: string;\n chain: string;\n network: string;\n operationId: string;\n /** The nonce or seqno: an operational identifier, never UTXO inputs. */\n value: string;\n };\n /**\n * A submitted Operation has waited past the grace period while the chain's pending nonce\n * (`expected`) is below its own. At-least-once: a monitor reports each (Operation,\n * expected) once, but that memory is per process and bounded, so the same gap is reported\n * again after a restart, by another process, or once it was forgotten.\n */\n 'nonce.gap': {\n namespace: string;\n chain: string;\n network: string;\n operationId: string;\n /** The chain's pending nonce: an operational identifier. */\n expected: string;\n blockingOperationId?: string;\n };\n /** A signer was asked for `requests` signatures. */\n 'signer.requested': {\n namespace: string;\n operationId: string;\n signerId: string;\n requests: number;\n };\n /** A signer answered: signed, pending (with a ticket), or with an error. */\n 'signer.completed': {\n namespace: string;\n operationId: string;\n signerId: string;\n status: 'signed' | 'pending' | 'error';\n latencyMs: number;\n };\n /** A scanner delivered a block. */\n 'scanner.block': { namespace: string; cursorKey: string; height: string };\n /** A scanner rolled back to `toHeight` after a reorg, removing `removed` blocks. */\n 'scanner.rollback': {\n namespace: string;\n cursorKey: string;\n toHeight: string;\n removed: number;\n };\n /** `recover()` left an Operation that needs its caller; `reason` is a code. */\n 'recovery.skipped': {\n namespace: string;\n operationId: string;\n state: OperationState;\n reason: string;\n };\n}\n\n/** The name of an event. */\nexport type AioEventName = keyof AioEvents;\n\n/** An event as a listener gets it: its payload, with its `type` and the time `at` it fired. */\nexport type AioEvent<E extends AioEventName = AioEventName> = {\n [K in E]: AioEvents[K] & { readonly type: K; readonly at: number };\n}[E];\n"]}
@@ -27,6 +27,11 @@ export interface OperationTarget extends ReadTarget {
27
27
  readonly wallet: ResolvedWallet;
28
28
  readonly assets: AssetService;
29
29
  }
30
+ /**
31
+ * Options of `bc.transfer()` and its kin: the `idempotencyKey` that makes a repeat return
32
+ * the same Operation (1 to 200 characters of well-formed text without U+0000; one is
33
+ * generated when absent), and a `signal` that stops waiting, never a payment already sent.
34
+ */
30
35
  export interface TransferOptions {
31
36
  readonly idempotencyKey?: string;
32
37
  readonly signal?: AbortSignal;