@arkiv-network/sdk 0.1.1-dev.0 → 0.1.2-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +22 -10
  2. package/dist/chains/index.cjs +1 -0
  3. package/dist/chains/index.d.ts +25 -25
  4. package/dist/chains/index.d.ts.map +1 -1
  5. package/dist/index.cjs +40 -10
  6. package/dist/index.js +13 -8
  7. package/dist/index.js.map +1 -1
  8. package/dist/query/index.cjs +1 -1
  9. package/dist/{queryBuilder-n9ocnT4P.cjs → queryBuilder-okYHE7jd.cjs} +1 -0
  10. package/dist/utils/index.cjs +1 -0
  11. package/dist/utils/index.d.cts.map +1 -1
  12. package/dist/utils/index.d.ts.map +1 -1
  13. package/package.json +22 -8
  14. package/src/accounts/index.ts +1 -0
  15. package/src/actions/public/buildQuery.ts +6 -0
  16. package/src/actions/public/getBlockTiming.ts +20 -0
  17. package/src/actions/public/getEntity.ts +18 -0
  18. package/src/actions/public/getEntityCount.ts +10 -0
  19. package/src/actions/public/query.ts +13 -0
  20. package/src/actions/public/subscribeEntityEvents.ts +105 -0
  21. package/src/actions/wallet/changeOwnership.ts +40 -0
  22. package/src/actions/wallet/createEntity.ts +45 -0
  23. package/src/actions/wallet/deleteEntity.ts +39 -0
  24. package/src/actions/wallet/extendEntity.ts +41 -0
  25. package/src/actions/wallet/mutateEntities.ts +100 -0
  26. package/src/actions/wallet/updateEntity.ts +47 -0
  27. package/src/chains/index.ts +3 -0
  28. package/src/chains/kaolin.ts +26 -0
  29. package/src/chains/localhost.ts +14 -0
  30. package/src/chains/marketplace.ts +26 -0
  31. package/src/clients/baseClient.ts +9 -0
  32. package/src/clients/createPublicClient.test.ts +22 -0
  33. package/src/clients/createPublicClient.ts +65 -0
  34. package/src/clients/createWalletClient.test.ts +23 -0
  35. package/src/clients/createWalletClient.ts +70 -0
  36. package/src/clients/decorators/arkivPublic.ts +203 -0
  37. package/src/clients/decorators/arkivWallet.ts +250 -0
  38. package/src/consts.ts +2 -0
  39. package/src/index.ts +21 -0
  40. package/src/query/engine.test.ts +288 -0
  41. package/src/query/engine.ts +112 -0
  42. package/src/query/errors.ts +23 -0
  43. package/src/query/index.ts +4 -0
  44. package/src/query/predicate.test.ts +418 -0
  45. package/src/query/predicate.ts +140 -0
  46. package/src/query/queryBuilder.test.ts +537 -0
  47. package/src/query/queryBuilder.ts +209 -0
  48. package/src/query/queryResult.test.ts +270 -0
  49. package/src/query/queryResult.ts +61 -0
  50. package/src/types/attributes.ts +4 -0
  51. package/src/types/entity.ts +36 -0
  52. package/src/types/events.ts +34 -0
  53. package/src/types/index.ts +4 -0
  54. package/src/types/mimeTypes.ts +27 -0
  55. package/src/types/rpcSchema.ts +61 -0
  56. package/src/types/txParams.ts +15 -0
  57. package/src/utils/arkivTransactions.ts +100 -0
  58. package/src/utils/compression.test.ts +32 -0
  59. package/src/utils/compression.ts +48 -0
  60. package/src/utils/entities.ts +23 -0
  61. package/src/utils/expirationTime.ts +13 -0
  62. package/src/utils/index.ts +3 -0
  63. package/src/utils/payload.ts +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkiv-network/sdk",
3
- "version": "0.1.1-dev.0",
3
+ "version": "0.1.2-dev.0",
4
4
  "description": "TypeScript-only client library for Arkiv blockchain interactions",
5
5
  "type": "module",
6
6
  "target": "esnext",
@@ -10,28 +10,40 @@
10
10
  "sideEffects": false,
