@arkiv-network/sdk 0.7.0 → 0.8.0-advanced.2

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 (237) hide show
  1. package/README.md +71 -16
  2. package/dist/actions/advanced/index.cjs +13 -0
  3. package/dist/actions/advanced/index.d.cts +8 -0
  4. package/dist/actions/advanced/index.d.ts +9 -0
  5. package/dist/actions/advanced/index.js +9 -0
  6. package/dist/advanced-8ZPTmmaN.js +598 -0
  7. package/dist/advanced-8ZPTmmaN.js.map +1 -0
  8. package/dist/advanced-fPImL6lW.cjs +656 -0
  9. package/dist/arkivTransactions-D74gERHG.d.cts +571 -0
  10. package/dist/arkivTransactions-D74gERHG.d.cts.map +1 -0
  11. package/dist/arkivTransactions-NtGD6uk5.d.ts +571 -0
  12. package/dist/arkivTransactions-NtGD6uk5.d.ts.map +1 -0
  13. package/dist/attr/index.cjs +35 -0
  14. package/dist/attr/index.d.cts +2 -0
  15. package/dist/attr/index.d.ts +3 -0
  16. package/dist/attr/index.js +4 -0
  17. package/dist/attributes-BhY5DwJp.js +809 -0
  18. package/dist/attributes-BhY5DwJp.js.map +1 -0
  19. package/dist/attributes-Df9IsCVs.cjs +1029 -0
  20. package/dist/chains/index.cjs +2 -3
  21. package/dist/chains/index.d.cts +39 -77
  22. package/dist/chains/index.d.cts.map +1 -1
  23. package/dist/chains/index.d.ts +22 -60
  24. package/dist/chains/index.d.ts.map +1 -1
  25. package/dist/chains/index.js +2 -2
  26. package/dist/chains-BJrZs6sG.js +57 -0
  27. package/dist/chains-BJrZs6sG.js.map +1 -0
  28. package/dist/chains-BYRTTipa.cjs +73 -0
  29. package/dist/codec-Car3KkFF.d.ts +102 -0
  30. package/dist/codec-Car3KkFF.d.ts.map +1 -0
  31. package/dist/entity/index.cjs +20 -0
  32. package/dist/entity/index.d.cts +4 -0
  33. package/dist/entity/index.d.ts +5 -0
  34. package/dist/entity/index.js +7 -0
  35. package/dist/entity-B00Li04j.cjs +71 -0
  36. package/dist/entity-B7G8q_Eo.cjs +0 -0
  37. package/dist/entity-BYQR1uoe.js +67 -0
  38. package/dist/entity-BYQR1uoe.js.map +1 -0
  39. package/dist/entity-CD_qFF2M.js +0 -0
  40. package/dist/errors-BVbjKVMN.cjs +56 -0
  41. package/dist/errors-LTe7bOYS.js +33 -0
  42. package/dist/errors-LTe7bOYS.js.map +1 -0
  43. package/dist/expiry-BELY2Kpw.cjs +135 -0
  44. package/dist/expiry-BjpxZZQU.js +95 -0
  45. package/dist/expiry-BjpxZZQU.js.map +1 -0
  46. package/dist/expiry-DRV29F1r.d.cts +79 -0
  47. package/dist/expiry-DRV29F1r.d.cts.map +1 -0
  48. package/dist/expiry-nDbCgZX4.d.ts +79 -0
  49. package/dist/expiry-nDbCgZX4.d.ts.map +1 -0
  50. package/dist/flags-5dTNRnow.d.ts +41 -0
  51. package/dist/flags-5dTNRnow.d.ts.map +1 -0
  52. package/dist/flags-CRjPpoh3.d.cts +41 -0
  53. package/dist/flags-CRjPpoh3.d.cts.map +1 -0
  54. package/dist/flags-DFBs2J94.js +33 -0
  55. package/dist/flags-DFBs2J94.js.map +1 -0
  56. package/dist/flags-kr276q6i.cjs +43 -0
  57. package/dist/index-B5j76711.d.ts +184 -0
  58. package/dist/index-B5j76711.d.ts.map +1 -0
  59. package/dist/index-BF7Mq9Is.d.cts +280 -0
  60. package/dist/index-BF7Mq9Is.d.cts.map +1 -0
  61. package/dist/index-CA4V7Pdh.d.cts +167 -0
  62. package/dist/index-CA4V7Pdh.d.cts.map +1 -0
  63. package/dist/index-CV5zCdpa.d.cts +417 -0
  64. package/dist/index-CV5zCdpa.d.cts.map +1 -0
  65. package/dist/index-DHDud2hC.d.ts +280 -0
  66. package/dist/index-DHDud2hC.d.ts.map +1 -0
  67. package/dist/index-DvYvrkdk.d.ts +320 -0
  68. package/dist/index-DvYvrkdk.d.ts.map +1 -0
  69. package/dist/index-EeUO0nnJ.d.cts +184 -0
  70. package/dist/index-EeUO0nnJ.d.cts.map +1 -0
  71. package/dist/index-fX_XyqLp.d.ts +167 -0
  72. package/dist/index-fX_XyqLp.d.ts.map +1 -0
  73. package/dist/index.cjs +422 -399
  74. package/dist/index.d.cts +364 -204
  75. package/dist/index.d.cts.map +1 -1
  76. package/dist/index.d.ts +365 -204
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +357 -389
  79. package/dist/index.js.map +1 -1
  80. package/dist/key-D1Bh7MF0.js +70 -0
  81. package/dist/key-D1Bh7MF0.js.map +1 -0
  82. package/dist/key-WKhXnXuU.cjs +98 -0
  83. package/dist/logger-CVpvU8ik.js +153 -0
  84. package/dist/logger-CVpvU8ik.js.map +1 -0
  85. package/dist/logger-Cr15lPAQ.cjs +188 -0
  86. package/dist/payload-BNoud2KZ.d.cts +94 -0
  87. package/dist/payload-BNoud2KZ.d.cts.map +1 -0
  88. package/dist/payload-Bz6651ax.js +67 -0
  89. package/dist/payload-Bz6651ax.js.map +1 -0
  90. package/dist/payload-CcUj85ys.d.ts +94 -0
  91. package/dist/payload-CcUj85ys.d.ts.map +1 -0
  92. package/dist/payload-KC14SDlN.cjs +83 -0
  93. package/dist/query/index.cjs +26 -149
  94. package/dist/query/index.d.cts +5 -3
  95. package/dist/query/index.d.ts +6 -3
  96. package/dist/query/index.js +8 -137
  97. package/dist/queryBuilder-DM6AWCBa.js +820 -0
  98. package/dist/queryBuilder-DM6AWCBa.js.map +1 -0
  99. package/dist/queryBuilder-DbUMEZln.cjs +944 -0
  100. package/dist/selection-C4UhsMOO.d.ts +434 -0
  101. package/dist/selection-C4UhsMOO.d.ts.map +1 -0
  102. package/dist/selection-DPg0uyJf.d.cts +433 -0
  103. package/dist/selection-DPg0uyJf.d.cts.map +1 -0
  104. package/dist/types/index.cjs +4 -1
  105. package/dist/types/index.d.cts +7 -2
  106. package/dist/types/index.d.ts +8 -2
  107. package/dist/types/index.js +4 -1
  108. package/dist/types-Bu_ZwMbZ.js +0 -0
  109. package/dist/types-NRqymi6S.cjs +0 -0
  110. package/dist/utils/index.cjs +4 -17
  111. package/dist/utils/index.d.cts +3 -17
  112. package/dist/utils/index.d.ts +3 -17
  113. package/dist/utils/index.js +4 -18
  114. package/package.json +26 -5
  115. package/src/actions/advanced/advanced.test.ts +258 -0
  116. package/src/actions/advanced/buildMutation.ts +104 -0
  117. package/src/actions/advanced/getMutationResult.ts +112 -0
  118. package/src/actions/advanced/index.ts +21 -0
  119. package/src/actions/advanced/pingTransaction.ts +43 -0
  120. package/src/actions/advanced/sendMutation.ts +59 -0
  121. package/src/actions/public/getEntity.ts +27 -43
  122. package/src/actions/public/getEntityNonce.ts +30 -0
  123. package/src/actions/public/predictEntityKeys.test.ts +143 -0
  124. package/src/actions/public/predictEntityKeys.ts +138 -0
  125. package/src/actions/public/query.ts +35 -67
  126. package/src/actions/public/watchEntityEvents.test.ts +414 -0
  127. package/src/actions/public/watchEntityEvents.ts +225 -0
  128. package/src/actions/wallet/changeOwnership.ts +8 -8
  129. package/src/actions/wallet/createEntity.ts +104 -26
  130. package/src/actions/wallet/deleteEntity.ts +2 -3
  131. package/src/actions/wallet/extendEntity.ts +39 -16
  132. package/src/actions/wallet/mutateEntities.test.ts +76 -0
  133. package/src/actions/wallet/mutateEntities.ts +23 -83
  134. package/src/actions/wallet/patchEntity.ts +90 -0
  135. package/src/attr/attributes.test.ts +120 -0
  136. package/src/attr/attributes.ts +190 -0
  137. package/src/attr/codec.test.ts +162 -0
  138. package/src/attr/codec.ts +220 -0
  139. package/src/attr/decimal.ts +86 -0
  140. package/src/attr/errors.ts +145 -0
  141. package/src/attr/index.ts +50 -0
  142. package/src/attr/names.ts +106 -0
  143. package/src/attr/types.ts +150 -0
  144. package/src/attr/values.test.ts +271 -0
  145. package/src/attr/values.ts +502 -0
  146. package/src/chains/cheesecake.ts +22 -0
  147. package/src/chains/index.ts +1 -2
  148. package/src/clients/createPublicClient.test.ts +3 -5
  149. package/src/clients/createPublicClient.ts +5 -4
  150. package/src/clients/createWalletClient.test.ts +2 -2
  151. package/src/clients/createWalletClient.ts +13 -7
  152. package/src/clients/decorators/arkivAdvanced.ts +144 -0
  153. package/src/clients/decorators/arkivPublic.ts +172 -139
  154. package/src/clients/decorators/arkivWallet.ts +106 -95
  155. package/src/consts.ts +2 -1
  156. package/src/entity/create.test.ts +184 -0
  157. package/src/entity/errors.ts +38 -0
  158. package/src/entity/events.ts +16 -0
  159. package/src/entity/expiry.test.ts +195 -0
  160. package/src/entity/expiry.ts +181 -0
  161. package/src/entity/flags.ts +65 -0
  162. package/src/entity/index.ts +15 -0
  163. package/src/entity/key.ts +68 -0
  164. package/src/entity/operations.ts +134 -0
  165. package/src/entity/params.ts +15 -0
  166. package/src/errors.ts +33 -28
  167. package/src/index.ts +19 -0
  168. package/src/query/engine.ts +68 -132
  169. package/src/query/errors.ts +151 -0
  170. package/src/query/expression.test.ts +286 -0
  171. package/src/query/expression.ts +493 -0
  172. package/src/query/index.ts +40 -4
  173. package/src/query/injection.test.ts +151 -0
  174. package/src/query/queryBuilder.test.ts +342 -637
  175. package/src/query/queryBuilder.ts +133 -359
  176. package/src/query/queryResult.ts +54 -51
  177. package/src/query/selection.test.ts +48 -98
  178. package/src/query/selection.ts +77 -65
  179. package/src/types/entity.test.ts +44 -155
  180. package/src/types/entity.ts +62 -44
  181. package/src/types/events.ts +64 -23
  182. package/src/types/index.ts +20 -16
  183. package/src/types/rpcSchema.ts +70 -33
  184. package/src/utils/arkivTransactions.test.ts +681 -38
  185. package/src/utils/arkivTransactions.ts +400 -115
  186. package/src/utils/chains.test.ts +21 -24
  187. package/src/utils/compression.ts +1 -1
  188. package/src/utils/entities.test.ts +62 -0
  189. package/src/utils/entities.ts +111 -29
  190. package/src/utils/expirationTime.ts +114 -10
  191. package/src/utils/logger.ts +2 -2
  192. package/src/utils/payload.ts +4 -2
  193. package/src/utils/revert.test.ts +99 -0
  194. package/src/utils/revert.ts +145 -0
  195. package/dist/chains-BifaY04V.cjs +0 -108
  196. package/dist/chains-CrtkVbBh.js +0 -86
  197. package/dist/chains-CrtkVbBh.js.map +0 -1
  198. package/dist/consts-AUoL-v42.cjs +0 -18
  199. package/dist/consts-BV4PR-de.js +0 -7
  200. package/dist/consts-BV4PR-de.js.map +0 -1
  201. package/dist/entity-B6g_EPm1.d.cts +0 -382
  202. package/dist/entity-B6g_EPm1.d.cts.map +0 -1
  203. package/dist/entity-qoLMAuuk.d.ts +0 -382
  204. package/dist/entity-qoLMAuuk.d.ts.map +0 -1
  205. package/dist/index-DdspxNAA.d.ts +0 -481
  206. package/dist/index-DdspxNAA.d.ts.map +0 -1
  207. package/dist/index-Ds9dwqb5.d.cts +0 -481
  208. package/dist/index-Ds9dwqb5.d.cts.map +0 -1
  209. package/dist/payload-B2kFJyah.d.ts +0 -6
  210. package/dist/payload-B2kFJyah.d.ts.map +0 -1
  211. package/dist/payload-CJN8fTvX.d.cts +0 -6
  212. package/dist/payload-CJN8fTvX.d.cts.map +0 -1
  213. package/dist/payload-Claf2jUO.js +0 -13
  214. package/dist/payload-Claf2jUO.js.map +0 -1
  215. package/dist/payload-DpA5PA-w.cjs +0 -23
  216. package/dist/query/index.js.map +0 -1
  217. package/dist/queryBuilder-D2uwP9jI.js +0 -704
  218. package/dist/queryBuilder-D2uwP9jI.js.map +0 -1
  219. package/dist/queryBuilder-UW2MCaX4.cjs +0 -792
  220. package/dist/utils/index.d.cts.map +0 -1
  221. package/dist/utils/index.d.ts.map +0 -1
  222. package/dist/utils/index.js.map +0 -1
  223. package/src/actions/public/buildQuery.ts +0 -10
  224. package/src/actions/public/subscribeEntityEvents.ts +0 -119
  225. package/src/actions/wallet/updateEntity.ts +0 -60
  226. package/src/chains/braga.ts +0 -26
  227. package/src/chains/kaolin.ts +0 -29
  228. package/src/query/engine.test.ts +0 -526
  229. package/src/query/predicate.test.ts +0 -461
  230. package/src/query/predicate.ts +0 -144
  231. package/src/query/queryResult.test.ts +0 -270
  232. package/src/query/selectQueryBuilder.test.ts +0 -210
  233. package/src/types/attributes.ts +0 -16
  234. package/src/utils/validation.test.ts +0 -60
  235. package/src/utils/validation.ts +0 -32
  236. /package/dist/{types-H-TSmRpm.js → attr-DlmErkvR.cjs} +0 -0
  237. /package/dist/{types-o3zWarRp.cjs → attr-GcQKatub.js} +0 -0
