@xyo-network/xl1-rpc 1.2.3

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 (191) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +44 -0
  3. package/dist/browser/index.mjs +1247 -0
  4. package/dist/browser/index.mjs.map +1 -0
  5. package/dist/neutral/index.mjs +1247 -0
  6. package/dist/neutral/index.mjs.map +1 -0
  7. package/dist/node/index.mjs +1247 -0
  8. package/dist/node/index.mjs.map +1 -0
  9. package/dist/types/engine/index.d.ts +2 -0
  10. package/dist/types/engine/index.d.ts.map +1 -0
  11. package/dist/types/engine/rpcEngineFromProvider.d.ts +4 -0
  12. package/dist/types/engine/rpcEngineFromProvider.d.ts.map +1 -0
  13. package/dist/types/engine/rpcMethodHandlersFromProvider.d.ts +4 -0
  14. package/dist/types/engine/rpcMethodHandlersFromProvider.d.ts.map +1 -0
  15. package/dist/types/engine/rpcMethodHandlersFromRunner.d.ts +4 -0
  16. package/dist/types/engine/rpcMethodHandlersFromRunner.d.ts.map +1 -0
  17. package/dist/types/engine/rpcMethodHandlersFromSigner.d.ts +4 -0
  18. package/dist/types/engine/rpcMethodHandlersFromSigner.d.ts.map +1 -0
  19. package/dist/types/engine/rpcMethodHandlersFromViewer.d.ts +4 -0
  20. package/dist/types/engine/rpcMethodHandlersFromViewer.d.ts.map +1 -0
  21. package/dist/types/engine/rpcMethodHandlersFromWallet.d.ts +4 -0
  22. package/dist/types/engine/rpcMethodHandlersFromWallet.d.ts.map +1 -0
  23. package/dist/types/index.d.ts +5 -0
  24. package/dist/types/index.d.ts.map +1 -0
  25. package/dist/types/provider/index.d.ts +6 -0
  26. package/dist/types/provider/index.d.ts.map +1 -0
  27. package/dist/types/provider/provider/MemoryXyoProvider.d.ts +22 -0
  28. package/dist/types/provider/provider/MemoryXyoProvider.d.ts.map +1 -0
  29. package/dist/types/provider/provider/index.d.ts +2 -0
  30. package/dist/types/provider/provider/index.d.ts.map +1 -0
  31. package/dist/types/provider/runner/JsonRpcXyoRunner.d.ts +10 -0
  32. package/dist/types/provider/runner/JsonRpcXyoRunner.d.ts.map +1 -0
  33. package/dist/types/provider/runner/MemoryXyoRunner.d.ts +9 -0
  34. package/dist/types/provider/runner/MemoryXyoRunner.d.ts.map +1 -0
  35. package/dist/types/provider/runner/NodeXyoRunner.d.ts +35 -0
  36. package/dist/types/provider/runner/NodeXyoRunner.d.ts.map +1 -0
  37. package/dist/types/provider/runner/index.d.ts +4 -0
  38. package/dist/types/provider/runner/index.d.ts.map +1 -0
  39. package/dist/types/provider/signer/JsonRpcXyoSigner.d.ts +13 -0
  40. package/dist/types/provider/signer/JsonRpcXyoSigner.d.ts.map +1 -0
  41. package/dist/types/provider/signer/MemoryXyoSigner.d.ts +12 -0
  42. package/dist/types/provider/signer/MemoryXyoSigner.d.ts.map +1 -0
  43. package/dist/types/provider/signer/index.d.ts +3 -0
  44. package/dist/types/provider/signer/index.d.ts.map +1 -0
  45. package/dist/types/provider/viewer/JsonRpcXyoViewer.d.ts +20 -0
  46. package/dist/types/provider/viewer/JsonRpcXyoViewer.d.ts.map +1 -0
  47. package/dist/types/provider/viewer/NodeXyoViewer.d.ts +97 -0
  48. package/dist/types/provider/viewer/NodeXyoViewer.d.ts.map +1 -0
  49. package/dist/types/provider/viewer/index.d.ts +3 -0
  50. package/dist/types/provider/viewer/index.d.ts.map +1 -0
  51. package/dist/types/provider/wallet/JsonRpcXyoWallet.d.ts +17 -0
  52. package/dist/types/provider/wallet/JsonRpcXyoWallet.d.ts.map +1 -0
  53. package/dist/types/provider/wallet/MemoryXyoWallet.d.ts +18 -0
  54. package/dist/types/provider/wallet/MemoryXyoWallet.d.ts.map +1 -0
  55. package/dist/types/provider/wallet/index.d.ts +3 -0
  56. package/dist/types/provider/wallet/index.d.ts.map +1 -0
  57. package/dist/types/transport/HttpRpcTransport.d.ts +11 -0
  58. package/dist/types/transport/HttpRpcTransport.d.ts.map +1 -0
  59. package/dist/types/transport/MemoryRpcTransport.d.ts +14 -0
  60. package/dist/types/transport/MemoryRpcTransport.d.ts.map +1 -0
  61. package/dist/types/transport/RpcTransport.d.ts +6 -0
  62. package/dist/types/transport/RpcTransport.d.ts.map +1 -0
  63. package/dist/types/transport/index.d.ts +4 -0
  64. package/dist/types/transport/index.d.ts.map +1 -0
  65. package/dist/types/types/ErrorCodes.d.ts +5 -0
  66. package/dist/types/types/ErrorCodes.d.ts.map +1 -0
  67. package/dist/types/types/JsonRpc.d.ts +2 -0
  68. package/dist/types/types/JsonRpc.d.ts.map +1 -0
  69. package/dist/types/types/XyoProviderRpc.d.ts +11 -0
  70. package/dist/types/types/XyoProviderRpc.d.ts.map +1 -0
  71. package/dist/types/types/XyoRunnerRpc.d.ts +7 -0
  72. package/dist/types/types/XyoRunnerRpc.d.ts.map +1 -0
  73. package/dist/types/types/XyoSignerRpc.d.ts +7 -0
  74. package/dist/types/types/XyoSignerRpc.d.ts.map +1 -0
  75. package/dist/types/types/XyoViewerRpc.d.ts +7 -0
  76. package/dist/types/types/XyoViewerRpc.d.ts.map +1 -0
  77. package/dist/types/types/XyoWalletRpc.d.ts +7 -0
  78. package/dist/types/types/XyoWalletRpc.d.ts.map +1 -0
  79. package/dist/types/types/index.d.ts +9 -0
  80. package/dist/types/types/index.d.ts.map +1 -0
  81. package/dist/types/types/schema/AllRpcSchemas.d.ts +3 -0
  82. package/dist/types/types/schema/AllRpcSchemas.d.ts.map +1 -0
  83. package/dist/types/types/schema/RpcSchemaMap.d.ts +18 -0
  84. package/dist/types/types/schema/RpcSchemaMap.d.ts.map +1 -0
  85. package/dist/types/types/schema/XyoProviderRpcSchemas.d.ts +4 -0
  86. package/dist/types/types/schema/XyoProviderRpcSchemas.d.ts.map +1 -0
  87. package/dist/types/types/schema/XyoRunnerRpcSchemas.d.ts +4 -0
  88. package/dist/types/types/schema/XyoRunnerRpcSchemas.d.ts.map +1 -0
  89. package/dist/types/types/schema/XyoSignerRpcSchemas.d.ts +4 -0
  90. package/dist/types/types/schema/XyoSignerRpcSchemas.d.ts.map +1 -0
  91. package/dist/types/types/schema/XyoViewerRpcSchemas.d.ts +4 -0
  92. package/dist/types/types/schema/XyoViewerRpcSchemas.d.ts.map +1 -0
  93. package/dist/types/types/schema/XyoWalletRpcSchemas.d.ts +4 -0
  94. package/dist/types/types/schema/XyoWalletRpcSchemas.d.ts.map +1 -0
  95. package/dist/types/types/schema/common/AddressSchema.d.ts +4 -0
  96. package/dist/types/types/schema/common/AddressSchema.d.ts.map +1 -0
  97. package/dist/types/types/schema/common/BigIntSchema.d.ts +4 -0
  98. package/dist/types/types/schema/common/BigIntSchema.d.ts.map +1 -0
  99. package/dist/types/types/schema/common/BlockBoundWitnessSchema.d.ts +235 -0
  100. package/dist/types/types/schema/common/BlockBoundWitnessSchema.d.ts.map +1 -0
  101. package/dist/types/types/schema/common/BoundWitnessSchema.d.ts +163 -0
  102. package/dist/types/types/schema/common/BoundWitnessSchema.d.ts.map +1 -0
  103. package/dist/types/types/schema/common/HashSchema.d.ts +4 -0
  104. package/dist/types/types/schema/common/HashSchema.d.ts.map +1 -0
  105. package/dist/types/types/schema/common/HexSchema.d.ts +4 -0
  106. package/dist/types/types/schema/common/HexSchema.d.ts.map +1 -0
  107. package/dist/types/types/schema/common/HydratedBlockSchema.d.ts +282 -0
  108. package/dist/types/types/schema/common/HydratedBlockSchema.d.ts.map +1 -0
  109. package/dist/types/types/schema/common/HydratedTransactionSchema.d.ts +214 -0
  110. package/dist/types/types/schema/common/HydratedTransactionSchema.d.ts.map +1 -0
  111. package/dist/types/types/schema/common/PayloadSchema.d.ts +28 -0
  112. package/dist/types/types/schema/common/PayloadSchema.d.ts.map +1 -0
  113. package/dist/types/types/schema/common/SequenceSchema.d.ts +8 -0
  114. package/dist/types/types/schema/common/SequenceSchema.d.ts.map +1 -0
  115. package/dist/types/types/schema/common/StorageMetaSchema.d.ts +46 -0
  116. package/dist/types/types/schema/common/StorageMetaSchema.d.ts.map +1 -0
  117. package/dist/types/types/schema/common/TransactionBoundWitnessSchema.d.ts +258 -0
  118. package/dist/types/types/schema/common/TransactionBoundWitnessSchema.d.ts.map +1 -0
  119. package/dist/types/types/schema/common/TransactionFees.d.ts +34 -0
  120. package/dist/types/types/schema/common/TransactionFees.d.ts.map +1 -0
  121. package/dist/types/types/schema/common/index.d.ts +14 -0
  122. package/dist/types/types/schema/common/index.d.ts.map +1 -0
  123. package/dist/types/types/schema/createRequestSchema.d.ts +29 -0
  124. package/dist/types/types/schema/createRequestSchema.d.ts.map +1 -0
  125. package/dist/types/types/schema/createResponseSchema.d.ts +24 -0
  126. package/dist/types/types/schema/createResponseSchema.d.ts.map +1 -0
  127. package/dist/types/types/schema/index.d.ts +10 -0
  128. package/dist/types/types/schema/index.d.ts.map +1 -0
  129. package/package.json +91 -0
  130. package/src/engine/index.ts +1 -0
  131. package/src/engine/rpcEngineFromProvider.ts +61 -0
  132. package/src/engine/rpcMethodHandlersFromProvider.ts +19 -0
  133. package/src/engine/rpcMethodHandlersFromRunner.ts +7 -0
  134. package/src/engine/rpcMethodHandlersFromSigner.ts +10 -0
  135. package/src/engine/rpcMethodHandlersFromViewer.ts +19 -0
  136. package/src/engine/rpcMethodHandlersFromWallet.ts +16 -0
  137. package/src/index.ts +4 -0
  138. package/src/provider/index.ts +5 -0
  139. package/src/provider/provider/MemoryXyoProvider.ts +73 -0
  140. package/src/provider/provider/index.ts +1 -0
  141. package/src/provider/runner/JsonRpcXyoRunner.ts +16 -0
  142. package/src/provider/runner/MemoryXyoRunner.ts +22 -0
  143. package/src/provider/runner/NodeXyoRunner.ts +41 -0
  144. package/src/provider/runner/index.ts +3 -0
  145. package/src/provider/signer/JsonRpcXyoSigner.ts +43 -0
  146. package/src/provider/signer/MemoryXyoSigner.ts +43 -0
  147. package/src/provider/signer/index.ts +2 -0
  148. package/src/provider/viewer/JsonRpcXyoViewer.ts +58 -0
  149. package/src/provider/viewer/NodeXyoViewer.ts +179 -0
  150. package/src/provider/viewer/index.ts +2 -0
  151. package/src/provider/wallet/JsonRpcXyoWallet.ts +45 -0
  152. package/src/provider/wallet/MemoryXyoWallet.ts +51 -0
  153. package/src/provider/wallet/index.ts +2 -0
  154. package/src/transport/HttpRpcTransport.ts +59 -0
  155. package/src/transport/MemoryRpcTransport.ts +49 -0
  156. package/src/transport/RpcTransport.ts +12 -0
  157. package/src/transport/index.ts +3 -0
  158. package/src/types/ErrorCodes.ts +9 -0
  159. package/src/types/JsonRpc.ts +1 -0
  160. package/src/types/XyoProviderRpc.ts +22 -0
  161. package/src/types/XyoRunnerRpc.ts +13 -0
  162. package/src/types/XyoSignerRpc.ts +13 -0
  163. package/src/types/XyoViewerRpc.ts +13 -0
  164. package/src/types/XyoWalletRpc.ts +13 -0
  165. package/src/types/index.ts +8 -0
  166. package/src/types/schema/AllRpcSchemas.ts +14 -0
  167. package/src/types/schema/RpcSchemaMap.ts +22 -0
  168. package/src/types/schema/XyoProviderRpcSchemas.ts +37 -0
  169. package/src/types/schema/XyoRunnerRpcSchemas.ts +22 -0
  170. package/src/types/schema/XyoSignerRpcSchemas.ts +47 -0
  171. package/src/types/schema/XyoViewerRpcSchemas.ts +124 -0
  172. package/src/types/schema/XyoWalletRpcSchemas.ts +91 -0
  173. package/src/types/schema/common/AddressSchema.ts +9 -0
  174. package/src/types/schema/common/BigIntSchema.ts +8 -0
  175. package/src/types/schema/common/BlockBoundWitnessSchema.ts +30 -0
  176. package/src/types/schema/common/BoundWitnessSchema.ts +45 -0
  177. package/src/types/schema/common/HashSchema.ts +7 -0
  178. package/src/types/schema/common/HexSchema.ts +7 -0
  179. package/src/types/schema/common/HydratedBlockSchema.ts +26 -0
  180. package/src/types/schema/common/HydratedTransactionSchema.ts +14 -0
  181. package/src/types/schema/common/PayloadSchema.ts +6 -0
  182. package/src/types/schema/common/SequenceSchema.ts +19 -0
  183. package/src/types/schema/common/StorageMetaSchema.ts +14 -0
  184. package/src/types/schema/common/TransactionBoundWitnessSchema.ts +33 -0
  185. package/src/types/schema/common/TransactionFees.ts +17 -0
  186. package/src/types/schema/common/index.ts +13 -0
  187. package/src/types/schema/createRequestSchema.ts +15 -0
  188. package/src/types/schema/createResponseSchema.ts +13 -0
  189. package/src/types/schema/index.ts +9 -0
  190. package/vitest.config.ts +11 -0
  191. package/xy.config.ts +10 -0