11
11
  "exports": {
12
12
  ".": {
13
+ "bun": "./src/index.ts",
13
14
  "import": "./dist/index.js",
14
- "require": "./dist/index.cjs"
15
+ "require": "./dist/index.cjs",
16
+ "default": "./dist/index.js"
15
17
  },
16
18
  "./accounts": {
19
+ "bun": "./src/accounts/index.ts",
17
20
  "import": "./dist/accounts/index.js",
18
- "require": "./dist/accounts/index.cjs"
21
+ "require": "./dist/accounts/index.cjs",
22
+ "default": "./dist/accounts/index.js"
19
23
  },
20
24
  "./chains": {
25
+ "bun": "./src/chains/index.ts",
21
26
  "import": "./dist/chains/index.js",
22
- "require": "./dist/chains/index.cjs"
27
+ "require": "./dist/chains/index.cjs",
28
+ "default": "./dist/chains/index.js"
23
29
  },
24
30
  "./query": {
31
+ "bun": "./src/query/index.ts",
25
32
  "import": "./dist/query/index.js",
26
- "require": "./dist/query/index.cjs"
33
+ "require": "./dist/query/index.cjs",
34
+ "default": "./dist/query/index.js"
27
35
  },
28
36
  "./types": {
37
+ "bun": "./src/types/index.ts",
29
38
  "import": "./dist/types/index.js",
30
- "require": "./dist/types/index.cjs"
39
+ "require": "./dist/types/index.cjs",
40
+ "default": "./dist/types/index.js"
31
41
  },
32
42
  "./utils": {
43
+ "bun": "./src/utils/index.ts",
33
44
  "import": "./dist/utils/index.js",
34
- "require": "./dist/utils/index.cjs"
45
+ "require": "./dist/utils/index.cjs",
46
+ "default": "./dist/utils/index.js"
35
47
  },
36
48
  "./package.json": "./package.json"
37
49
  },
@@ -52,13 +64,15 @@
52
64
  }
53
65
  },
54
66
  "files": [
55
- "dist"
67
+ "dist",
68
+ "src"
56
69
  ],