package/dist/index.cjs CHANGED
@@ -1,18 +1,28 @@
1
- const require_chains = require('./chains-BifaY04V.cjs');
2
- const require_queryBuilder = require('./queryBuilder-UW2MCaX4.cjs');
3
- const require_consts = require('./consts-AUoL-v42.cjs');
4
- require('./types-o3zWarRp.cjs');
5
- const require_payload = require('./payload-DpA5PA-w.cjs');
1
+ const require_chains = require('./chains-BYRTTipa.cjs');
2
+ const require_expiry = require('./expiry-BELY2Kpw.cjs');
3
+ const require_advanced = require('./advanced-fPImL6lW.cjs');
4
+ const require_attributes = require('./attributes-Df9IsCVs.cjs');
5
+ const require_key = require('./key-WKhXnXuU.cjs');
6
+ const require_errors = require('./errors-BVbjKVMN.cjs');
7
+ const require_flags = require('./flags-kr276q6i.cjs');
8
+ const require_logger = require('./logger-Cr15lPAQ.cjs');
9
+ require('./attr-DlmErkvR.cjs');
10
+ const require_entity = require('./entity-B00Li04j.cjs');
11
+ const require_queryBuilder = require('./queryBuilder-DbUMEZln.cjs');
12
+ require('./entity-B7G8q_Eo.cjs');
13
+ require('./types-NRqymi6S.cjs');
14
+ const require_payload = require('./payload-KC14SDlN.cjs');
6
15
  let viem = require("viem");