@@ -0,0 +1,1247 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/engine/rpcEngineFromProvider.ts
5
+ import { createAsyncMiddleware, JsonRpcEngine } from "@metamask/json-rpc-engine";
6
+
7
+ // src/types/ErrorCodes.ts
8
+ var JsonRpcErrorCodes = {
9
+ InternalError: {
10
+ code: -32603,
11
+ message: "Internal JSON-RPC error (unexpected exception)."
12
+ },
13
+ InvalidParams: {
14
+ code: -32602,
15
+ message: "Invalid method parameter(s)."
16
+ },
17
+ InvalidRequest: {
18
+ code: -32600,
19
+ message: "The JSON sent is not a valid Request object."
20
+ },
21
+ MethodNotFound: {
22
+ code: -32601,
23
+ message: "The method does not exist or is not available."
24
+ }
25
+ };
26
+
27
+ // src/types/JsonRpc.ts
28
+ var jsonrpc = "2.0";
29
+
30
+ // src/types/schema/XyoProviderRpcSchemas.ts
31
+ import { z as z14 } from "zod";
32
+
33
+ // src/types/schema/common/AddressSchema.ts
34
+ import { toAddress } from "@xylabs/hex";
35
+ import { AddressRegEx } from "@xyo-network/payload-wrapper";
36
+ import { z } from "zod";
37
+ var CompiledAddressRegEx = new RegExp(AddressRegEx);
38
+ var AddressToStringSchema = z.string().toLowerCase().regex(CompiledAddressRegEx);
39
+ var AddressFromStringSchema = z.string().toLowerCase().regex(CompiledAddressRegEx).transform((v) => toAddress(v));
40
+
41
+ // src/types/schema/common/BigIntSchema.ts
42
+ import { hexToBigInt, toHex } from "@xylabs/hex";
43
+ import { HexRegEx } from "@xyo-network/payload-wrapper";
44
+ import { z as z2 } from "zod";
45
+ var CompiledHexRegEx = new RegExp(HexRegEx);
46
+ var BigIntToStringSchema = z2.bigint().nonnegative().transform((x) => toHex(x));
47
+ var BigIntFromStringSchema = z2.string().regex(CompiledHexRegEx).transform((x) => hexToBigInt(toHex(x)));
48
+
49
+ // src/types/schema/common/BlockBoundWitnessSchema.ts
50
+ import { z as z9 } from "zod";
51
+
52
+ // src/types/schema/common/BoundWitnessSchema.ts
53
+ import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
54
+ import { z as z8 } from "zod";
55
+
56
+ // src/types/schema/common/HashSchema.ts
57
+ import { toHex as toHex2 } from "@xylabs/hex";
58
+ import { HashRegEx } from "@xyo-network/payload-wrapper";
59
+ import { z as z3 } from "zod";
60
+ var HashToStringSchema = z3.string().toLowerCase().regex(new RegExp(HashRegEx));
61
+ var HashFromStringSchema = z3.string().toLowerCase().regex(new RegExp(HashRegEx)).transform((v) => toHex2(v));
62
+
63
+ // src/types/schema/common/HexSchema.ts
64
+ import { toHex as toHex3 } from "@xylabs/hex";
65
+ import { HexRegEx as HexRegEx2 } from "@xyo-network/payload-wrapper";
66
+ import { z as z4 } from "zod";
67
+ var HexToStringSchema = z4.string().toLowerCase().regex(new RegExp(HexRegEx2));
68
+ var HexFromStringSchema = z4.string().toLowerCase().regex(new RegExp(HexRegEx2)).transform((v) => toHex3(v));
69
+
70
+ // src/types/schema/common/PayloadSchema.ts
71
+ import { z as z7 } from "zod";
72
+
73
+ // src/types/schema/common/StorageMetaSchema.ts
74
+ import { z as z6 } from "zod";
75
+
76
+ // src/types/schema/common/SequenceSchema.ts
77
+ import { toHex as toHex4 } from "@xylabs/hex";
78
+ import { SequenceConstants } from "@xyo-network/payload-model";
79
+ import { HexRegExMinMax } from "@xyo-network/payload-wrapper";
80
+ import { z as z5 } from "zod";
81
+ var LocalSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.localSequenceBytes, SequenceConstants.localSequenceBytes));
82
+ var LocalSequenceToStringSchema = z5.string().regex(LocalSequenceRegex);
83
+ var LocalSequenceFromStringSchema = z5.string().regex(LocalSequenceRegex).transform((v) => toHex4(v));
84
+ var QualifiedSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.qualifiedSequenceBytes, SequenceConstants.qualifiedSequenceBytes));
85
+ var QualifiedSequenceToStringSchema = z5.string().regex(QualifiedSequenceRegex);
86
+ var QualifiedSequenceFromStringSchema = z5.string().regex(QualifiedSequenceRegex).transform((v) => toHex4(v));
87
+ var SequenceToStringSchema = z5.union([
88
+ LocalSequenceToStringSchema,
89
+ QualifiedSequenceToStringSchema
90
+ ]);
91
+ var SequenceFromStringSchema = z5.union([
92
+ LocalSequenceFromStringSchema,
93
+ QualifiedSequenceFromStringSchema
94
+ ]);
95
+
96
+ // src/types/schema/common/StorageMetaSchema.ts
97
+ var StorageMetaSchema = z6.object({
98
+ _hash: HashToStringSchema,
99
+ _dataHash: HashToStringSchema,
100
+ _sequence: SequenceToStringSchema
101
+ });
102
+
103
+ // src/types/schema/common/PayloadSchema.ts
104
+ var PayloadSchema = z7.object({
105
+ schema: z7.string()
106
+ }).passthrough();
107
+ var PayloadWithStorageMetaSchema = PayloadSchema.extend(StorageMetaSchema.shape).passthrough();
108
+
109
+ // src/types/schema/common/BoundWitnessSchema.ts
110
+ var SchemaIdSchema = z8.string();
111
+ var BoundWitnessRequiredFieldsSchema = z8.object({
112
+ addresses: z8.array(AddressToStringSchema),
113
+ payload_hashes: z8.array(HashToStringSchema),
114
+ payload_schemas: z8.array(SchemaIdSchema),
115
+ previous_hashes: z8.array(HashToStringSchema.nullable())
116
+ });
117
+ var BoundWitnessMetaSchema = z8.object({
118
+ $destination: AddressToStringSchema.optional(),
119
+ $sourceQuery: HashToStringSchema.optional()
120
+ });
121
+ var UnsignedBoundWitnessSchema = PayloadSchema.extend({
122
+ schema: z8.literal(BoundWitnessSchema)
123
+ }).merge(BoundWitnessRequiredFieldsSchema).merge(BoundWitnessMetaSchema).passthrough();
124
+ var UnsignedBoundWitnessWithStorageMetaSchema = PayloadWithStorageMetaSchema.extend({
125
+ schema: z8.literal(BoundWitnessSchema)
126
+ }).merge(BoundWitnessRequiredFieldsSchema).merge(BoundWitnessMetaSchema).passthrough();
127
+ var SignedBoundWitnessSchema = UnsignedBoundWitnessSchema.extend({
128
+ $signatures: z8.array(HexToStringSchema)
129
+ }).passthrough();
130
+ var SignedBoundWitnessWithStorageMetaSchema = UnsignedBoundWitnessWithStorageMetaSchema.extend({
131
+ $signatures: z8.array(HexToStringSchema)
132
+ }).passthrough();
133
+
134
+ // src/types/schema/common/BlockBoundWitnessSchema.ts
135
+ var BlockNumberSchema = z9.number().int().nonnegative();
136
+ var BlockBoundWitnessFieldsSchema = z9.object({
137
+ block: BlockNumberSchema,
138
+ chain: HexToStringSchema,
139
+ previous: HexToStringSchema.nullable(),
140
+ protocol: z9.number().optional(),
141
+ step_hashes: z9.array(HexToStringSchema).optional()
142
+ });
143
+ var BlockBoundWitnessSchema = UnsignedBoundWitnessSchema.merge(BlockBoundWitnessFieldsSchema).passthrough();
144
+ var BlockBoundWitnessWithStorageMetaSchema = UnsignedBoundWitnessWithStorageMetaSchema.merge(BlockBoundWitnessFieldsSchema).passthrough();
145
+ var SignedBlockBoundWitnessSchema = SignedBoundWitnessSchema.merge(BlockBoundWitnessFieldsSchema).passthrough();
146
+ var SignedBlockBoundWitnessWithStorageMetaSchema = SignedBoundWitnessWithStorageMetaSchema.merge(BlockBoundWitnessFieldsSchema).passthrough();
147
+
148
+ // src/types/schema/common/HydratedBlockSchema.ts
149
+ import { z as z10 } from "zod";
150
+ var HydratedBlockSchema = z10.tuple([
151
+ BlockBoundWitnessSchema,
152
+ z10.array(PayloadSchema)
153
+ ]);
154
+ var HydratedBlockWithStorageMetaSchema = z10.tuple([
155
+ BlockBoundWitnessWithStorageMetaSchema,
156
+ z10.array(PayloadWithStorageMetaSchema)
157
+ ]);
158
+ var SignedHydratedBlockSchema = z10.tuple([
159
+ SignedBlockBoundWitnessSchema,
160
+ z10.array(PayloadSchema)
161
+ ]);
162
+ var SignedHydratedBlockWithStorageMetaSchema = z10.tuple([
163
+ SignedBlockBoundWitnessWithStorageMetaSchema,
164
+ z10.array(PayloadWithStorageMetaSchema)
165
+ ]);
166
+
167
+ // src/types/schema/common/HydratedTransactionSchema.ts
168
+ import { z as z12 } from "zod";
169
+
170
+ // src/types/schema/common/TransactionBoundWitnessSchema.ts
171
+ import z11 from "zod";
172
+ var BlockStartSchema = z11.object({
173
+ nbf: BlockNumberSchema
174
+ });
175
+ var BlockEndSchema = z11.object({
176
+ exp: BlockNumberSchema
177
+ });
178
+ var BlockDurationSchema = z11.object({
179
+ nbf: BlockNumberSchema,
180
+ exp: BlockNumberSchema
181
+ });
182
+ var TransactionFeesSchema = z11.object({
183
+ fees: z11.object({
184
+ base: HexToStringSchema,
185
+ gasLimit: HexToStringSchema,
186
+ gasPrice: HexToStringSchema,
187
+ priority: HexToStringSchema
188
+ })
189
+ });
190
+ var TransactionBoundWitnessFields = z11.object({
191
+ chain: AddressToStringSchema
192
+ });
193
+ var TransactionBoundWitnessSchema = UnsignedBoundWitnessSchema.merge(BlockDurationSchema).merge(TransactionFeesSchema).merge(TransactionBoundWitnessFields).passthrough();
194
+ var SignedTransactionBoundWitnessSchema = SignedBoundWitnessSchema.merge(BlockDurationSchema).merge(TransactionFeesSchema).merge(TransactionBoundWitnessFields).passthrough();
195
+
196
+ // src/types/schema/common/HydratedTransactionSchema.ts
197
+ var HydratedTransactionSchema = z12.tuple([
198
+ TransactionBoundWitnessSchema,
199
+ z12.array(PayloadSchema)
200
+ ]);
201
+ var SignedHydratedTransactionSchema = z12.tuple([
202
+ SignedTransactionBoundWitnessSchema,
203
+ z12.array(PayloadSchema)
204
+ ]);
205
+
206
+ // src/types/schema/common/TransactionFees.ts
207
+ import { z as z13 } from "zod";
208
+ var TransactionFeesToStingSchema = z13.object({
209
+ base: BigIntToStringSchema,
210
+ gasLimit: BigIntToStringSchema,
211
+ gasPrice: BigIntToStringSchema,
212
+ priority: BigIntToStringSchema
213
+ });
214
+ var TransactionFeesFromStingSchema = z13.object({
215
+ base: BigIntFromStringSchema,
216
+ gasLimit: BigIntFromStringSchema,
217
+ gasPrice: BigIntFromStringSchema,
218
+ priority: BigIntFromStringSchema
219
+ });
220
+
221
+ // src/types/schema/XyoProviderRpcSchemas.ts
222
+ var XyoProviderRpcSchemas = {
223
+ xyoProvider_send: {
224
+ params: {
225
+ to: z14.tuple([
226
+ AddressFromStringSchema,
227
+ z14.array(PayloadSchema),
228
+ z14.array(PayloadSchema),
229
+ z14.number().nonnegative(),
230
+ z14.number().nonnegative(),
231
+ TransactionFeesToStingSchema,
232
+ AddressFromStringSchema.optional()
233
+ ]),
234
+ from: z14.tuple([
235
+ AddressToStringSchema,
236
+ z14.array(PayloadSchema),
237
+ z14.array(PayloadSchema),
238
+ z14.number().nonnegative(),
239
+ z14.number().nonnegative(),
240
+ TransactionFeesFromStingSchema,
241
+ AddressToStringSchema.optional()
242
+ ])
243
+ },
244
+ result: {
245
+ to: SignedTransactionBoundWitnessSchema,
246
+ from: SignedTransactionBoundWitnessSchema
247
+ }
248
+ }
249
+ };
250
+
251
+ // src/types/schema/XyoRunnerRpcSchemas.ts
252
+ import { z as z15 } from "zod";
253
+ var XyoRunnerRpcSchemas = {
254
+ xyoRunner_broadcastTransaction: {
255
+ params: {
256
+ to: z15.tuple([
257
+ SignedHydratedTransactionSchema
258
+ ]),
259
+ from: z15.tuple([
260
+ SignedHydratedTransactionSchema
261
+ ])
262
+ },
263
+ result: {
264
+ to: HashToStringSchema,
265
+ from: HashFromStringSchema
266
+ }
267
+ }
268
+ };
269
+
270
+ // src/types/schema/XyoSignerRpcSchemas.ts
271
+ import { z as z16 } from "zod";
272
+ var XyoSignerRpcSchemas = {
273
+ xyoSigner_address: {
274
+ params: {
275
+ to: z16.array(z16.any()).length(0).optional(),
276
+ from: z16.array(z16.any()).length(0).optional()
277
+ },
278
+ result: {
279
+ to: AddressToStringSchema,
280
+ from: AddressFromStringSchema
281
+ }
282
+ },
283
+ xyoSigner_createSignedTransaction: {
284
+ params: {
285
+ to: z16.tuple([
286
+ AddressFromStringSchema,
287
+ z16.array(PayloadSchema),
288
+ z16.array(PayloadSchema),
289
+ z16.number().nonnegative(),
290
+ z16.number().nonnegative(),
291
+ TransactionFeesToStingSchema,
292
+ AddressFromStringSchema.optional()
293
+ ]),
294
+ from: z16.tuple([
295
+ AddressToStringSchema,
296
+ z16.array(PayloadSchema),
297
+ z16.array(PayloadSchema),
298
+ z16.number().nonnegative(),
299
+ z16.number().nonnegative(),
300
+ TransactionFeesFromStingSchema,
301
+ AddressToStringSchema.optional()
302
+ ])
303
+ },
304
+ result: {
305
+ to: SignedTransactionBoundWitnessSchema,
306
+ from: SignedTransactionBoundWitnessSchema
307
+ }
308
+ }
309
+ };
310
+
311
+ // src/types/schema/XyoViewerRpcSchemas.ts
312
+ import { z as z17 } from "zod";
313
+ var XyoViewerRpcSchemas = {
314
+ xyoViewer_accountBalance: {
315
+ params: {
316
+ to: z17.tuple([
317
+ AddressToStringSchema,
318
+ z17.number(),
319
+ z17.boolean()
320
+ ]),
321
+ from: z17.tuple([
322
+ AddressFromStringSchema,
323
+ z17.number(),
324
+ z17.boolean()
325
+ ])
326
+ },
327
+ result: {
328
+ to: BigIntToStringSchema,
329
+ from: BigIntFromStringSchema
330
+ }
331
+ },
332
+ xyoViewer_blockByHash: {
333
+ params: {
334
+ to: z17.tuple([
335
+ HashToStringSchema
336
+ ]),
337
+ from: z17.tuple([
338
+ HashFromStringSchema
339
+ ])
340
+ },
341
+ result: {
342
+ to: SignedHydratedBlockSchema,
343
+ from: SignedHydratedBlockSchema
344
+ }
345
+ },
346
+ xyoViewer_blockByNumber: {
347
+ params: {
348
+ to: z17.tuple([
349
+ z17.number()
350
+ ]),
351
+ from: z17.tuple([
352
+ z17.number()
353
+ ])
354
+ },
355
+ result: {
356
+ to: SignedHydratedBlockSchema,
357
+ from: SignedHydratedBlockSchema
358
+ }
359
+ },
360
+ xyoViewer_blocksByHash: {
361
+ params: {
362
+ to: z17.tuple([
363
+ HashToStringSchema,
364
+ z17.number().optional()
365
+ ]),
366
+ from: z17.tuple([
367
+ HashFromStringSchema,
368
+ z17.number().optional()
369
+ ])
370
+ },
371
+ result: {
372
+ to: z17.array(SignedHydratedBlockSchema),
373
+ from: z17.array(SignedHydratedBlockSchema)
374
+ }
375
+ },
376
+ xyoViewer_chainId: {
377
+ params: {
378
+ to: z17.array(z17.any()).length(0).optional(),
379
+ from: z17.array(z17.any()).length(0).optional()
380
+ },
381
+ result: {
382
+ to: AddressToStringSchema,
383
+ from: AddressFromStringSchema
384
+ }
385
+ },
386
+ xyoViewer_currentBlock: {
387
+ params: {
388
+ to: z17.array(z17.any()).length(0).optional(),
389
+ from: z17.array(z17.any()).length(0).optional()
390
+ },
391
+ result: {
392
+ to: SignedHydratedBlockSchema,
393
+ from: SignedHydratedBlockSchema
394
+ }
395
+ },
396
+ xyoViewer_currentBlockHash: {
397
+ params: {
398
+ to: z17.array(z17.any()).length(0).optional(),
399
+ from: z17.array(z17.any()).length(0).optional()
400
+ },
401
+ result: {
402
+ to: HashToStringSchema,
403
+ from: HashFromStringSchema
404
+ }
405
+ },
406
+ xyoViewer_currentBlockNumber: {
407
+ params: {
408
+ to: z17.array(z17.any()).length(0).optional(),
409
+ from: z17.array(z17.any()).length(0).optional()
410
+ },
411
+ result: {
412
+ to: BlockNumberSchema,
413
+ from: BlockNumberSchema
414
+ }
415
+ },
416
+ xyoViewer_transactionByBlockHashAndIndex: {
417
+ params: {
418
+ to: z17.tuple([
419
+ HashToStringSchema,
420
+ z17.number()
421
+ ]),
422
+ from: z17.tuple([
423
+ HashFromStringSchema,
424
+ z17.number()
425
+ ])
426
+ },
427
+ result: {
428
+ to: SignedHydratedTransactionSchema.nullable(),
429
+ from: SignedHydratedTransactionSchema.nullable()
430
+ }
431
+ },
432
+ xyoViewer_transactionByBlockNumberAndIndex: {
433
+ params: {
434
+ to: z17.tuple([
435
+ z17.number(),
436
+ z17.number()
437
+ ]),
438
+ from: z17.tuple([
439
+ z17.number(),
440
+ z17.number()
441
+ ])
442
+ },
443
+ result: {
444
+ to: SignedHydratedTransactionSchema.nullable(),
445
+ from: SignedHydratedTransactionSchema.nullable()
446
+ }
447
+ },
448
+ xyoViewer_transactionByHash: {
449
+ params: {
450
+ to: z17.tuple([
451
+ HashToStringSchema
452
+ ]),
453
+ from: z17.tuple([
454
+ HashFromStringSchema
455
+ ])
456
+ },
457
+ result: {
458
+ to: SignedHydratedTransactionSchema.nullable(),
459
+ from: SignedHydratedTransactionSchema.nullable()
460
+ }
461
+ }
462
+ };
463
+
464
+ // src/types/schema/XyoWalletRpcSchemas.ts
465
+ import { z as z18 } from "zod";
466
+ var XyoWalletRpcSchemas = {
467
+ xyoWallet_accounts: {
468
+ params: {
469
+ to: z18.array(z18.any()).length(0).optional(),
470
+ from: z18.array(z18.any()).length(0).optional()
471
+ },
472
+ result: {
473
+ to: z18.array(AddressToStringSchema),
474
+ from: z18.array(AddressFromStringSchema)
475
+ }
476
+ },
477
+ xyoWallet_addChain: {
478
+ params: {
479
+ to: z18.array(z18.any()).length(0).optional(),
480
+ from: z18.array(z18.any()).length(0).optional()
481
+ },
482
+ result: {
483
+ from: z18.any(),
484
+ to: z18.any()
485
+ }
486
+ },
487
+ xyoWallet_chain: {
488
+ params: {
489
+ to: z18.array(z18.any()).length(0).optional(),
490
+ from: z18.array(z18.any()).length(0).optional()
491
+ },
492
+ result: {
493
+ to: AddressToStringSchema,
494
+ from: AddressFromStringSchema
495
+ }
496
+ },
497
+ xyoWallet_chains: {
498
+ params: {
499
+ to: z18.array(z18.any()).length(0).optional(),
500
+ from: z18.array(z18.any()).length(0).optional()
501
+ },
502
+ result: {
503
+ from: z18.any(),
504
+ to: z18.any()
505
+ }
506
+ },
507
+ xyoWallet_permissions: {
508
+ params: {
509
+ to: z18.array(z18.any()).length(0).optional(),
510
+ from: z18.array(z18.any()).length(0).optional()
511
+ },
512
+ result: {
513
+ from: z18.any(),
514
+ to: z18.any()
515
+ }
516
+ },
517
+ xyoWallet_requestPermissions: {
518
+ params: {
519
+ to: z18.array(z18.any()).length(0).optional(),
520
+ from: z18.array(z18.any()).length(0).optional()
521
+ },
522
+ result: {
523
+ from: z18.any(),
524
+ to: z18.any()
525
+ }
526
+ },
527
+ xyoWallet_revokePermissions: {
528
+ params: {
529
+ to: z18.array(z18.any()).length(0).optional(),
530
+ from: z18.array(z18.any()).length(0).optional()
531
+ },
532
+ result: {
533
+ from: z18.any(),
534
+ to: z18.any()
535
+ }
536
+ },
537
+ xyoWallet_switchChain: {
538
+ params: {
539
+ to: z18.array(z18.any()).length(0).optional(),
540
+ from: z18.array(z18.any()).length(0).optional()
541
+ },
542
+ result: {
543
+ from: z18.any(),
544
+ to: z18.any()
545
+ }
546
+ }
547
+ };
548
+
549
+ // src/types/schema/AllRpcSchemas.ts
550
+ var AllRpcSchemas = {
551
+ ...XyoProviderRpcSchemas,
552
+ ...XyoRunnerRpcSchemas,
553
+ ...XyoSignerRpcSchemas,
554
+ ...XyoViewerRpcSchemas,
555
+ ...XyoWalletRpcSchemas
556
+ };
557
+
558
+ // src/types/schema/createRequestSchema.ts
559
+ import { z as z19 } from "zod";
560
+ var createRequestSchema = /* @__PURE__ */ __name((methodName, paramsSchema = z19.undefined()) => z19.object({
561
+ id: z19.union([
562
+ z19.string(),
563
+ z19.number()
564
+ ]),
565
+ jsonrpc: z19.literal(jsonrpc),
566
+ method: z19.literal(methodName),
567
+ params: paramsSchema
568
+ }), "createRequestSchema");
569
+
570
+ // src/types/schema/createResponseSchema.ts
571
+ import { z as z20 } from "zod";
572
+ var createResponseSchema = /* @__PURE__ */ __name((resultSchema = z20.undefined()) => z20.object({
573
+ id: z20.union([
574
+ z20.string(),
575
+ z20.number()
576
+ ]),
577
+ jsonrpc: z20.literal(jsonrpc),
578
+ result: resultSchema
579
+ }), "createResponseSchema");
580
+
581
+ // src/engine/rpcMethodHandlersFromRunner.ts
582
+ var rpcMethodHandlersFromRunner = /* @__PURE__ */ __name((runner) => {
583
+ return {
584
+ xyoRunner_broadcastTransaction: /* @__PURE__ */ __name((params) => runner.broadcastTransaction(...params ?? []), "xyoRunner_broadcastTransaction")
585
+ };
586
+ }, "rpcMethodHandlersFromRunner");
587
+
588
+ // src/engine/rpcMethodHandlersFromSigner.ts
589
+ var rpcMethodHandlersFromSigner = /* @__PURE__ */ __name((signer) => {
590
+ return {
591
+ xyoSigner_address: /* @__PURE__ */ __name((params) => signer.address(...params ?? []), "xyoSigner_address"),
592
+ xyoSigner_createSignedTransaction: /* @__PURE__ */ __name((params) => signer.createSignedTransaction(...params ?? []), "xyoSigner_createSignedTransaction")
593
+ };
594
+ }, "rpcMethodHandlersFromSigner");
595
+
596
+ // src/engine/rpcMethodHandlersFromViewer.ts
597
+ var rpcMethodHandlersFromViewer = /* @__PURE__ */ __name((viewer) => {
598
+ return {
599
+ xyoViewer_accountBalance: /* @__PURE__ */ __name((params) => viewer.accountBalance(...params ?? []), "xyoViewer_accountBalance"),
600
+ xyoViewer_blockByHash: /* @__PURE__ */ __name((params) => viewer.blockByHash(...params ?? []), "xyoViewer_blockByHash"),
601
+ xyoViewer_blockByNumber: /* @__PURE__ */ __name((params) => viewer.blockByNumber(...params ?? []), "xyoViewer_blockByNumber"),
602
+ xyoViewer_blocksByHash: /* @__PURE__ */ __name((params) => viewer.blocksByHash(...params ?? []), "xyoViewer_blocksByHash"),
603
+ xyoViewer_chainId: /* @__PURE__ */ __name((params) => viewer.chainId(...params ?? []), "xyoViewer_chainId"),
604
+ xyoViewer_currentBlock: /* @__PURE__ */ __name((params) => viewer.currentBlock(...params ?? []), "xyoViewer_currentBlock"),
605
+ xyoViewer_currentBlockHash: /* @__PURE__ */ __name((params) => viewer.currentBlockHash(...params ?? []), "xyoViewer_currentBlockHash"),
606
+ xyoViewer_currentBlockNumber: /* @__PURE__ */ __name((params) => viewer.currentBlockNumber(...params ?? []), "xyoViewer_currentBlockNumber"),
607
+ xyoViewer_transactionByBlockHashAndIndex: /* @__PURE__ */ __name((params) => viewer.transactionByBlockHashAndIndex(...params ?? []), "xyoViewer_transactionByBlockHashAndIndex"),
608
+ xyoViewer_transactionByBlockNumberAndIndex: /* @__PURE__ */ __name((params) => viewer.transactionByBlockNumberAndIndex(...params ?? []), "xyoViewer_transactionByBlockNumberAndIndex"),
609
+ xyoViewer_transactionByHash: /* @__PURE__ */ __name((params) => viewer.transactionByHash(...params ?? []), "xyoViewer_transactionByHash")
610
+ };
611
+ }, "rpcMethodHandlersFromViewer");
612
+
613
+ // src/engine/rpcMethodHandlersFromWallet.ts
614
+ var rpcMethodHandlersFromWallet = /* @__PURE__ */ __name((wallet) => {
615
+ return {
616
+ xyoWallet_accounts: /* @__PURE__ */ __name((params) => wallet.accounts(...params ?? []), "xyoWallet_accounts"),
617
+ xyoWallet_addChain: /* @__PURE__ */ __name((params) => wallet.addChain(...params ?? []), "xyoWallet_addChain"),
618
+ xyoWallet_chain: /* @__PURE__ */ __name((params) => wallet.chain(...params ?? []), "xyoWallet_chain"),
619
+ xyoWallet_chains: /* @__PURE__ */ __name((params) => wallet.chains(...params ?? []), "xyoWallet_chains"),
620
+ xyoWallet_permissions: /* @__PURE__ */ __name((params) => wallet.permissions(...params ?? []), "xyoWallet_permissions"),
621
+ xyoWallet_requestPermissions: /* @__PURE__ */ __name((params) => wallet.requestPermissions(...params ?? []), "xyoWallet_requestPermissions"),
622
+ xyoWallet_revokePermissions: /* @__PURE__ */ __name((params) => wallet.revokePermissions(...params ?? []), "xyoWallet_revokePermissions"),
623
+ xyoWallet_switchChain: /* @__PURE__ */ __name((params) => wallet.switchChain(...params ?? []), "xyoWallet_switchChain")
624
+ };
625
+ }, "rpcMethodHandlersFromWallet");
626
+
627
+ // src/engine/rpcMethodHandlersFromProvider.ts
628
+ var rpcMethodHandlersFromProvider = /* @__PURE__ */ __name((provider) => {
629
+ const { runner, signer, viewer, wallet } = provider;
630
+ let result = {
631
+ xyoProvider_send: /* @__PURE__ */ __name((params) => provider.send(...params ?? []), "xyoProvider_send")
632
+ };
633
+ if (runner) result = {
634
+ ...result,
635
+ ...rpcMethodHandlersFromRunner(runner)
636
+ };
637
+ if (signer) result = {
638
+ ...result,
639
+ ...rpcMethodHandlersFromSigner(signer)
640
+ };
641
+ if (viewer) result = {
642
+ ...result,
643
+ ...rpcMethodHandlersFromViewer(viewer)
644
+ };
645
+ if (wallet) result = {
646
+ ...result,
647
+ ...rpcMethodHandlersFromWallet(wallet)
648
+ };
649
+ return result;
650
+ }, "rpcMethodHandlersFromProvider");
651
+
652
+ // src/engine/rpcEngineFromProvider.ts
653
+ var requestSchemas = {};
654
+ var rpcEngineFromProvider = /* @__PURE__ */ __name((provider) => {
655
+ const engine = new JsonRpcEngine();
656
+ const handlers = rpcMethodHandlersFromProvider(provider);
657
+ engine.push(createAsyncMiddleware(async (req, res) => {
658
+ const method = req.method;
659
+ const handler = handlers[method];
660
+ const schema = AllRpcSchemas[method];
661
+ if (!schema || !handler) {
662
+ res.error = JsonRpcErrorCodes.MethodNotFound;
663
+ return;
664
+ }
665
+ let requestSchema = requestSchemas[method];
666
+ if (!requestSchema) {
667
+ requestSchema = createRequestSchema(method, schema.params.from);
668
+ requestSchemas[method] = requestSchema;
669
+ }
670
+ const parsed = requestSchema.safeParse(req);
671
+ if (!parsed.success) {
672
+ res.error = {
673
+ // Return invalid params error
674
+ ...JsonRpcErrorCodes.InvalidParams,
675
+ // with the specific validation error message
676
+ message: parsed.error.message
677
+ };
678
+ return;
679
+ }
680
+ const { params } = parsed.data;
681
+ const result = await handler(params);
682
+ res.result = schema.result.to.parse(result);
683
+ }));
684
+ return engine;
685
+ }, "rpcEngineFromProvider");
686
+
687
+ // src/provider/provider/MemoryXyoProvider.ts
688
+ import { assertEx } from "@xylabs/assert";
689
+ import { defaultFees } from "@xyo-network/xl1-protocol";
690
+ var MemoryXyoProvider = class {
691
+ static {
692
+ __name(this, "MemoryXyoProvider");
693
+ }
694
+ _runner;
695
+ _signer;
696
+ _viewer;
697
+ _wallet;
698
+ constructor(params) {
699
+ this._runner = params?.runner;
700
+ this._signer = params?.signer;
701
+ this._viewer = params?.viewer;
702
+ this._wallet = params?.wallet;
703
+ }
704
+ get runner() {
705
+ return this._runner;
706
+ }
707
+ get signer() {
708
+ return this._signer;
709
+ }
710
+ get viewer() {
711
+ return this._viewer;
712
+ }
713
+ get wallet() {
714
+ return this._wallet;
715
+ }
716
+ async send(elevatedPayloads, additionalPayloads, chain, nbf, exp, from, fees) {
717
+ const chainValue = chain === void 0 ? await this._wallet?.chain() : chain;
718
+ if (chainValue === void 0) throw new Error("Failed to determine chain");
719
+ const nbfValue = nbf === void 0 ? await this._viewer?.currentBlockNumber() : nbf;
720
+ if (nbfValue === void 0) throw new Error("Failed to determine nbf");
721
+ const expValue = exp === void 0 ? nbfValue + 1e3 : exp;
722
+ const feesValue = fees === void 0 ? defaultFees : fees;
723
+ const fromValue = from === void 0 ? await this._signer?.address() : from;
724
+ if (fromValue === void 0) throw new Error("Failed to determine from address");
725
+ const signedTransaction = assertEx(await this._signer?.createSignedTransaction(chainValue, elevatedPayloads, additionalPayloads, nbfValue, expValue, feesValue, fromValue), () => "Failed to create transaction");
726
+ assertEx(await this.runner?.broadcastTransaction([
727
+ signedTransaction,
728
+ elevatedPayloads
729
+ ]), () => "Failed to broadcast transaction");
730
+ return signedTransaction;
731
+ }
732
+ };
733
+
734
+ // src/provider/runner/JsonRpcXyoRunner.ts
735
+ var JsonRpcXyoRunner = class {
736
+ static {
737
+ __name(this, "JsonRpcXyoRunner");
738
+ }
739
+ transport;
740
+ constructor(transport) {
741
+ this.transport = transport;
742
+ }
743
+ async broadcastTransaction(transaction) {
744
+ return await this.transport.sendRequest("xyoRunner_broadcastTransaction", [
745
+ transaction
746
+ ]);
747
+ }
748
+ };
749
+
750
+ // src/provider/runner/MemoryXyoRunner.ts
751
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
752
+ import { flattenHydratedTransaction } from "@xyo-network/chain-protocol";
753
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
754
+ var MemoryXyoRunner = class {
755
+ static {
756
+ __name(this, "MemoryXyoRunner");
757
+ }
758
+ _archivist;
759
+ async broadcastTransaction(transaction) {
760
+ const archivist = await this.getArchivist();
761
+ await archivist.insert(flattenHydratedTransaction(transaction));
762
+ return await PayloadBuilder.hash(transaction[0]);
763
+ }
764
+ async getArchivist() {
765
+ if (!this._archivist) {
766
+ this._archivist = await MemoryArchivist.create({
767
+ account: "random"
768
+ });
769
+ }
770
+ return this._archivist;
771
+ }
772
+ };
773
+
774
+ // src/provider/runner/NodeXyoRunner.ts
775
+ import { assertEx as assertEx2 } from "@xylabs/assert";
776
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
777
+ import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/chain-protocol";
778
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
779
+ var NodeXyoRunner = class {
780
+ static {
781
+ __name(this, "NodeXyoRunner");
782
+ }
783
+ // TODO: Make configurable with defaults
784
+ node;
785
+ pendingArchivistPath = "XYOChain:Pending:PendingTransactions";
786
+ _pendingArchivist;
787
+ constructor(node) {
788
+ this.node = node;
789
+ }
790
+ async broadcastTransaction(transaction) {
791
+ const pendingArchivist = await this.getPendingArchivist();
792
+ await pendingArchivist.insert(flattenHydratedTransaction2(transaction));
793
+ return await PayloadBuilder2.hash(transaction[0]);
794
+ }
795
+ getArchivist = /* @__PURE__ */ __name(async (identifier) => {
796
+ const diviner = await this.node.resolve(identifier);
797
+ return assertEx2(asArchivistInstance(diviner), () => `Error: Could not resolve ${identifier} to an archivist instance`);
798
+ }, "getArchivist");
799
+ getPendingArchivist = /* @__PURE__ */ __name(async () => {
800
+ if (this._pendingArchivist) return this._pendingArchivist;
801
+ this._pendingArchivist = await this.getArchivist(this.pendingArchivistPath);
802
+ return this._pendingArchivist;
803
+ }, "getPendingArchivist");
804
+ };
805
+
806
+ // src/provider/signer/JsonRpcXyoSigner.ts
807
+ var JsonRpcXyoSigner = class {
808
+ static {
809
+ __name(this, "JsonRpcXyoSigner");
810
+ }
811
+ transport;
812
+ constructor(transport) {
813
+ this.transport = transport;
814
+ }
815
+ async address() {
816
+ return await this.transport.sendRequest("xyoSigner_address");
817
+ }
818
+ async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
819
+ return await this.transport.sendRequest("xyoSigner_createSignedTransaction", [
820
+ chain,
821
+ elevatedPayloads,
822
+ additionalPayloads,
823
+ nbf,
824
+ exp,
825
+ fees,
826
+ from
827
+ ]);
828
+ }
829
+ };
830
+
831
+ // src/provider/signer/MemoryXyoSigner.ts
832
+ import { buildTransaction } from "@xyo-network/xl1-protocol";
833
+ var MemoryXyoSigner = class {
834
+ static {
835
+ __name(this, "MemoryXyoSigner");
836
+ }
837
+ _account;
838
+ constructor(account) {
839
+ this._account = account;
840
+ }
841
+ address() {
842
+ return this._account.address;
843
+ }
844
+ async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
845
+ const fromAddress = from ?? this._account.address;
846
+ const transaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, this._account, nbf, exp, fromAddress, fees);
847
+ return transaction[0];
848
+ }
849
+ };
850
+
851
+ // src/provider/viewer/JsonRpcXyoViewer.ts
852
+ var JsonRpcXyoViewer = class {
853
+ static {
854
+ __name(this, "JsonRpcXyoViewer");
855
+ }
856
+ transport;
857
+ constructor(transport) {
858
+ this.transport = transport;
859
+ }
860
+ async accountBalance(address, blockNumber, full) {
861
+ return await this.transport.sendRequest("xyoViewer_accountBalance", [
862
+ address,
863
+ blockNumber,
864
+ full
865
+ ]);
866
+ }
867
+ async blockByHash(hash) {
868
+ return await this.transport.sendRequest("xyoViewer_blockByHash", [
869
+ hash
870
+ ]);
871
+ }
872
+ async blockByNumber(blockNumber) {
873
+ return await this.transport.sendRequest("xyoViewer_blockByNumber", [
874
+ blockNumber
875
+ ]);
876
+ }
877
+ async blocksByHash(hash, limit) {
878
+ return await this.transport.sendRequest("xyoViewer_blocksByHash", [
879
+ hash,
880
+ limit
881
+ ]);
882
+ }
883
+ async chainId() {
884
+ return await this.transport.sendRequest("xyoViewer_chainId");
885
+ }
886
+ async currentBlock() {
887
+ return await this.transport.sendRequest("xyoViewer_currentBlock");
888
+ }
889
+ async currentBlockHash() {
890
+ return await this.transport.sendRequest("xyoViewer_currentBlockHash");
891
+ }
892
+ async currentBlockNumber() {
893
+ return await this.transport.sendRequest("xyoViewer_currentBlockNumber");
894
+ }
895
+ async transactionByBlockHashAndIndex(blockHash, transactionIndex) {
896
+ return await this.transport.sendRequest("xyoViewer_transactionByBlockHashAndIndex", [
897
+ blockHash,
898
+ transactionIndex
899
+ ]);
900
+ }
901
+ async transactionByBlockNumberAndIndex(blockNumber, transactionIndex) {
902
+ return await this.transport.sendRequest("xyoViewer_transactionByBlockNumberAndIndex", [
903
+ blockNumber,
904
+ transactionIndex
905
+ ]);
906
+ }
907
+ async transactionByHash(transactionHash) {
908
+ return await this.transport.sendRequest("xyoViewer_transactionByHash", [
909
+ transactionHash
910
+ ]);
911
+ }
912
+ };
913
+
914
+ // src/provider/viewer/NodeXyoViewer.ts
915
+ import { filterAs } from "@xylabs/array";
916
+ import { assertEx as assertEx3 } from "@xylabs/assert";
917
+ import { exists } from "@xylabs/exists";
918
+ import { asAddress } from "@xylabs/hex";
919
+ import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
920
+ import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
921
+ import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
922
+ import { analyzeChain, BalanceAnalyzer, findMostRecentBlock, hydrateBlock, hydrateTransaction, isChainSummaryBalances } from "@xyo-network/chain-protocol";
923
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
924
+ import { asOptionalBlockBoundWitnessWithStorageMeta, asOptionalTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-model";
925
+ var WindowLimit = 1e3;
926
+ var WindowLimitBigInt = BigInt(WindowLimit);
927
+ var NodeXyoViewer = class {
928
+ static {
929
+ __name(this, "NodeXyoViewer");
930
+ }
931
+ // TODO: Make configurable with defaults
932
+ finalizedArchivistPath = "XYOChain:Chain:Finalized";
933
+ headValidationDivinerPath = "XYOChain:Chain:HeadValidationDiviner";
934
+ node;
935
+ _chainId;
936
+ _finalizedArchivist;
937
+ _headValidationDiviner;
938
+ constructor(node) {
939
+ this.node = node;
940
+ }
941
+ async accountBalance(address, blockNumber, full) {
942
+ const head = await this.blockByNumber(blockNumber);
943
+ if (!head) {
944
+ throw new Error(`Error: Could not find block ${blockNumber}`);
945
+ }
946
+ const analysis = await analyzeChain(await this.getFinalizedArchivist(), [
947
+ new BalanceAnalyzer()
948
+ ], head, null, full ? -1n : WindowLimitBigInt);
949
+ const balances = assertEx3(analysis.find(isChainSummaryBalances)?.balances, () => "Failed to sync balances");
950
+ return balances[address] ? hexToBigInt2(balances[address]) : 0n;
951
+ }
952
+ async blockByHash(hash) {
953
+ const finalizedArchivist = await this.getFinalizedArchivist();
954
+ return await hydrateBlock(finalizedArchivist, hash);
955
+ }
956
+ async blockByNumber(blockNumber) {
957
+ const finalizedArchivist = await this.getFinalizedArchivist();
958
+ const result = await this.currentBlock();
959
+ let currentBlock = result[0];
960
+ if (currentBlock.block === blockNumber) return result;
961
+ if (blockNumber > currentBlock.block) throw new Error(`Error: Block number ${blockNumber} is greater than current block number ${currentBlock.block}`);
962
+ if (blockNumber < 0) throw new Error(`Error: Block number ${blockNumber} is less than 0`);
963
+ if (blockNumber - currentBlock.block > WindowLimit) throw new Error(`Error: Block number ${blockNumber} is too far in the past`);
964
+ do {
965
+ const { previous } = currentBlock;
966
+ if (previous === null) return null;
967
+ const nextBlock = asOptionalBlockBoundWitnessWithStorageMeta((await finalizedArchivist.get([
968
+ previous
969
+ ]))[0]);
970
+ if (!nextBlock) return null;
971
+ currentBlock = nextBlock;
972
+ } while (blockNumber != currentBlock.block);
973
+ return currentBlock.block === blockNumber ? await hydrateBlock(finalizedArchivist, currentBlock._hash) : null;
974
+ }
975
+ async blocksByHash(hash, limit = 10) {
976
+ assertEx3(limit > 0, () => "Error: limit must be greater than 0");
977
+ assertEx3(limit <= 100, () => "Error: limit must be less than 100");
978
+ const blocks = [];
979
+ let current = await this.blockByHash(hash);
980
+ while (current && blocks.length < limit) {
981
+ blocks.push(current);
982
+ const previousHash = current[0].previous;
983
+ if (!previousHash) break;
984
+ current = await this.blockByHash(previousHash);
985
+ }
986
+ return blocks;
987
+ }
988
+ async chainId() {
989
+ if (this._chainId) return this._chainId;
990
+ const headValidationDiviner = await this.getHeadValidationDiviner();
991
+ this._chainId = assertEx3(asAddress(headValidationDiviner.params.chainIdentification?.id), () => "HeadValidationDiviner.params.chainIdentification.id is required and must be an Address");
992
+ return await Promise.resolve(this._chainId);
993
+ }
994
+ async currentBlock() {
995
+ const finalizedArchivist = await this.getFinalizedArchivist();
996
+ return await hydrateBlock(finalizedArchivist, await this.currentBlockHash());
997
+ }
998
+ async currentBlockHash() {
999
+ const finalizedArchivist = await this.getFinalizedArchivist();
1000
+ const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
1001
+ return block._hash;
1002
+ }
1003
+ async currentBlockNumber() {
1004
+ const finalizedArchivist = await this.getFinalizedArchivist();
1005
+ const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
1006
+ return block.block;
1007
+ }
1008
+ async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
1009
+ assertEx3(transactionIndex >= 0, () => "Error: transactionIndex must be greater than or equal to 0");
1010
+ try {
1011
+ const block = await this.blockByHash(blockHash);
1012
+ if (!block) return null;
1013
+ const blockBoundWitnessIndexes = block[0].payload_schemas.map((schema, index) => schema === BoundWitnessSchema2 ? index : void 0).filter(exists);
1014
+ const blockBoundWitnessHashes = new Set(blockBoundWitnessIndexes.map((index) => block[0].payload_hashes[index]));
1015
+ const blockBoundWitnesses = block[1].filter((payload) => blockBoundWitnessHashes.has(payload._hash) || blockBoundWitnessHashes.has(payload._dataHash));
1016
+ const blockTransactionBoundWitnesses = filterAs(blockBoundWitnesses, asOptionalTransactionBoundWitnessWithStorageMeta);
1017
+ const transaction = blockTransactionBoundWitnesses.at(transactionIndex);
1018
+ if (!transaction) return null;
1019
+ return await this.transactionByHash(transaction._hash);
1020
+ } catch {
1021
+ return null;
1022
+ }
1023
+ }
1024
+ async transactionByBlockNumberAndIndex(blockNumber, transactionIndex = 0) {
1025
+ try {
1026
+ const block = await this.blockByNumber(blockNumber);
1027
+ if (!block) return null;
1028
+ return await this.transactionByBlockHashAndIndex(block[0]._hash, transactionIndex);
1029
+ } catch {
1030
+ return null;
1031
+ }
1032
+ }
1033
+ async transactionByHash(transactionHash) {
1034
+ try {
1035
+ const finalizedArchivist = await this.getFinalizedArchivist();
1036
+ return await hydrateTransaction(finalizedArchivist, transactionHash);
1037
+ } catch {
1038
+ return null;
1039
+ }
1040
+ }
1041
+ getArchivist = /* @__PURE__ */ __name(async (identifier) => {
1042
+ const diviner = await this.node.resolve(identifier);
1043
+ return assertEx3(asArchivistInstance2(diviner), () => `Error: Could not resolve ${identifier} to an archivist instance`);
1044
+ }, "getArchivist");
1045
+ getDiviner = /* @__PURE__ */ __name(async (identifier) => {
1046
+ const diviner = await this.node.resolve(identifier);
1047
+ return assertEx3(asDivinerInstance(diviner), () => `Error: Could not resolve ${identifier} to a diviner instance`);
1048
+ }, "getDiviner");
1049
+ getFinalizedArchivist = /* @__PURE__ */ __name(async () => {
1050
+ if (this._finalizedArchivist) return this._finalizedArchivist;
1051
+ this._finalizedArchivist = await this.getArchivist(this.finalizedArchivistPath);
1052
+ return this._finalizedArchivist;
1053
+ }, "getFinalizedArchivist");
1054
+ getHeadValidationDiviner = /* @__PURE__ */ __name(async () => {
1055
+ if (this._headValidationDiviner) return this._headValidationDiviner;
1056
+ this._headValidationDiviner = await this.getDiviner(this.headValidationDivinerPath);
1057
+ return this._headValidationDiviner;
1058
+ }, "getHeadValidationDiviner");
1059
+ };
1060
+
1061
+ // src/provider/wallet/JsonRpcXyoWallet.ts
1062
+ var JsonRpcXyoWallet = class {
1063
+ static {
1064
+ __name(this, "JsonRpcXyoWallet");
1065
+ }
1066
+ transport;
1067
+ constructor(transport) {
1068
+ this.transport = transport;
1069
+ }
1070
+ async accounts() {
1071
+ return await this.transport.sendRequest("xyoWallet_accounts");
1072
+ }
1073
+ async addChain(chain, name) {
1074
+ return await this.transport.sendRequest("xyoWallet_addChain", [
1075
+ chain,
1076
+ name
1077
+ ]);
1078
+ }
1079
+ async chain() {
1080
+ return await this.transport.sendRequest("xyoWallet_chain");
1081
+ }
1082
+ async chains() {
1083
+ return await this.transport.sendRequest("xyoWallet_chains");
1084
+ }
1085
+ async permissions() {
1086
+ return await this.transport.sendRequest("xyoWallet_permissions");
1087
+ }
1088
+ async requestPermissions(permissions) {
1089
+ return await this.transport.sendRequest("xyoWallet_requestPermissions", [
1090
+ permissions
1091
+ ]);
1092
+ }
1093
+ async revokePermissions(permissions) {
1094
+ return await this.transport.sendRequest("xyoWallet_revokePermissions", [
1095
+ permissions
1096
+ ]);
1097
+ }
1098
+ async switchChain(chain) {
1099
+ return await this.transport.sendRequest("xyoWallet_switchChain", [
1100
+ chain
1101
+ ]);
1102
+ }
1103
+ };
1104
+
1105
+ // src/provider/wallet/MemoryXyoWallet.ts
1106
+ import { assertEx as assertEx4 } from "@xylabs/assert";
1107
+ var MemoryXyoWallet = class {
1108
+ static {
1109
+ __name(this, "MemoryXyoWallet");
1110
+ }
1111
+ _account;
1112
+ _chain;
1113
+ _chains = {};
1114
+ constructor(account) {
1115
+ this._account = account;
1116
+ }
1117
+ accounts() {
1118
+ return [
1119
+ this._account.address
1120
+ ];
1121
+ }
1122
+ addChain(chain, name) {
1123
+ this._chains[chain] = name;
1124
+ return this.chains();
1125
+ }
1126
+ chain() {
1127
+ return assertEx4(this._chain, () => "Chain not set");
1128
+ }
1129
+ chains() {
1130
+ return this._chains;
1131
+ }
1132
+ permissions() {
1133
+ throw new Error("Method not implemented.");
1134
+ }
1135
+ requestPermissions(_permissions) {
1136
+ throw new Error("Method not implemented.");
1137
+ }
1138
+ revokePermissions(_permissions) {
1139
+ throw new Error("Method not implemented.");
1140
+ }
1141
+ switchChain(chain) {
1142
+ if (this._chains[chain]) {
1143
+ this._chain = chain;
1144
+ } else {
1145
+ throw new Error(`Chain ${chain} not found in wallet`);
1146
+ }
1147
+ }
1148
+ };
1149
+
1150
+ // src/transport/HttpRpcTransport.ts
1151
+ import { AxiosJson } from "@xylabs/axios";
1152
+ import { v4 } from "uuid";
1153
+ var HttpRpcTransport = class {
1154
+ static {
1155
+ __name(this, "HttpRpcTransport");
1156
+ }
1157
+ _rpcUrl;
1158
+ _schemas;
1159
+ constructor(rpcUrl, schemas) {
1160
+ this._rpcUrl = rpcUrl;
1161
+ this._schemas = schemas;
1162
+ }
1163
+ async sendRequest(method, params) {
1164
+ return await this.callRpc(this._rpcUrl, this._schemas, method, params);
1165
+ }
1166
+ async callRpc(url, schemas, method, params) {
1167
+ const id = v4();
1168
+ const body = {
1169
+ jsonrpc,
1170
+ id,
1171
+ method
1172
+ };
1173
+ if (params) {
1174
+ body.params = schemas[method].params.to.parse(params);
1175
+ }
1176
+ const res = await new AxiosJson().post(url, body);
1177
+ const json = res.data;
1178
+ if (!json || json.error) {
1179
+ throw new Error(json.error.message);
1180
+ }
1181
+ return schemas[method].result.from.parse(json.result);
1182
+ }
1183
+ };
1184
+
1185
+ // src/transport/MemoryRpcTransport.ts
1186
+ import { v4 as v42 } from "uuid";
1187
+ var MemoryRpcTransport = class {
1188
+ static {
1189
+ __name(this, "MemoryRpcTransport");
1190
+ }
1191
+ _rpcEngine;
1192
+ _schemas;
1193
+ requestSchemas = {};
1194
+ responseSchemas = {};
1195
+ constructor(rpcEngine, schemas = AllRpcSchemas) {
1196
+ this._rpcEngine = rpcEngine;
1197
+ this._schemas = schemas;
1198
+ }
1199
+ async sendRequest(method, params) {
1200
+ const schema = this._schemas[method];
1201
+ let requestSchema = this.requestSchemas[method];
1202
+ if (!requestSchema) {
1203
+ requestSchema = createRequestSchema(method, schema.params.to);
1204
+ this.requestSchemas[method] = requestSchema;
1205
+ }
1206
+ const req = {
1207
+ jsonrpc,
1208
+ id: v42(),
1209
+ method,
1210
+ params
1211
+ };
1212
+ const request = requestSchema.parse(req);
1213
+ const response = await this._rpcEngine.handle(request);
1214
+ let responseSchema = this.responseSchemas[method];
1215
+ if (!responseSchema) {
1216
+ responseSchema = createResponseSchema(schema.result.from);
1217
+ this.responseSchemas[method] = responseSchema;
1218
+ }
1219
+ return responseSchema.parse(response)?.result;
1220
+ }
1221
+ };
1222
+ export {
1223
+ AllRpcSchemas,
1224
+ HttpRpcTransport,
1225
+ JsonRpcErrorCodes,
1226
+ JsonRpcXyoRunner,
1227
+ JsonRpcXyoSigner,
1228
+ JsonRpcXyoViewer,
1229
+ JsonRpcXyoWallet,
1230
+ MemoryRpcTransport,
1231
+ MemoryXyoProvider,
1232
+ MemoryXyoRunner,
1233
+ MemoryXyoSigner,
1234
+ MemoryXyoWallet,
1235
+ NodeXyoRunner,
1236
+ NodeXyoViewer,
1237
+ XyoProviderRpcSchemas,
1238
+ XyoRunnerRpcSchemas,
1239
+ XyoSignerRpcSchemas,
1240
+ XyoViewerRpcSchemas,
1241
+ XyoWalletRpcSchemas,
1242
+ createRequestSchema,
1243
+ createResponseSchema,
1244
+ jsonrpc,
1245
+ rpcEngineFromProvider
1246
+ };
1247
+ //# sourceMappingURL=index.mjs.map