57
70
  "scripts": {
58
71
  "build": "tsdown",
59
72
  "type-check": "tsc --noEmit",
60
73
  "lint": "biome check src/",
61
74
  "lint:fix": "biome check --write src/",
75
+ "test:unit": "bun test src/**/*",
62
76
  "package": "rimraf arkiv-network-sdk-*.tgz && bun run build && bun pm pack --no-cache",
63
77
  "package:test": "bun run package && mv arkiv-network-sdk-*.tgz arkiv-network-sdk-latest.tgz",
64
78
  "prepublishOnly": "bun run build && bun run package && mv arkiv-network-sdk-*.tgz arkiv-network-sdk-latest.tgz",
@@ -0,0 +1 @@
1
+ export * from "viem/accounts"
@@ -0,0 +1,6 @@
1
+ import type { ArkivClient } from "../../clients/baseClient"
2
+ import { QueryBuilder } from "../../query/queryBuilder"
3
+
4
+ export async function buildQuery(client: ArkivClient) {
5
+ return new QueryBuilder(client)
6
+ }
@@ -0,0 +1,20 @@
1
+ import type { ArkivClient } from "../../clients/baseClient"
2
+
3
+ export type GetBlockTimingReturnType = {
4
+ currentBlock: bigint
5
+ currentBlockTime: number
6
+ blockDuration: number
7
+ }
8
+
9
+ export async function getBlockTiming(client: ArkivClient) {
10
+ const blockTiming = await client.request({
11
+ method: "arkiv_getBlockTiming",
12
+ params: [],
13
+ })
14
+ console.debug("Block timing", blockTiming)
15
+ return {
16
+ currentBlock: blockTiming.current_block,
17
+ currentBlockTime: blockTiming.current_block_time,
18
+ blockDuration: blockTiming.duration,
19
+ }
20
+ }
@@ -0,0 +1,18 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import { NoEntityFoundError } from "../../query/errors"
4
+ import { entityFromRpcResult } from "../../utils/entities"
5
+
6
+ export async function getEntity(client: ArkivClient, key: Hex) {
7
+ const result = await client.request({
8
+ method: "arkiv_query",
9
+ params: [`$key = ${key}`],
10
+ })
11
+ console.debug("GetEntity result", result)
12
+
13
+ if (!result.data) {
14
+ throw new NoEntityFoundError()
15
+ }
16
+
17
+ return entityFromRpcResult(result.data[0])
18
+ }
@@ -0,0 +1,10 @@
1
+ import type { ArkivClient } from "../../clients/baseClient"
2
+
3
+ export async function getEntityCount(client: ArkivClient) {
4
+ const count = await client.request({
5
+ method: "arkiv_getEntityCount",
6
+ params: [],
7
+ })
8
+
9
+ return count
10
+ }
@@ -0,0 +1,13 @@
1
+ import type { ArkivClient } from "../../clients/baseClient"
2
+ import { entityFromRpcResult } from "../../utils/entities"
3
+
4
+ export async function query(client: ArkivClient, query: string) {
5
+ const result = await client.request({
6
+ method: "arkiv_query",
7
+ params: [query],
8
+ })
9
+
10
+ const entities = await Promise.all(result.data.map((entity) => entityFromRpcResult(entity)))
11
+
12
+ return entities
13
+ }
@@ -0,0 +1,105 @@
1
+ import { decodeEventLog, parseAbi, toHex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { PublicArkivClient } from "../../clients/createPublicClient"
4
+ import type {
5
+ OnEntityCreatedEvent,
6
+ OnEntityDeletedEvent,
7
+ OnEntityExpiredEvent,
8
+ OnEntityExpiresInExtendedEvent,
9
+ OnEntityUpdatedEvent,
10
+ } from "../../types/events"
11
+
12
+ export const arkivABI = parseAbi([
13
+ "event ArkivEntityCreated(uint256 indexed entityKey, address indexed ownerAddress, uint256 expirationBlock, uint256 cost)",
14
+ "event ArkivEntityUpdated(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)",
15
+ "event ArkivEntityExpired(uint256 indexed entityKey, address indexed ownerAddress)",
16
+ "event ArkivEntityDeleted(uint256 indexed entityKey, address indexed ownerAddress)",
17
+ "event ArkivEntityBTLExtended(uint256 indexed entityKey, address indexed ownerAddress, uint256 oldExpirationBlock, uint256 newExpirationBlock, uint256 cost)",
18
+ ])
19
+
20
+ export async function subscribeEntityEvents(
21
+ client: ArkivClient,
22
+ {
23
+ onError,
24
+ onEntityCreated,
25
+ onEntityUpdated,
26
+ onEntityDeleted,
27
+ onEntityExpired,
28
+ onEntityExpiresInExtended,
29
+ }: {
30
+ onError: ((error: Error) => void) | undefined
31
+ onEntityCreated?: ((event: OnEntityCreatedEvent) => void) | undefined
32
+ onEntityUpdated?: ((event: OnEntityUpdatedEvent) => void) | undefined
33
+ onEntityDeleted?: ((event: OnEntityDeletedEvent) => void) | undefined
34
+ onEntityExpired?: ((event: OnEntityExpiredEvent) => void) | undefined
35
+ onEntityExpiresInExtended?: ((event: OnEntityExpiresInExtendedEvent) => void) | undefined
36
+ },
37
+ pollingInterval?: number,
38
+ fromBlock?: bigint,
39
+ ): Promise<() => void> {
40
+ const unsubscribe = (client as PublicArkivClient).watchEvent({
41
+ pollingInterval: pollingInterval ?? 1000,
42
+ fromBlock: fromBlock ?? 0n,
43
+ events: arkivABI,
44
+ onLogs: (logs) => {
45
+ console.debug("logs from subscribeEntityEvents", logs)
46
+ for (const log of logs) {
47
+ const event = decodeEventLog({
48
+ abi: arkivABI,
49
+ topics: log.topics,
50
+ data: log.data,
51
+ })
52
+ console.debug("event from subscribeEntityEvents", event)
53
+ switch (event.eventName) {
54
+ case "ArkivEntityCreated":
55
+ onEntityCreated?.({
56
+ entityKey: toHex(event.args.entityKey, { size: 32 }),
57
+ owner: event.args.ownerAddress,
58
+ expirationBlock: Number(event.args.expirationBlock),
59
+ cost: event.args.cost,
60
+ })
61
+ break
62
+ case "ArkivEntityUpdated":
63
+ onEntityUpdated?.({
64
+ entityKey: toHex(event.args.entityKey, { size: 32 }),
65
+ owner: event.args.ownerAddress,
66
+ oldExpirationBlock: Number(event.args.oldExpirationBlock),
67
+ newExpirationBlock: Number(event.args.newExpirationBlock),
68
+ cost: event.args.cost,
69
+ })
70
+ break
71
+ case "ArkivEntityDeleted":
72
+ onEntityDeleted?.({
73
+ entityKey: toHex(event.args.entityKey, { size: 32 }),
74
+ owner: event.args.ownerAddress,
75
+ })
76
+ break
77
+ case "ArkivEntityBTLExtended":
78
+ onEntityExpiresInExtended?.({
79
+ entityKey: toHex(event.args.entityKey, { size: 32 }),
80
+ owner: event.args.ownerAddress,
81
+ oldExpirationBlock: Number(event.args.oldExpirationBlock),
82
+ newExpirationBlock: Number(event.args.newExpirationBlock),
83
+ cost: event.args.cost,
84
+ })
85
+ break
86
+ case "ArkivEntityExpired":
87
+ onEntityExpired?.({
88
+ entityKey: toHex(event.args.entityKey, { size: 32 }),
89
+ owner: event.args.ownerAddress,
90
+ })
91
+ break
92
+ default:
93
+ console.warn("unknown event from subscribeEntityEvents", event)
94
+ break
95
+ }
96
+ }
97
+ },
98
+ onError: (error) => {
99
+ console.error("error from subscribeEntityEvents", error)
100
+ onError?.(error)
101
+ },
102
+ })
103
+
104
+ return unsubscribe
105
+ }
@@ -0,0 +1,40 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+
6
+ /**
7
+ * Parameters for the deleteEntity function.
8
+ * - entityKey: The key of the entity to delete.
9
+ */
10
+ export type ChangeOwnershipParameters = {
11
+ entityKey: Hex
12
+ newOwner: Hex
13
+ }
14
+
15
+ /**
16
+ * Return type for the deleteEntity function.
17
+ * - entityKey: The key of the entity.
18
+ * - txHash: The transaction hash.
19
+ */
20
+ export type ChangeOwnershipReturnType = {
21
+ entityKey: Hex
22
+ txHash: string
23
+ }
24
+
25
+ export async function changeOwnership(
26
+ client: ArkivClient,
27
+ data: ChangeOwnershipParameters,
28
+ txParams?: TxParams,
29
+ ): Promise<ChangeOwnershipReturnType> {
30
+ console.debug("changeOwnership", data)
31
+ const txData = opsToTxData({ ownershipChanges: [data] })
32
+ const receipt = await sendArkivTransaction(client, txData, txParams)
33
+
34
+ console.debug("Receipt from changeOwnership", receipt)
35
+
36
+ return {
37
+ txHash: receipt.transactionHash,
38
+ entityKey: data.entityKey,
39
+ }
40
+ }
@@ -0,0 +1,45 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { Attribute, MimeType, TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+
6
+ /**
7
+ * Parameters for the createEntity function.
8
+ * - payload: The payload of the entity.
9
+ * - attributes: The attributes of the entity.
10
+ * - contentType: The content type of the entity.
11
+ * - expiresIn: The expires in of the entity in seconds.
12
+ */
13
+ export type CreateEntityParameters = {
14
+ payload: Uint8Array
15
+ attributes: Attribute[]
16
+ contentType: MimeType
17
+ expiresIn: number
18
+ }
19
+
20
+ /**
21
+ * Return type for the createEntity function.
22
+ * - entityKey: The key of the entity.
23
+ * - txHash: The transaction hash.
24
+ */
25
+ export type CreateEntityReturnType = {
26
+ entityKey: Hex
27
+ txHash: string
28
+ }
29
+
30
+ export async function createEntity(
31
+ client: ArkivClient,
32
+ data: CreateEntityParameters,
33
+ txParams?: TxParams,
34
+ ): Promise<CreateEntityReturnType> {
35
+ console.debug("createEntity", data)
36
+ const txData = opsToTxData({ creates: [data] })
37
+ const receipt = await sendArkivTransaction(client, txData, txParams)
38
+
39
+ console.debug("Receipt from createEntity", receipt)
40
+
41
+ return {
42
+ txHash: receipt.transactionHash,
43
+ entityKey: receipt.logs[0].topics[1] as Hex,
44
+ }
45
+ }
@@ -0,0 +1,39 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+
6
+ /**
7
+ * Parameters for the deleteEntity function.
8
+ * - entityKey: The key of the entity to delete.
9
+ */
10
+ export type DeleteEntityParameters = {
11
+ entityKey: Hex
12
+ }
13
+
14
+ /**
15
+ * Return type for the deleteEntity function.
16
+ * - entityKey: The key of the entity.
17
+ * - txHash: The transaction hash.
18
+ */
19
+ export type DeleteEntityReturnType = {
20
+ entityKey: Hex
21
+ txHash: string
22
+ }
23
+
24
+ export async function deleteEntity(
25
+ client: ArkivClient,
26
+ data: DeleteEntityParameters,
27
+ txParams?: TxParams,
28
+ ): Promise<DeleteEntityReturnType> {
29
+ console.debug("deleteEntity", data)
30
+ const txData = opsToTxData({ deletes: [data] })
31
+ const receipt = await sendArkivTransaction(client, txData, txParams)
32
+
33
+ console.debug("Receipt from deleteEntity", receipt)
34
+
35
+ return {
36
+ txHash: receipt.transactionHash,
37
+ entityKey: data.entityKey,
38
+ }
39
+ }
@@ -0,0 +1,41 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+
6
+ /**
7
+ * Parameters for the extendEntity function.
8
+ * - entityKey: The key of the entity to extend.
9
+ * - expiresIn: The expires in of the entity in seconds.
10
+ */
11
+ export type ExtendEntityParameters = {
12
+ entityKey: Hex
13
+ expiresIn: number
14
+ }
15
+
16
+ /**
17
+ * Return type for the extendEntity function.
18
+ * - entityKey: The key of the entity.
19
+ * - txHash: The transaction hash.
20
+ */
21
+ export type ExtendEntityReturnType = {
22
+ entityKey: Hex
23
+ txHash: string
24
+ }
25
+
26
+ export async function extendEntity(
27
+ client: ArkivClient,
28
+ data: ExtendEntityParameters,
29
+ txParams?: TxParams,
30
+ ): Promise<ExtendEntityReturnType> {
31
+ console.debug("extendEntity", data)
32
+ const txData = opsToTxData({ extensions: [data] })
33
+ const receipt = await sendArkivTransaction(client, txData, txParams)
34
+
35
+ console.debug("Receipt from extendEntity", receipt)
36
+
37
+ return {
38
+ txHash: receipt.transactionHash,
39
+ entityKey: receipt.logs[0].topics[1] as Hex,
40
+ }
41
+ }
@@ -0,0 +1,100 @@
1
+ import type { Hex, TransactionReceipt } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+ import type { CreateEntityParameters } from "./createEntity"
6
+ import type { DeleteEntityParameters } from "./deleteEntity"
7
+ import type { ExtendEntityParameters } from "./extendEntity"
8
+ import type { UpdateEntityParameters } from "./updateEntity"
9
+
10
+ /**
11
+ * Parameters for the mutateEntities function.
12
+ * - creates: The creates to perform.
13
+ * - updates: The updates to perform.
14
+ * - deletes: The deletes to perform.
15
+ * - extensions: The extensions to perform.
16
+ */
17
+ export type MutateEntitiesParameters = {
18
+ creates?: CreateEntityParameters[]
19
+ updates?: UpdateEntityParameters[]
20
+ deletes?: DeleteEntityParameters[]
21
+ extensions?: ExtendEntityParameters[]
22
+ }
23
+
24
+ function parseReceipt(receipt: TransactionReceipt, params: MutateEntitiesParameters) {
25
+ const createdEntities: Hex[] = []
26
+ const updatedEntities: Hex[] = []
27
+ const deletedEntities: Hex[] = []
28
+ const extendedEntities: Hex[] = []
29
+ const totalCreates = params.creates?.length ?? 0
30
+ const totalUpdates = params.updates?.length ?? 0
31
+ const totalDeletes = params.deletes?.length ?? 0
32
+
33
+ // iterate over all logs and parse the event
34
+ // each odd log is the interested ones, logs goes in order like: creates, deleted, updates, extends
35
+ for (let i = 0; i < receipt.logs.length; i++) {
36
+ const log = receipt.logs[i]
37
+ if (i % 2 === 1) continue
38
+
39
+ const index = i / 2
40
+ if (index < totalCreates) {
41
+ createdEntities.push(log.topics[1] as Hex)
42
+ } else if (index < totalCreates + totalDeletes) {
43
+ deletedEntities.push(log.topics[1] as Hex)
44
+ } else if (index < totalCreates + totalUpdates + totalDeletes) {
45
+ updatedEntities.push(log.topics[1] as Hex)
46
+ } else {
47
+ extendedEntities.push(log.topics[1] as Hex)
48
+ }
49
+ }
50
+
51
+ return { createdEntities, updatedEntities, deletedEntities, extendedEntities }
52
+ }
53
+
54
+ /**
55
+ * Return type for the mutateEntities function.
56
+ * - txHash: The transaction hash.
57
+ * - createdEntities: The keys of the created entities.
58
+ * - updatedEntities: The keys of the updated entities.
59
+ * - deletedEntities: The keys of the deleted entities.
60
+ * - extendedEntities: The keys of the extended entities.
61
+ */
62
+ export type MutateEntitiesReturnType = {
63
+ txHash: string
64
+ createdEntities: Hex[]
65
+ updatedEntities: Hex[]
66
+ deletedEntities: Hex[]
67
+ extendedEntities: Hex[]
68
+ }
69
+ export async function mutateEntities(
70
+ client: ArkivClient,
71
+ data: MutateEntitiesParameters,
72
+ txParams?: TxParams,
73
+ ): Promise<MutateEntitiesReturnType> {
74
+ if (!data.creates && !data.updates && !data.deletes && !data.extensions) {
75
+ throw new Error("No operations to perform")
76
+ }
77
+
78
+ const txData = opsToTxData({
79
+ creates: data.creates ?? [],
80
+ updates: data.updates ?? [],
81
+ deletes: data.deletes ?? [],
82
+ extensions: data.extensions ?? [],
83
+ })
84
+
85
+ const receipt = await sendArkivTransaction(client, txData, txParams)
86
+
87
+ console.debug("Receipt from mutateEntities", receipt)
88
+
89
+ const { createdEntities, updatedEntities, deletedEntities, extendedEntities } = parseReceipt(
90
+ receipt,
91
+ data,
92
+ )
93
+ return {
94
+ txHash: receipt.transactionHash,
95
+ createdEntities,
96
+ updatedEntities,
97
+ deletedEntities,
98
+ extendedEntities,
99
+ }
100
+ }
@@ -0,0 +1,47 @@
1
+ import type { Hex } from "viem"
2
+ import type { ArkivClient } from "../../clients/baseClient"
3
+ import type { Attribute, MimeType, TxParams } from "../../types"
4
+ import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
5
+
6
+ /**
7
+ * Parameters for the updateEntity function.
8
+ * - entityKey: The key of the entity to update.
9
+ * - payload: The payload of the entity.
10
+ * - attributes: The attributes of the entity.
11
+ * - contentType: The content type of the entity.
12
+ * - expiresIn: The expires in of the entity in seconds.
13
+ */
14
+ export type UpdateEntityParameters = {
15
+ entityKey: Hex
16
+ payload: Uint8Array
17
+ attributes: Attribute[]
18
+ contentType: MimeType
19
+ expiresIn: number
20
+ }
21
+
22
+ /**
23
+ * Return type for the updateEntity function.
24
+ * - entityKey: The key of the entity.
25
+ * - txHash: The transaction hash.
26
+ */
27
+ export type UpdateEntityReturnType = {
28
+ entityKey: Hex
29
+ txHash: string
30
+ }
31
+
32
+ export async function updateEntity(
33
+ client: ArkivClient,
34
+ data: UpdateEntityParameters,
35
+ txParams?: TxParams,
36
+ ): Promise<UpdateEntityReturnType> {
37
+ console.debug("updateEntity", data)
38
+ const txData = opsToTxData({ updates: [data] })
39
+ const receipt = await sendArkivTransaction(client, txData, txParams)
40
+
41
+ console.debug("Receipt from updateEntity", receipt)
42
+
43
+ return {
44
+ txHash: receipt.transactionHash,
45
+ entityKey: receipt.logs[0].topics[1] as Hex,
46
+ }
47
+ }
@@ -0,0 +1,3 @@
1
+ export { kaolin } from "./kaolin"
2
+ export { localhost } from "./localhost"
3
+ export { marketplace } from "./marketplace"
@@ -0,0 +1,26 @@
1
+ import { defineChain } from "viem"
2
+
3
+ export const kaolin = defineChain({
4
+ id: 60138453025,
5
+ name: "Kaolin",
6
+ network: "kaolin",
7
+ nativeCurrency: {
8
+ name: "Ethereum",
9
+ symbol: "ETH",
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ["https://kaolin.hoodi.arkiv.network/rpc"],
15
+ webSocket: ["wss://kaolin.hoodi.arkiv.network/rpc/ws"],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: "Kaolin Arkiv Explorer",
21
+ url: "https://explorer.kaolin.hoodi.arkiv.network",
22
+ apiUrl: "https://explorer.kaolin.hoodi.arkiv.network/api",
23
+ },
24
+ },
25
+ testnet: true,
26
+ })
@@ -0,0 +1,14 @@
1
+ import { defineChain } from "viem"
2
+
3
+ export const localhost = defineChain({
4
+ id: 1337,
5
+ name: "Localhost",
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: "Ether",
9
+ symbol: "ETH",
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ["http://127.0.0.1:8545"] },
13
+ },
14
+ })
@@ -0,0 +1,26 @@
1
+ import { defineChain } from "viem"
2
+
3
+ export const marketplace = defineChain({
4
+ id: 60138453027,
5
+ name: "Marketplace",
6
+ network: "marketplace",
7
+ nativeCurrency: {
8
+ name: "Ethereum",
9
+ symbol: "ETH",
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ["https://marketplace.hoodi.arkiv.network/rpc"],
15
+ webSocket: ["wss://marketplace.hoodi.arkiv.network/rpc/ws"],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: "Marketplace Arkiv Explorer",
21
+ url: "https://explorer.marketplace.hoodi.arkiv.network",
22
+ apiUrl: "https://explorer.marketplace.hoodi.arkiv.network/api",
23
+ },
24
+ },
25
+ testnet: true,
26
+ })
@@ -0,0 +1,9 @@
1
+ import type { Account, Chain, Client, RpcSchema, Transport } from "viem"
2
+ import type { ArkivRpcSchema } from "../types/rpcSchema"
3
+
4
+ export type ArkivClient<
5
+ transport extends Transport = Transport,
6
+ chain extends Chain | undefined = Chain | undefined,
7
+ accountOrAddress extends Account | undefined = Account | undefined,
8
+ rpcSchema extends RpcSchema | undefined = ArkivRpcSchema,
9
+ > = Client<transport, chain, accountOrAddress, rpcSchema>
@@ -0,0 +1,22 @@
1
+ import { expect, test, vi } from "bun:test"
2
+ import { createTransport, type EIP1193RequestFn } from "viem"
3
+ import { createPublicClient } from "./createPublicClient"
4
+
5
+ const mockTransport = () =>
6
+ createTransport({
7
+ key: "mock",
8
+ name: "Mock Transport",
9
+ request: vi.fn(() => null) as unknown as EIP1193RequestFn,
10
+ type: "mock",
11
+ })
12
+
13
+ test("creates", () => {
14
+ const { uid, ...client } = createPublicClient({
15
+ transport: mockTransport,
16
+ })
17
+
18
+ expect(uid).toBeDefined()
19
+ expect(client.getEntity).toBeDefined()
20
+ expect(typeof client.getEntity).toBe("function")
21
+ expect(client.createEntity).not.toBeDefined()
22
+ })