16
+ let viem_actions = require("viem/actions");
7
17
 
8
18
  //#region src/actions/public/getBlockTiming.ts
9
- const logger$9 = require_queryBuilder.getLogger("actions:public:get-block-timing");
19
+ const logger$8 = require_logger.getLogger("actions:public:get-block-timing");
10
20
  async function getBlockTiming(client) {
11
21
  const blockTiming = await client.request({
12
22
  method: "arkiv_getBlockTiming",
13
23
  params: []
14
24
  });
15
- logger$9("Block timing %o", blockTiming);
25
+ logger$8("Block timing %o", blockTiming);
16
26
  return {
17
27
  currentBlock: BigInt(blockTiming.current_block),
18
28
  currentBlockTime: blockTiming.current_block_time,
@@ -22,33 +32,26 @@ async function getBlockTiming(client) {
22
32
 
23
33
  //#endregion
24
34
  //#region src/actions/public/getEntity.ts
25
- async function getEntity(client, key) {
26
- let bytes;
27
- try {
28
- bytes = (0, viem.hexToBytes)(key);
29
- } catch {
30
- throw new Error(`Invalid key format: ${key}. Key must be a valid hex string.`);
31
- }
32
- if (bytes.length !== 32) throw new Error(`Invalid key length: ${bytes.length} bytes. Key must be 32 bytes (64 hex characters) long.`);
33
- const hexKey = (0, viem.bytesToHex)(bytes);
34
- const result = await client.request({
35
- method: "arkiv_query",
36
- params: [`$key = ${hexKey}`, { includeData: {
37
- key: true,
38
- attributes: true,
39
- payload: true,
40
- contentType: true,
41
- expiration: true,
42
- owner: true,
43
- creator: true,
44
- createdAtBlock: true,
45
- lastModifiedAtBlock: true,
46
- transactionIndexInBlock: true,
47
- operationIndexInTransaction: true
48
- } }]
35
+ /**
36
+ * Reads one entity by key, with every field selected.
37
+ *
38
+ * Returns a {@link FullEntity} rather than an {@link Entity}: the selection is fixed at `"*"`, so
39
+ * every field is populated and none of them needs a `?` at the call site. The bare `Entity` type
40
+ * has every field optional because a `select()` result carries only what it asked for.
41
+ *
42
+ * @throws {InvalidValueError} If the key is not 32 bytes.
43
+ * @throws {NoEntityFoundError} If no live entity has that key — it never existed, or it was
44
+ * deleted or has expired.
45
+ */
46
+ async function getEntity(client, entityKey) {
47
+ const { entities } = await require_queryBuilder.runQuery(client, {
48
+ query: require_queryBuilder.eq("$key", require_attributes.key(entityKey)).toString(),
49
+ select: require_queryBuilder.toRpcSelect("*"),
50
+ limit: 1
49
51
  });
50
- if (!result.data.length) throw new require_queryBuilder.NoEntityFoundError();
51
- return await require_queryBuilder.entityFromRpcResult(result.data[0]);
52
+ const entity = entities[0];
53
+ if (entity === void 0) throw new require_logger.NoEntityFoundError(entityKey);
54
+ return entity;
52
55
  }
53
56
 
54
57
  //#endregion
@@ -60,145 +63,295 @@ async function getEntityCount(client) {
60
63
  });
61
64
  }
62
65
 
66
+ //#endregion
67
+ //#region src/actions/public/getEntityNonce.ts
68
+ const logger$7 = require_logger.getLogger("actions:public:get-entity-nonce");
69
+ /**
70
+ * Reads an owner's entity-minting nonce — how many entities that account has created.
71
+ *
72
+ * This is not the account's transaction nonce. The engine keeps a separate counter per creator and
73
+ * mixes it into every key it mints, which is what makes two identical creates from one account land
74
+ * on different keys.
75
+ *
76
+ * @param owner - The account whose nonce to read.
77
+ * @returns The number of entities `owner` has created so far, which is the nonce its next create
78
+ * will use.
79
+ */
80
+ async function getEntityNonce(client, owner) {
81
+ const nonce = await (0, viem_actions.readContract)(client, {
82
+ address: require_expiry.ARKIV_ADDRESS,
83
+ abi: require_advanced.ENTITY_NONCE_ABI,
84
+ functionName: "entityNonce",
85
+ args: [owner]
86
+ });
87
+ logger$7("entity nonce of %s is %s", owner, nonce);
88
+ return nonce;
89
+ }
90
+
91
+ //#endregion
92
+ //#region src/actions/public/predictEntityKeys.ts
93
+ /**
94
+ * Works out the keys an account's next creates will be given, before sending them.
95
+ *
96
+ * A key is `keccak256(chainId ++ registry ++ owner ++ nonce ++ salt)`. Everything but the nonce is
97
+ * known to the caller, and the nonce is read here — so a batch can reference a key it is about to
98
+ * mint, storing it as a `key` attribute on a sibling entity created in the same transaction.
99
+ *
100
+ * Each key arrives paired with its salt, and the create must be given that salt: a create left to
101
+ * pick its own salt picks a random one, which mints a different key.
102
+ *
103
+ * The prediction is valid only while nothing else from this owner is in flight. Every create that
104
+ * lands first takes the nonce with it and moves these keys. For a key you can rely on
105
+ * unconditionally, read it back from the create instead — `createEntity` and `mutateEntities`
106
+ * report the keys the engine actually minted.
107
+ *
108
+ * @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
109
+ * @returns One `{ key, salt }` pair per create, in batch order. {@link PredictEntityKeysReturnType}
110
+ *
111
+ * @example A batch whose second entity points at its first.
112
+ * import { key } from "@arkiv-network/sdk/attr"
113
+ *
114
+ * const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
115
+ * await wallet.mutateEntities({
116
+ * creates: [
117
+ * { payload, contentType, expires, salt: parent.salt },
118
+ * {
119
+ * payload,
120
+ * contentType,
121
+ * expires,
122
+ * salt: child.salt,
123
+ * attributes: { parent: key(parent.key) },
124
+ * },
125
+ * ],
126
+ * })
127
+ */
128
+ async function predictEntityKeys(client, { owner, count, salts }) {
129
+ const resolvedSalts = resolveSalts(count, salts);
130
+ const chainId = client.chain?.id ?? await (0, viem_actions.getChainId)(client);
131
+ const nonce = await getEntityNonce(client, owner);
132
+ return resolvedSalts.map((salt, index) => ({
133
+ key: require_key.predictEntityKey({
134
+ owner,
135
+ nonce: nonce + BigInt(index),
136
+ salt,
137
+ chainId
138
+ }),
139
+ salt
140
+ }));
141
+ }
142
+ /** The salts to derive from: the ones given, or `count` fresh random ones. */
143
+ function resolveSalts(count, salts) {
144
+ if (salts !== void 0) {
145
+ if (salts.length === 0) throw new Error("predictEntityKeys: `salts` is empty — there is nothing to predict");
146
+ return salts.map(require_key.validateSalt);
147
+ }
148
+ if (count === void 0) throw new Error("predictEntityKeys: pass either `count` or `salts`");
149
+ if (!Number.isInteger(count) || count <= 0) throw new Error(`predictEntityKeys: \`count\` must be a positive whole number, got ${count}`);
150
+ return Array.from({ length: count }, () => require_key.randomSalt());
151
+ }
152
+
63
153
  //#endregion
64
154
  //#region src/actions/public/query.ts
65
- async function query(client, query$1, queryOptions) {
66
- const rpcQueryOptions = {
67
- includeData: {
68
- key: true,
69
- payload: queryOptions?.includeData?.payload ?? true,
70
- attributes: queryOptions?.includeData?.attributes ?? false,
71
- contentType: queryOptions?.includeData?.metadata ?? false,
72
- expiration: queryOptions?.includeData?.metadata ?? false,
73
- owner: queryOptions?.includeData?.metadata ?? false,
74
- creator: queryOptions?.includeData?.metadata ?? false,
75
- createdAtBlock: queryOptions?.includeData?.metadata ?? false,
76
- lastModifiedAtBlock: queryOptions?.includeData?.metadata ?? false,
77
- transactionIndexInBlock: queryOptions?.includeData?.metadata ?? false,
78
- operationIndexInTransaction: queryOptions?.includeData?.metadata ?? false
79
- },
80
- ...queryOptions?.atBlock !== void 0 && { atBlock: (0, viem.numberToHex)(queryOptions.atBlock) },
81
- ...queryOptions?.orderBy && { orderBy: queryOptions?.orderBy.map((order) => ({
82
- name: order.name,
83
- type: order.type,
84
- desc: order.desc === "desc"
85
- })) },
86
- ...queryOptions?.resultsPerPage !== void 0 && { resultsPerPage: (0, viem.numberToHex)(queryOptions.resultsPerPage) },
87
- ...queryOptions?.cursor !== void 0 && { cursor: queryOptions?.cursor }
88
- };
89
- const result = await client.request({
90
- method: "arkiv_query",
91
- params: [query$1, rpcQueryOptions]
155
+ /**
156
+ * Runs a single query and returns one page, with no builder in between.
157
+ *
158
+ * Takes either an {@link Expression} or a raw query string. The string form is an escape hatch for
159
+ * a query built elsewhere — it goes to the node exactly as written, with none of the name, type or
160
+ * operator checks the expression combinators apply.
161
+ *
162
+ * @throws {QueryError} If the node rejects the query.
163
+ */
164
+ function query(client, query$1, options = {}) {
165
+ return require_queryBuilder.runQuery(client, {
166
+ query: query$1.toString(),
167
+ select: require_queryBuilder.toRpcSelect(options.select),
168
+ limit: options.limit,
169
+ cursor: options.cursor,
170
+ atBlock: options.atBlock
92
171
  });
93
- return {
94
- entities: await Promise.all(result.data.map((entity) => require_queryBuilder.entityFromRpcResult(entity))),
95
- cursor: result.cursor,
96
- blockNumber: BigInt(result.blockNumber)
97
- };
98
172
  }
99
173
 
100
174
  //#endregion
101
- //#region src/actions/public/subscribeEntityEvents.ts
102
- const logger$8 = require_queryBuilder.getLogger("actions:public:subscribe-entity-events");
103
- const arkivABI = (0, viem.parseAbi)([
104
- "event ArkivEntityCreated(uint256 indexed entityKey, address indexed ownerAddress, uint256 expirationBlock, uint256 cost)",
105
- "event ArkivEntityUpdated(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)",
106
- "event ArkivEntityExpired(uint256 indexed entityKey, address indexed ownerAddress)",
107
- "event ArkivEntityDeleted(uint256 indexed entityKey, address indexed ownerAddress)",
108
- "event ArkivEntityBTLExtended(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)",
109
- "event ArkivEntityOwnerChanged(uint256 indexed entityKey, address indexed oldOwnerAddress, address indexed newOwnerAddress)"
110
- ]);
111
- async function subscribeEntityEvents(client, { onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpired, onEntityExpiresInExtended, onEntityOwnerChanged }, pollingInterval, fromBlock) {
112
- return client.watchEvent({
113
- pollingInterval: pollingInterval ?? 1e3,
114
- fromBlock,
115
- events: arkivABI,
175
+ //#region src/actions/public/watchEntityEvents.ts
176
+ const logger$6 = require_logger.getLogger("actions:public:watch-entity-events");
177
+ /**
178
+ * How often to poll, when the caller does not say.
179
+ *
180
+ * Half a block: fast enough that an event is never a whole block stale, slow enough not to hammer
181
+ * the node. viem's own default is derived from a 12-second Ethereum block and is far too slow here.
182
+ */
183
+ const DEFAULT_POLLING_INTERVAL = require_expiry.BLOCK_TIME * 1e3 / 2;
184
+ /**
185
+ * Watches entity events, calling the handlers you pass as they arrive.
186
+ *
187
+ * Every event here is decoded from a log the Arkiv operation address emitted, and carries the
188
+ * block, transaction and log index it came from — so consuming them in order replays exactly what
189
+ * the engine did.
190
+ *
191
+ * @param parameters - Handlers and options. {@link WatchEntityEventsParameters}
192
+ * @returns A function that stops the watcher.
193
+ *
194
+ *
195
+ * @example
196
+ * import { createPublicClient } from "@arkiv-network/sdk"
197
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
198
+ * import { http } from "viem"
199
+ *
200
+ * const client = createPublicClient({ chain: cheesecake, transport: http() })
201
+ *
202
+ * const unwatch = client.watchEntityEvents({
203
+ * onEntityCreated: ({ entityKey, owner, expiresAt }) =>
204
+ * console.log("created", entityKey, "by", owner, "until block", expiresAt),
205
+ * onEntityDeleted: ({ entityKey }) => console.log("deleted", entityKey),
206
+ * onError: (error) => console.error(error),
207
+ * })
208
+ *
209
+ * unwatch()
210
+ */
211
+ function watchEntityEvents(client, parameters) {
212
+ const { onEntityCreated, onEntityPatched, onExpiryExtended, onOwnershipTransferred, onEntityDeleted, onEvent, onError, fromBlock, pollingInterval = DEFAULT_POLLING_INTERVAL } = parameters;
213
+ const publicClient = client;
214
+ const reportError = onError ?? logToConsole;
215
+ function emit(event) {
216
+ deliver(onEvent, event);
217
+ switch (event.type) {
218
+ case "EntityCreated":
219
+ deliver(onEntityCreated, event);
220
+ break;
221
+ case "EntityPatched":
222
+ deliver(onEntityPatched, event);
223
+ break;
224
+ case "ExpiryExtended":
225
+ deliver(onExpiryExtended, event);
226
+ break;
227
+ case "OwnershipTransferred":
228
+ deliver(onOwnershipTransferred, event);
229
+ break;
230
+ case "EntityDeleted":
231
+ deliver(onEntityDeleted, event);
232
+ break;
233
+ }
234
+ }
235
+ /**
236
+ * Runs one handler, keeping its failure to itself.
237
+ *
238
+ * A handler that throws is the consumer's problem, not the watcher's: letting it escape would
239
+ * reject the poll, drop the rest of the batch, and take down every other handler with it.
240
+ */
241
+ function deliver(handler, event) {
242
+ if (handler === void 0) return;
243
+ try {
244
+ handler(event);
245
+ } catch (error) {
246
+ reportError(asError(error));
247
+ }
248
+ }
249
+ return publicClient.watchEvent({
250
+ address: require_expiry.ARKIV_ADDRESS,
251
+ events: require_key.ENTITY_EVENTS_ABI,
252
+ pollingInterval,
253
+ ...fromBlock !== void 0 && { fromBlock },
116
254
  onLogs: (logs) => {
117
- logger$8("logs from subscribeEntityEvents %o", logs);
255
+ logger$6("logs %o", logs);
118
256
  for (const log of logs) {
119
- const event = (0, viem.decodeEventLog)({
120
- abi: arkivABI,
121
- topics: log.topics,
122
- data: log.data
123
- });
124
- logger$8("event from subscribeEntityEvents %o", event);
125
- switch (event.eventName) {
126
- case "ArkivEntityCreated":
127
- onEntityCreated?.({
128
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
129
- owner: event.args.ownerAddress,
130
- expirationBlock: Number(event.args.expirationBlock),
131
- cost: event.args.cost
132
- });
133
- break;
134
- case "ArkivEntityUpdated":
135
- onEntityUpdated?.({
136
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
137
- owner: event.args.ownerAddress,
138
- oldExpirationBlock: Number(event.args.oldExpirationBlock),
139
- newExpirationBlock: Number(event.args.newExpirationBlock),
140
- cost: event.args.cost
141
- });
142
- break;
143
- case "ArkivEntityDeleted":
144
- onEntityDeleted?.({
145
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
146
- owner: event.args.ownerAddress
147
- });
148
- break;
149
- case "ArkivEntityBTLExtended":
150
- onEntityExpiresInExtended?.({
151
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
152
- owner: event.args.ownerAddress,
153
- oldExpirationBlock: Number(event.args.oldExpirationBlock),
154
- newExpirationBlock: Number(event.args.newExpirationBlock),
155
- cost: event.args.cost
156
- });
157
- break;
158
- case "ArkivEntityExpired":
159
- onEntityExpired?.({
160
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
161
- owner: event.args.ownerAddress
162
- });
163
- break;
164
- case "ArkivEntityOwnerChanged":
165
- onEntityOwnerChanged?.({
166
- entityKey: (0, viem.toHex)(event.args.entityKey, { size: 32 }),
167
- oldOwner: event.args.oldOwnerAddress,
168
- newOwner: event.args.newOwnerAddress
169
- });
170
- break;
171
- default:
172
- console.warn("unknown event from subscribeEntityEvents", event);
173
- break;
257
+ if (log.blockNumber === null || log.transactionHash === null || log.logIndex === null) continue;
258
+ const context = {
259
+ blockNumber: log.blockNumber,
260
+ transactionHash: log.transactionHash,
261
+ logIndex: log.logIndex
262
+ };
263
+ let event;
264
+ try {
265
+ event = toEntityEvent(log.topics, log.data, context);
266
+ } catch (error) {
267
+ reportError(asError(error));
268
+ continue;
174
269
  }
270
+ emit(event);
175
271
  }
176
272
  },
177
- onError: (error) => {
178
- console.error("error from subscribeEntityEvents", error);
179
- onError?.(error);
180
- }
273
+ onError: (error) => reportError(error)
181
274
  });
182
275
  }
276
+ /** The fallback when no `onError` was given — see {@link WatchEntityEventsParameters.onError}. */
277
+ function logToConsole(error) {
278
+ console.error("watchEntityEvents error", error);
279
+ }
280
+ /** Handlers take an `Error`, and a `throw` can be anything. */
281
+ function asError(error) {
282
+ return error instanceof Error ? error : new Error(String(error));
283
+ }
284
+ /**
285
+ * Decodes one log into the {@link EntityEvent} it carries.
286
+ *
287
+ * @throws If the log does not decode against {@link ENTITY_EVENTS_ABI}.
288
+ */
289
+ function toEntityEvent(topics, data, context) {
290
+ const decoded = (0, viem.decodeEventLog)({
291
+ abi: require_key.ENTITY_EVENTS_ABI,
292
+ topics,
293
+ data
294
+ });
295
+ switch (decoded.eventName) {
296
+ case "EntityCreated": return {
297
+ type: "EntityCreated",
298
+ ...context,
299
+ ...decoded.args,
300
+ creationFlags: require_flags.decodeCreationFlags(decoded.args.creationFlags)
301
+ };
302
+ case "EntityPatched": return {
303
+ type: "EntityPatched",
304
+ ...context,
305
+ ...decoded.args
306
+ };
307
+ case "ExpiryExtended": return {
308
+ type: "ExpiryExtended",
309
+ ...context,
310
+ ...decoded.args
311
+ };
312
+ case "OwnershipTransferred": return {
313
+ type: "OwnershipTransferred",
314
+ ...context,
315
+ ...decoded.args
316
+ };
317
+ case "EntityDeleted": return {
318
+ type: "EntityDeleted",
319
+ ...context,
320
+ ...decoded.args
321
+ };
322
+ }
323
+ }
324
+
325
+ //#endregion
326
+ //#region src/clients/decorators/arkivAdvanced.ts
327
+ function publicAdvancedActions(client) {
328
+ return {
329
+ pingTransaction: (txHash) => require_advanced.pingTransaction(client, txHash),
330
+ getMutationResult: (txHash) => require_advanced.getMutationResult(client, txHash),
331
+ decodeMutationResult: (receipt) => require_advanced.decodeMutationResult(receipt)
332
+ };
333
+ }
334
+ function walletAdvancedActions(client) {
335
+ return {
336
+ ...publicAdvancedActions(client),
337
+ buildMutation: (data, options) => require_advanced.buildMutation(client, data, options),
338
+ sendMutation: (data, options) => require_advanced.sendMutation(client, data, options)
339
+ };
340
+ }
183
341
 
184
342
  //#endregion
185
343
  //#region src/clients/decorators/arkivPublic.ts
186
344
  function publicArkivActions(client) {
187
345
  return {
188
- getEntity: (key) => getEntity(client, key),
346
+ getEntity: (key$1) => getEntity(client, key$1),
189
347
  query: (rawQuery, queryOptions) => query(client, rawQuery, queryOptions),
190
- buildQuery: () => new require_queryBuilder.QueryBuilder(client),
191
348
  select: (selection) => new require_queryBuilder.SelectQueryBuilder(client, selection),
192
349
  getBlockTiming: () => getBlockTiming(client),
193
350
  getEntityCount: () => getEntityCount(client),
194
- subscribeEntityEvents: ({ onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpired, onEntityExpiresInExtended }, pollingInterval, fromBlock) => subscribeEntityEvents(client, {
195
- onError,
196
- onEntityCreated,
197
- onEntityUpdated,
198
- onEntityDeleted,
199
- onEntityExpired,
200
- onEntityExpiresInExtended
201
- }, pollingInterval, fromBlock)
351
+ getEntityNonce: (owner) => getEntityNonce(client, owner),
352
+ predictEntityKeys: (parameters) => predictEntityKeys(client, parameters),
353
+ watchEntityEvents: (parameters) => watchEntityEvents(client, parameters),
354
+ advanced: publicAdvancedActions(client)
202
355
  };
203
356
  }
204
357
 
@@ -209,201 +362,36 @@ function publicArkivActions(client) {
209
362
  *
210
363
  * - Docs: https://docs.arkiv.network/ts-sdk/clients/public
211
364
  *
212
- * A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Braga JSON-RPC API](https://braga.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
365
+ * A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Cheesecake JSON-RPC API](https://rpc.cheesecake.db-chain.devnet.gobas.me) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
213
366
  *
214
367
  * @param parameters - Configuration object for the public client (chain, transport, etc.)
215
368
  * @returns A Arkiv Public Client. {@link PublicArkivClient}
216
369
  *
217
370
  * @example
218
- * import { createPublicClient, http } from 'arkiv'
219
- * import { braga } from 'arkiv/chains'
371
+ * import { createPublicClient } from "@arkiv-network/sdk"
372
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
373
+ * import { http } from "viem"
220
374
  *
221
375
  * const client = createPublicClient({
222
- * chain: braga,
376
+ * chain: cheesecake,
223
377
  * transport: http(),
224
378
  * })
225
379
  */
226
380
  function createPublicClient(parameters) {
227
- const { key = "public", name = "Public Client" } = parameters;
381
+ const { key: key$1 = "public", name = "Public Client" } = parameters;
228
382
  return (0, viem.createClient)({
229
383
  ...parameters,
230
- key,
384
+ key: key$1,
231
385
  name
232
386
  }).extend(viem.publicActions).extend(publicArkivActions);
233
387
  }
234
388
 
235
- //#endregion
236
- //#region src/utils/compression.ts
237
- const logger$7 = require_queryBuilder.getLogger("utils:compression");
238
- const isNode = typeof process !== "undefined" && process.versions?.node != null;
239
- let zlib = null;
240
- let brotli = null;
241
- async function getZlib() {
242
- if (!isNode) return null;
243
- if (!zlib) try {
244
- zlib = await import("zlib");
245
- } catch (error) {
246
- console.error("Error importing zlib", error);
247
- return null;
248
- }
249
- return zlib;
250
- }
251
- async function getBrotli() {
252
- if (brotli) return brotli;
253
- try {
254
- const brotliModule = await import("brotli-wasm");
255
- brotli = brotliModule.default ? await brotliModule.default : brotliModule;
256
- } catch (error) {
257
- console.error("Error importing brotli-wasm", error);
258
- return null;
259
- }
260
- return brotli;
261
- }
262
- async function compress(data) {
263
- logger$7("Compressing data size %d", data.length);
264
- if (isNode) {
265
- const zlibModule = await getZlib();
266
- if (zlibModule) try {
267
- const buffer = Buffer.from(data);
268
- const compressed = zlibModule.brotliCompressSync(buffer);
269
- const result = new Uint8Array(compressed);
270
- logger$7("Brotli compressed with zlib size %d", result.length);
271
- return result;
272
- } catch (error) {
273
- console.warn("zlib compression failed, falling back to brotli-wasm", error);
274
- }
275
- }
276
- const brotliInstance = await getBrotli();
277
- if (!brotliInstance) {
278
- console.warn("Brotli instance not found, not compressing data");
279
- return data;
280
- }
281
- const brotliCompressed = brotliInstance.compress(data);
282
- logger$7("Brotli compressed with wasm size %d", brotliCompressed.length);
283
- return brotliCompressed;
284
- }
285
-
286
- //#endregion
287
- //#region src/utils/validation.ts
288
- /**
289
- * Expiration on Arkiv is measured in blocks (1 block =
290
- * 2 seconds), so the value must be a positive integer that is
291
- * a multiple of the block time.
292
- *
293
- * @param expiresIn - The expiration in seconds.
294
- * @throws {InvalidExpirationError} If the value is not a positive integer that
295
- * is a multiple of the block time.
296
- */
297
- function validateExpiresIn(expiresIn) {
298
- if (!Number.isInteger(expiresIn) || expiresIn <= 0 || expiresIn % require_consts.BLOCK_TIME !== 0) throw new require_queryBuilder.InvalidExpirationError(expiresIn);
299
- }
300
- /**
301
- * Validates a single attribute. Arkiv supports string and number attribute
302
- * values, but numeric values must be integers.
303
- *
304
- * @param attribute - The attribute to validate.
305
- * @throws {InvalidAttributeError} If the attribute has a non-integer numeric
306
- * value.
307
- */
308
- function validateAttribute(attribute) {
309
- if (typeof attribute.value === "number" && !Number.isInteger(attribute.value)) throw new require_queryBuilder.InvalidAttributeError(attribute.key, attribute.value);
310
- }
311
-
312
- //#endregion
313
- //#region src/utils/arkivTransactions.ts
314
- const logger$6 = require_queryBuilder.getLogger("utils:arkiv-transactions");
315
- function opsToTxData({ creates, updates, deletes, extensions, ownershipChanges }) {
316
- function formatAttributes(attribute) {
317
- return [(0, viem.toHex)(attribute.key), (0, viem.toHex)(typeof attribute.value === "number" && attribute.value === 0 ? "" : attribute.value)];
318
- }
319
- const payload = [
320
- (creates ?? []).map((item) => {
321
- validateExpiresIn(item.expiresIn);
322
- item.attributes.forEach(validateAttribute);
323
- return [
324
- (0, viem.toHex)(item.expiresIn / require_consts.BLOCK_TIME),
325
- (0, viem.toHex)(item.contentType),
326
- (0, viem.toHex)(item.payload),
327
- item.attributes.filter((attribute) => typeof attribute.value === "string").map(formatAttributes),
328
- item.attributes.filter((attribute) => typeof attribute.value === "number").map(formatAttributes)
329
- ];
330
- }),
331
- (updates ?? []).map((item) => {
332
- validateExpiresIn(item.expiresIn);
333
- item.attributes.forEach(validateAttribute);
334
- return [
335
- item.entityKey,
336
- (0, viem.toHex)(item.contentType),
337
- (0, viem.toHex)(item.expiresIn / require_consts.BLOCK_TIME),
338
- (0, viem.toHex)(item.payload),
339
- item.attributes.filter((attribute) => typeof attribute.value === "string").map(formatAttributes),
340
- item.attributes.filter((attribute) => typeof attribute.value === "number").map(formatAttributes)
341
- ];
342
- }),
343
- (deletes ?? []).map((item) => item.entityKey),
344
- (extensions ?? []).map((item) => {
345
- validateExpiresIn(item.expiresIn);
346
- return [item.entityKey, (0, viem.toHex)(item.expiresIn / require_consts.BLOCK_TIME)];
347
- }),
348
- (ownershipChanges ?? []).map((item) => [item.entityKey, item.newOwner])
349
- ];
350
- logger$6("txData to send as RLP %o length %d", payload, payload.length);
351
- return (0, viem.toRlp)(payload);
352
- }
353
- async function sendArkivTransaction(client, data, txParams) {
354
- if (!client.account) throw new Error("Account required");
355
- const walletClient = client;
356
- logger$6("Sending transaction %o", {
357
- account: client.account,
358
- chain: client.chain,
359
- to: require_consts.ARKIV_ADDRESS,
360
- value: 0n,
361
- data,
362
- ...txParams
363
- });
364
- try {
365
- const compressed = await compress((0, viem.toBytes)(data));
366
- const txHash = await walletClient.sendTransaction({
367
- account: client.account,
368
- chain: client.chain,
369
- to: require_consts.ARKIV_ADDRESS,
370
- value: 0n,
371
- data: (0, viem.toHex)(compressed),
372
- ...txParams
373
- });
374
- const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash });
375
- logger$6("Tx receipt %o", receipt);
376
- if (receipt.status === "reverted") try {
377
- const callResult = await walletClient.call({
378
- account: client.account,
379
- to: require_consts.ARKIV_ADDRESS,
380
- value: 0n,
381
- data: (0, viem.toHex)(compressed),
382
- ...txParams
383
- });
384
- throw new require_queryBuilder.EntityMutationError(`Transaction ${receipt.transactionHash} reverted. Please make sure the data for entities doesn't contain invalid characters or invalid data types.
385
- Reason: ${callResult.data ? (0, viem.hexToString)(callResult.data) : "No reason provided by backend."}`);
386
- } catch (err) {
387
- const reason = err.cause?.details ?? "No reason provided by backend.";
388
- logger$6("Error while calling to get more details about reverted transaction. Reason: %s", reason);
389
- throw new require_queryBuilder.EntityMutationError(`Transaction ${receipt.transactionHash} reverted. Reason: ${reason}`);
390
- }
391
- return receipt;
392
- } catch (error) {
393
- let message = "Transaction failed";
394
- if (error instanceof viem.TransactionExecutionError) message += `: ${error.details}`;
395
- else if (error instanceof require_queryBuilder.EntityMutationError) throw error;
396
- logger$6("%s Detailed error stack: %o", message, error);
397
- throw new require_queryBuilder.EntityMutationError(message);
398
- }
399
- }
400
-
401
389
  //#endregion
402
390
  //#region src/actions/wallet/changeOwnership.ts
403
- const logger$5 = require_queryBuilder.getLogger("actions:wallet:change-ownership");
391
+ const logger$5 = require_logger.getLogger("actions:wallet:change-ownership");
404
392
  async function changeOwnership(client, data, txParams) {
405
393
  logger$5("changeOwnership %o", data);
406
- const receipt = await sendArkivTransaction(client, opsToTxData({ ownershipChanges: [data] }), txParams);
394
+ const { receipt } = await require_advanced.sendArkivTransaction(client, { ownershipChanges: [data] }, txParams);
407
395
  logger$5("Receipt from changeOwnership %o", receipt);
408
396
  return {
409
397
  txHash: receipt.transactionHash,
@@ -413,23 +401,27 @@ async function changeOwnership(client, data, txParams) {
413
401
 
414
402
  //#endregion
415
403
  //#region src/actions/wallet/createEntity.ts
416
- const logger$4 = require_queryBuilder.getLogger("actions:wallet:create-entity");
404
+ const logger$4 = require_logger.getLogger("actions:wallet:create-entity");
417
405
  async function createEntity(client, data, txParams) {
418
406
  logger$4("createEntity %o", data);
419
- const receipt = await sendArkivTransaction(client, opsToTxData({ creates: [data] }), txParams);
407
+ const { receipt, createdEntityKeys, createdExpiries } = await require_advanced.sendArkivTransaction(client, { creates: [data] }, txParams);
420
408
  logger$4("Receipt from createEntity %o", receipt);
409
+ const [entityKey] = createdEntityKeys;
410
+ const [expiresAt] = createdExpiries;
411
+ if (entityKey === void 0 || expiresAt === void 0) throw new require_logger.EntityMutationError(`Transaction ${receipt.transactionHash} succeeded, but the receipt did not carry the expected entity key or expiry.`);
421
412
  return {
422
413
  txHash: receipt.transactionHash,
423
- entityKey: receipt.logs[0].topics[1]
414
+ entityKey,
415
+ expiresAt
424
416
  };
425
417
  }
426
418
 
427
419
  //#endregion
428
420
  //#region src/actions/wallet/deleteEntity.ts
429
- const logger$3 = require_queryBuilder.getLogger("actions:wallet:delete-entity");
421
+ const logger$3 = require_logger.getLogger("actions:wallet:delete-entity");
430
422
  async function deleteEntity(client, data, txParams) {
431
423
  logger$3("deleteEntity %o", data);
432
- const receipt = await sendArkivTransaction(client, opsToTxData({ deletes: [data] }), txParams);
424
+ const { receipt } = await require_advanced.sendArkivTransaction(client, { deletes: [data] }, txParams);
433
425
  logger$3("Receipt from deleteEntity %o", receipt);
434
426
  return {
435
427
  txHash: receipt.transactionHash,
@@ -439,77 +431,46 @@ async function deleteEntity(client, data, txParams) {
439
431
 
440
432
  //#endregion
441
433
  //#region src/actions/wallet/extendEntity.ts
442
- const logger$2 = require_queryBuilder.getLogger("actions:wallet:extend-entity");
434
+ const logger$2 = require_logger.getLogger("actions:wallet:extend-entity");
443
435
  async function extendEntity(client, data, txParams) {
444
436
  logger$2("extendEntity %o", data);
445
- const receipt = await sendArkivTransaction(client, opsToTxData({ extensions: [data] }), txParams);
437
+ const { receipt, extendedExpiries } = await require_advanced.sendArkivTransaction(client, { extensions: [data] }, txParams);
446
438
  logger$2("Receipt from extendEntity %o", receipt);
439
+ const [expiresAt] = extendedExpiries;
440
+ if (expiresAt === void 0) throw new require_logger.EntityMutationError(`Transaction ${receipt.transactionHash} succeeded, but the receipt did not carry the expected entity expiry.`);
447
441
  return {
448
442
  txHash: receipt.transactionHash,
449
- entityKey: receipt.logs[0].topics[1]
443
+ entityKey: data.entityKey,
444
+ expiresAt
450
445
  };
451
446
  }
452
447
 
453
448
  //#endregion
454
449
  //#region src/actions/wallet/mutateEntities.ts
455
- const logger$1 = require_queryBuilder.getLogger("actions:wallet:mutate-entities");
456
- function parseReceipt(receipt, params) {
457
- const createdEntities = [];
458
- const updatedEntities = [];
459
- const deletedEntities = [];
460
- const extendedEntities = [];
461
- const ownershipChanges = [];
462
- const totalCreates = params.creates?.length ?? 0;
463
- const totalUpdates = params.updates?.length ?? 0;
464
- const totalDeletes = params.deletes?.length ?? 0;
465
- const totalExtensions = params.extensions?.length ?? 0;
466
- for (let index = 0; index < receipt.logs.length; index++) {
467
- const log = receipt.logs[index];
468
- if (index < totalCreates) createdEntities.push(log.topics[1]);
469
- else if (index < totalCreates + totalDeletes) deletedEntities.push(log.topics[1]);
470
- else if (index < totalCreates + totalUpdates + totalDeletes) updatedEntities.push(log.topics[1]);
471
- else if (index < totalCreates + totalUpdates + totalDeletes + totalExtensions) extendedEntities.push(log.topics[1]);
472
- else ownershipChanges.push(log.topics[1]);
473
- }
474
- return {
475
- createdEntities,
476
- updatedEntities,
477
- deletedEntities,
478
- extendedEntities,
479
- ownershipChanges
480
- };
481
- }
450
+ const logger$1 = require_logger.getLogger("actions:wallet:mutate-entities");
482
451
  async function mutateEntities(client, data, txParams) {
483
- if (!data.creates && !data.updates && !data.deletes && !data.extensions) throw new Error("No operations to perform");
484
- const receipt = await sendArkivTransaction(client, opsToTxData({
485
- creates: data.creates ?? [],
486
- updates: data.updates ?? [],
487
- deletes: data.deletes ?? [],
488
- extensions: data.extensions ?? [],
489
- ownershipChanges: data.ownershipChanges ?? []
490
- }), txParams);
452
+ const { receipt, createdEntityKeys } = await require_advanced.sendArkivTransaction(client, data, txParams);
491
453
  logger$1("Receipt from mutateEntities %o", receipt);
492
- const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } = parseReceipt(receipt, data);
493
454
  return {
494
455
  txHash: receipt.transactionHash,
495
- createdEntities,
496
- updatedEntities,
497
- deletedEntities,
498
- extendedEntities,
499
- ownershipChanges
456
+ createdEntities: createdEntityKeys,
457
+ patchedEntities: (data.patches ?? []).map((p) => p.entityKey),
458
+ deletedEntities: (data.deletes ?? []).map((d) => d.entityKey),
459
+ extendedEntities: (data.extensions ?? []).map((e) => e.entityKey),
460
+ ownershipChanges: (data.ownershipChanges ?? []).map((o) => o.entityKey)
500
461
  };
501
462
  }
502
463
 
503
464
  //#endregion
504
- //#region src/actions/wallet/updateEntity.ts
505
- const logger = require_queryBuilder.getLogger("actions:wallet:update-entity");
506
- async function updateEntity(client, data, txParams) {
507
- logger("updateEntity %o", data);
508
- const receipt = await sendArkivTransaction(client, opsToTxData({ updates: [data] }), txParams);
509
- logger("Receipt from updateEntity %o", receipt);
465
+ //#region src/actions/wallet/patchEntity.ts
466
+ const logger = require_logger.getLogger("actions:wallet:patch-entity");
467
+ async function patchEntity(client, data, txParams) {
468
+ logger("patchEntity %o", data);
469
+ const { receipt } = await require_advanced.sendArkivTransaction(client, { patches: [data] }, txParams);
470
+ logger("Receipt from patchEntity %o", receipt);
510
471
  return {
511
472
  txHash: receipt.transactionHash,
512
- entityKey: receipt.logs[0].topics[1]
473
+ entityKey: data.entityKey
513
474
  };
514
475
  }
515
476
 
@@ -518,47 +479,54 @@ async function updateEntity(client, data, txParams) {
518
479
  function walletArkivActions(client) {
519
480
  return {
520
481
  createEntity: (data, txParams) => createEntity(client, data, txParams),
521
- updateEntity: (data, txParams) => updateEntity(client, data, txParams),
482
+ patchEntity: (data, txParams) => patchEntity(client, data, txParams),
522
483
  deleteEntity: (data, txParams) => deleteEntity(client, data, txParams),
523
484
  extendEntity: (data, txParams) => extendEntity(client, data, txParams),
524
485
  changeOwnership: (data, txParams) => changeOwnership(client, data, txParams),
525
- mutateEntities: (data, txParams) => mutateEntities(client, data, txParams)
486
+ mutateEntities: (data, txParams) => mutateEntities(client, data, txParams),
487
+ advanced: walletAdvancedActions(client)
526
488
  };
527
489
  }
528
490
 
529
491
  //#endregion
530
492
  //#region src/clients/createWalletClient.ts
531
493
  /**
532
- * Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
494
+ * Creates a Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro) configured
495
+ * for a [Chain](https://viem.sh/docs/clients/chains) and an account.
533
496
  *
534
- * - Docs: https://docs.arkiv.network/ts-sdk/clients/public
497
+ * - Docs: https://docs.arkiv.network/ts-sdk/clients/wallet
535
498
  *
536
- * A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Braga JSON-RPC API](https://braga.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
499
+ * A Wallet Client signs and sends transactions, so it carries an `account` and exposes everything
500
+ * that mutates state — `createEntity`, `patchEntity`, `deleteEntity`, `extendEntity`,
501
+ * `changeOwnership` and `mutateEntities` — on top of the read actions a Public Client has.
537
502
  *
538
503
  * @param parameters - Configuration object for the wallet client (chain, transport, account, etc.)
539
504
  * @returns A Arkiv Wallet Client. {@link WalletArkivClient}
540
505
  *
541
506
  * @example
542
- * import { createPublicClient, http } from 'arkiv'
543
- * import { braga } from 'arkiv/chains'
507
+ * import { createWalletClient } from "@arkiv-network/sdk"
508
+ * import { cheesecake } from "@arkiv-network/sdk/chains"
509
+ * import { http } from "viem"
510
+ * import { privateKeyToAccount } from "viem/accounts"
544
511
  *
545
- * const client = createPublicClient({
546
- * chain: braga,
512
+ * const client = createWalletClient({
513
+ * chain: cheesecake,
547
514
  * transport: http(),
515
+ * account: privateKeyToAccount("0x..."),
548
516
  * })
549
517
  */
550
518
  function createWalletClient(parameters) {
551
- const { key = "wallet", name = "Wallet Client" } = parameters;
519
+ const { key: key$1 = "wallet", name = "Wallet Client" } = parameters;
552
520
  return (0, viem.createClient)({
553
521
  ...parameters,
554
- key,
522
+ key: key$1,
555
523
  name
556
524
  }).extend(viem.publicActions).extend(viem.walletActions).extend(walletArkivActions);
557
525
  }
558
526
 
559
527
  //#endregion
560
528
  //#region src/utils/chains.ts
561
- const chainMap = new Map(Object.entries(require_chains.chains_exports).map(([key, value]) => [key.toLowerCase(), value]));
529
+ const chainMap = new Map(Object.entries(require_chains.chains_exports).map(([key$1, value]) => [key$1.toLowerCase(), value]));
562
530
  /**
563
531
  * Get a chain from its name
564
532
  * @param name - The name of the chain, case insensitive
@@ -572,14 +540,69 @@ function chainFromName(name) {
572
540
  }
573
541
 
574
542
  //#endregion
575
- exports.EntityMutationError = require_queryBuilder.EntityMutationError;
576
- exports.InvalidAttributeError = require_queryBuilder.InvalidAttributeError;
577
- exports.InvalidExpirationError = require_queryBuilder.InvalidExpirationError;
578
- exports.NoCursorOrLimitError = require_queryBuilder.NoCursorOrLimitError;
579
- exports.NoEntityFoundError = require_queryBuilder.NoEntityFoundError;
580
- exports.NoMoreResultsError = require_queryBuilder.NoMoreResultsError;
543
+ exports.ConflictingMutationError = require_attributes.ConflictingMutationError;
544
+ exports.DECIMAL_SCALE = require_attributes.DECIMAL_SCALE;
545
+ exports.DECIMAL_UNIT = require_attributes.DECIMAL_UNIT;
546
+ exports.ENTITY_EVENTS_ABI = require_key.ENTITY_EVENTS_ABI;
547
+ exports.EmptyPatchError = require_logger.EmptyPatchError;
548
+ exports.Entity = require_entity.Entity;
549
+ exports.EntityMutationError = require_logger.EntityMutationError;
550
+ exports.ExpirationTime = require_payload.ExpirationTime;
551
+ exports.I32_MAX = require_attributes.I32_MAX;
552
+ exports.I32_MIN = require_attributes.I32_MIN;
553
+ exports.InvalidAttributeNameError = require_attributes.InvalidAttributeNameError;
554
+ exports.InvalidContentTypeError = require_logger.InvalidContentTypeError;
555
+ exports.InvalidCreationFlagsError = require_errors.InvalidCreationFlagsError;
556
+ exports.InvalidExpiryError = require_errors.InvalidExpiryError;
557
+ exports.InvalidSaltError = require_errors.InvalidSaltError;
558
+ exports.InvalidValueError = require_attributes.InvalidValueError;
559
+ exports.MAX_ATTRIBUTES = require_attributes.MAX_ATTRIBUTES;
560
+ exports.MAX_EXPIRES_AT = require_expiry.MAX_EXPIRES_AT;
561
+ exports.MAX_NAME_BYTES = require_attributes.MAX_NAME_BYTES;
562
+ exports.MAX_PAYLOAD_BYTES = require_attributes.MAX_PAYLOAD_BYTES;
563
+ exports.MAX_SALT = require_key.MAX_SALT;
564
+ exports.MAX_STRING_BYTES = require_attributes.MAX_STRING_BYTES;
565
+ exports.MissingValueError = require_attributes.MissingValueError;
566
+ exports.NoEntityFoundError = require_logger.NoEntityFoundError;
567
+ exports.NoMoreResultsError = require_logger.NoMoreResultsError;
568
+ exports.NoRandomSourceError = require_errors.NoRandomSourceError;
569
+ exports.OperationType = require_expiry.OperationType;
570
+ exports.TooManyAttributesError = require_attributes.TooManyAttributesError;
571
+ exports.U256_MAX = require_attributes.U256_MAX;
572
+ exports.U64_MAX = require_attributes.U64_MAX;
573
+ exports.UnknownAttributeTypeError = require_attributes.UnknownAttributeTypeError;
574
+ exports.UntypedValueError = require_attributes.UntypedValueError;
575
+ exports.addr = require_attributes.addr;
576
+ exports.bool = require_attributes.bool;
577
+ exports.buildEntityOperations = require_advanced.buildEntityOperations;
578
+ exports.buildMutation = require_advanced.buildMutation;
579
+ exports.bytes32 = require_attributes.bytes32;
581
580
  exports.chainFromName = chainFromName;
581
+ exports.collectMutationEvents = require_advanced.collectMutationEvents;
582
582
  exports.createPublicClient = createPublicClient;
583
583
  exports.createWalletClient = createWalletClient;
584
+ exports.dec = require_attributes.dec;
585
+ exports.decFromUnits = require_attributes.decFromUnits;
586
+ exports.decUnits = require_attributes.decUnits;
587
+ exports.decodeCreationFlags = require_flags.decodeCreationFlags;
588
+ exports.decodeMutationResult = require_advanced.decodeMutationResult;
589
+ exports.encodeCreationFlags = require_flags.encodeCreationFlags;
590
+ exports.getMutationResult = require_advanced.getMutationResult;
591
+ exports.i32 = require_attributes.i32;
592
+ exports.isArkivValue = require_attributes.isArkivValue;
593
+ exports.isValidAttributeName = require_attributes.isValidAttributeName;
584
594
  exports.jsonToPayload = require_payload.jsonToPayload;
585
- exports.stringToPayload = require_payload.stringToPayload;
595
+ exports.key = require_attributes.key;
596
+ exports.mutationNeedsBlockNumber = require_advanced.mutationNeedsBlockNumber;
597
+ exports.pingTransaction = require_advanced.pingTransaction;
598
+ exports.predictEntityKey = require_key.predictEntityKey;
599
+ exports.randomSalt = require_key.randomSalt;
600
+ exports.resolveExpiry = require_expiry.resolveExpiry;
601
+ exports.sendMutation = require_advanced.sendMutation;
602
+ exports.str = require_attributes.str;
603
+ exports.stringToPayload = require_payload.stringToPayload;
604
+ exports.toBlocks = require_expiry.toBlocks;
605
+ exports.toValue = require_attributes.toValue;
606
+ exports.u256 = require_attributes.u256;
607
+ exports.u64 = require_attributes.u64;
608
+ exports.validateAttributeName = require_attributes.validateAttributeName;