@trufnetwork/sdk-js 0.0.0-dev-20241126103246

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 (140) hide show
  1. package/LICENSE.md +13 -0
  2. package/README.md +95 -0
  3. package/dist/cjs/client/browserClient.cjs +39 -0
  4. package/dist/cjs/client/browserClient.cjs.map +7 -0
  5. package/dist/cjs/client/client.cjs +200 -0
  6. package/dist/cjs/client/client.cjs.map +7 -0
  7. package/dist/cjs/client/client.test.cjs +32 -0
  8. package/dist/cjs/client/client.test.cjs.map +7 -0
  9. package/dist/cjs/client/listAllStreams.cjs +51 -0
  10. package/dist/cjs/client/listAllStreams.cjs.map +7 -0
  11. package/dist/cjs/client/nodeClient.cjs +39 -0
  12. package/dist/cjs/client/nodeClient.cjs.map +7 -0
  13. package/dist/cjs/contracts/composed_stream_template.json +1638 -0
  14. package/dist/cjs/contracts/contractsContent.cjs +53 -0
  15. package/dist/cjs/contracts/contractsContent.cjs.map +7 -0
  16. package/dist/cjs/contracts/primitive_stream_template.json +952 -0
  17. package/dist/cjs/contracts-api/composedStream.cjs +137 -0
  18. package/dist/cjs/contracts-api/composedStream.cjs.map +7 -0
  19. package/dist/cjs/contracts-api/contractValues.cjs +66 -0
  20. package/dist/cjs/contracts-api/contractValues.cjs.map +7 -0
  21. package/dist/cjs/contracts-api/deployStream.cjs +55 -0
  22. package/dist/cjs/contracts-api/deployStream.cjs.map +7 -0
  23. package/dist/cjs/contracts-api/destroyStream.cjs +45 -0
  24. package/dist/cjs/contracts-api/destroyStream.cjs.map +7 -0
  25. package/dist/cjs/contracts-api/primitiveStream.cjs +86 -0
  26. package/dist/cjs/contracts-api/primitiveStream.cjs.map +7 -0
  27. package/dist/cjs/contracts-api/stream.cjs +379 -0
  28. package/dist/cjs/contracts-api/stream.cjs.map +7 -0
  29. package/dist/cjs/index.browser.cjs +29 -0
  30. package/dist/cjs/index.browser.cjs.map +7 -0
  31. package/dist/cjs/index.cjs +31 -0
  32. package/dist/cjs/index.cjs.map +7 -0
  33. package/dist/cjs/index.common.cjs +39 -0
  34. package/dist/cjs/index.common.cjs.map +7 -0
  35. package/dist/cjs/index.node.cjs +29 -0
  36. package/dist/cjs/index.node.cjs.map +7 -0
  37. package/dist/cjs/types/other.cjs +19 -0
  38. package/dist/cjs/types/other.cjs.map +7 -0
  39. package/dist/cjs/types/stream.cjs +19 -0
  40. package/dist/cjs/types/stream.cjs.map +7 -0
  41. package/dist/cjs/util/EthereumAddress.cjs +108 -0
  42. package/dist/cjs/util/EthereumAddress.cjs.map +7 -0
  43. package/dist/cjs/util/StreamId.cjs +77 -0
  44. package/dist/cjs/util/StreamId.cjs.map +7 -0
  45. package/dist/cjs/util/head.cjs +30 -0
  46. package/dist/cjs/util/head.cjs.map +7 -0
  47. package/dist/cjs/util/visibility.cjs +42 -0
  48. package/dist/cjs/util/visibility.cjs.map +7 -0
  49. package/dist/esm/client/browserClient.mjs +18 -0
  50. package/dist/esm/client/browserClient.mjs.map +7 -0
  51. package/dist/esm/client/client.mjs +183 -0
  52. package/dist/esm/client/client.mjs.map +7 -0
  53. package/dist/esm/client/client.test.mjs +30 -0
  54. package/dist/esm/client/client.test.mjs.map +7 -0
  55. package/dist/esm/client/listAllStreams.mjs +30 -0
  56. package/dist/esm/client/listAllStreams.mjs.map +7 -0
  57. package/dist/esm/client/nodeClient.mjs +18 -0
  58. package/dist/esm/client/nodeClient.mjs.map +7 -0
  59. package/dist/esm/contracts/composed_stream_template.json +1638 -0
  60. package/dist/esm/contracts/contractsContent.mjs +21 -0
  61. package/dist/esm/contracts/contractsContent.mjs.map +7 -0
  62. package/dist/esm/contracts/primitive_stream_template.json +952 -0
  63. package/dist/esm/contracts-api/composedStream.mjs +116 -0
  64. package/dist/esm/contracts-api/composedStream.mjs.map +7 -0
  65. package/dist/esm/contracts-api/contractValues.mjs +45 -0
  66. package/dist/esm/contracts-api/contractValues.mjs.map +7 -0
  67. package/dist/esm/contracts-api/deployStream.mjs +37 -0
  68. package/dist/esm/contracts-api/deployStream.mjs.map +7 -0
  69. package/dist/esm/contracts-api/destroyStream.mjs +24 -0
  70. package/dist/esm/contracts-api/destroyStream.mjs.map +7 -0
  71. package/dist/esm/contracts-api/primitiveStream.mjs +65 -0
  72. package/dist/esm/contracts-api/primitiveStream.mjs.map +7 -0
  73. package/dist/esm/contracts-api/stream.mjs +367 -0
  74. package/dist/esm/contracts-api/stream.mjs.map +7 -0
  75. package/dist/esm/index.browser.mjs +7 -0
  76. package/dist/esm/index.browser.mjs.map +7 -0
  77. package/dist/esm/index.common.mjs +18 -0
  78. package/dist/esm/index.common.mjs.map +7 -0
  79. package/dist/esm/index.mjs +9 -0
  80. package/dist/esm/index.mjs.map +7 -0
  81. package/dist/esm/index.node.mjs +7 -0
  82. package/dist/esm/index.node.mjs.map +7 -0
  83. package/dist/esm/types/other.mjs +1 -0
  84. package/dist/esm/types/other.mjs.map +7 -0
  85. package/dist/esm/types/stream.mjs +1 -0
  86. package/dist/esm/types/stream.mjs.map +7 -0
  87. package/dist/esm/util/EthereumAddress.mjs +90 -0
  88. package/dist/esm/util/EthereumAddress.mjs.map +7 -0
  89. package/dist/esm/util/StreamId.mjs +59 -0
  90. package/dist/esm/util/StreamId.mjs.map +7 -0
  91. package/dist/esm/util/head.mjs +9 -0
  92. package/dist/esm/util/head.mjs.map +7 -0
  93. package/dist/esm/util/visibility.mjs +21 -0
  94. package/dist/esm/util/visibility.mjs.map +7 -0
  95. package/dist/tsconfig.build.tsbuildinfo +1 -0
  96. package/dist/types/client/browserClient.d.ts +7 -0
  97. package/dist/types/client/browserClient.d.ts.map +1 -0
  98. package/dist/types/client/client.d.ts +103 -0
  99. package/dist/types/client/client.d.ts.map +1 -0
  100. package/dist/types/client/client.test.d.ts +2 -0
  101. package/dist/types/client/client.test.d.ts.map +1 -0
  102. package/dist/types/client/listAllStreams.d.ts +14 -0
  103. package/dist/types/client/listAllStreams.d.ts.map +1 -0
  104. package/dist/types/client/nodeClient.d.ts +7 -0
  105. package/dist/types/client/nodeClient.d.ts.map +1 -0
  106. package/dist/types/contracts/contractsContent.d.ts +4 -0
  107. package/dist/types/contracts/contractsContent.d.ts.map +1 -0
  108. package/dist/types/contracts-api/composedStream.d.ts +57 -0
  109. package/dist/types/contracts-api/composedStream.d.ts.map +1 -0
  110. package/dist/types/contracts-api/contractValues.d.ts +49 -0
  111. package/dist/types/contracts-api/contractValues.d.ts.map +1 -0
  112. package/dist/types/contracts-api/deployStream.d.ts +23 -0
  113. package/dist/types/contracts-api/deployStream.d.ts.map +1 -0
  114. package/dist/types/contracts-api/destroyStream.d.ts +27 -0
  115. package/dist/types/contracts-api/destroyStream.d.ts.map +1 -0
  116. package/dist/types/contracts-api/primitiveStream.d.ts +39 -0
  117. package/dist/types/contracts-api/primitiveStream.d.ts.map +1 -0
  118. package/dist/types/contracts-api/stream.d.ts +135 -0
  119. package/dist/types/contracts-api/stream.d.ts.map +1 -0
  120. package/dist/types/index.browser.d.ts +3 -0
  121. package/dist/types/index.browser.d.ts.map +1 -0
  122. package/dist/types/index.common.d.ts +16 -0
  123. package/dist/types/index.common.d.ts.map +1 -0
  124. package/dist/types/index.d.ts +4 -0
  125. package/dist/types/index.d.ts.map +1 -0
  126. package/dist/types/index.node.d.ts +3 -0
  127. package/dist/types/index.node.d.ts.map +1 -0
  128. package/dist/types/types/other.d.ts +2 -0
  129. package/dist/types/types/other.d.ts.map +1 -0
  130. package/dist/types/types/stream.d.ts +13 -0
  131. package/dist/types/types/stream.d.ts.map +1 -0
  132. package/dist/types/util/EthereumAddress.d.ts +14 -0
  133. package/dist/types/util/EthereumAddress.d.ts.map +1 -0
  134. package/dist/types/util/StreamId.d.ts +13 -0
  135. package/dist/types/util/StreamId.d.ts.map +1 -0
  136. package/dist/types/util/head.d.ts +3 -0
  137. package/dist/types/util/head.d.ts.map +1 -0
  138. package/dist/types/util/visibility.d.ts +10 -0
  139. package/dist/types/util/visibility.d.ts.map +1 -0
  140. package/package.json +82 -0
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/util/EthereumAddress.ts
21
+ var EthereumAddress_exports = {};
22
+ __export(EthereumAddress_exports, {
23
+ EthereumAddress: () => EthereumAddress
24
+ });
25
+ module.exports = __toCommonJS(EthereumAddress_exports);
26
+ var import_ethers = require("ethers");
27
+ var import_either = require("monads-io/either");
28
+ var import_meta = {};
29
+ var EthereumAddress = class _EthereumAddress {
30
+ address;
31
+ correctlyCreated = false;
32
+ constructor(address) {
33
+ address = address.toLowerCase();
34
+ if (!address.startsWith("0x")) {
35
+ address = "0x" + address;
36
+ }
37
+ if (!this.validateEthereumAddress(address)) {
38
+ throw new Error("Invalid Ethereum address");
39
+ }
40
+ this.address = address;
41
+ this.correctlyCreated = true;
42
+ }
43
+ validateEthereumAddress(address) {
44
+ return /^(0x)?[0-9a-f]{40}$/i.test(address);
45
+ }
46
+ getAddress() {
47
+ if (!this.correctlyCreated) {
48
+ throw new Error("EthereumAddress not correctly created");
49
+ }
50
+ return this.address;
51
+ }
52
+ getBytes() {
53
+ return new TextEncoder().encode(this.getAddress());
54
+ }
55
+ toJSON() {
56
+ return this.getAddress();
57
+ }
58
+ static fromJSON(json) {
59
+ return new _EthereumAddress(json);
60
+ }
61
+ static fromBytes(bytes) {
62
+ try {
63
+ return (0, import_either.right)(new _EthereumAddress(import_ethers.ethers.hexlify(bytes)));
64
+ } catch (e) {
65
+ return (0, import_either.left)(e);
66
+ }
67
+ }
68
+ static fromString(str) {
69
+ try {
70
+ return (0, import_either.right)(new _EthereumAddress(str));
71
+ } catch (e) {
72
+ return (0, import_either.left)(e);
73
+ }
74
+ }
75
+ };
76
+ if (import_meta.vitest) {
77
+ const { describe, it, expect } = import_meta.vitest;
78
+ describe("EthereumAddress", () => {
79
+ it("should create a valid EthereumAddress with correct format", () => {
80
+ const address = new EthereumAddress(
81
+ "0x1234567890123456789012345678901234567890"
82
+ );
83
+ expect(address.getAddress()).toBe(
84
+ "0x1234567890123456789012345678901234567890"
85
+ );
86
+ });
87
+ it("should throw an error for an invalid Ethereum address", () => {
88
+ expect(() => new EthereumAddress("invalid_address")).toThrow(
89
+ "Invalid Ethereum address"
90
+ );
91
+ });
92
+ it("should enforce lowercase addresses", () => {
93
+ const mixedCaseAddress = "0xaaBbccDdEeff1234567890123456789012345678".toLowerCase();
94
+ const address = new EthereumAddress(mixedCaseAddress);
95
+ expect(address.getAddress()).toBe(
96
+ "0xaabbccddeeff1234567890123456789012345678"
97
+ );
98
+ });
99
+ it("should correctly serialize and deserialize to/from JSON", () => {
100
+ const originalAddress = "0x1234567890123456789012345678901234567890";
101
+ const address = new EthereumAddress(originalAddress);
102
+ const json = address.toJSON();
103
+ const deserializedAddress = EthereumAddress.fromJSON(json);
104
+ expect(deserializedAddress.getAddress()).toBe(originalAddress);
105
+ });
106
+ });
107
+ }
108
+ //# sourceMappingURL=EthereumAddress.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/EthereumAddress.ts"],
4
+ "sourcesContent": ["import { ethers } from \"ethers\";\nimport { Either, left, right } from \"monads-io/either\";\n\nexport class EthereumAddress {\n private readonly address: string;\n private readonly correctlyCreated: boolean = false;\n\n constructor(address: string) {\n address = address.toLowerCase();\n if (!address.startsWith(\"0x\")) {\n address = \"0x\" + address;\n }\n\n if (!this.validateEthereumAddress(address)) {\n throw new Error(\"Invalid Ethereum address\");\n }\n\n this.address = address;\n this.correctlyCreated = true;\n }\n\n private validateEthereumAddress(address: string): boolean {\n return /^(0x)?[0-9a-f]{40}$/i.test(address);\n }\n\n public getAddress(): string {\n if (!this.correctlyCreated) {\n throw new Error(\"EthereumAddress not correctly created\");\n }\n\n return this.address;\n }\n\n public getBytes(): Uint8Array {\n return new TextEncoder().encode(this.getAddress());\n }\n\n public toJSON(): string {\n return this.getAddress();\n }\n\n public static fromJSON(json: string): EthereumAddress {\n return new EthereumAddress(json);\n }\n\n public static fromBytes(bytes: Uint8Array): Either<Error, EthereumAddress> {\n try {\n return right(new EthereumAddress(ethers.hexlify(bytes)));\n } catch (e) {\n return left(e as Error);\n }\n }\n\n public static fromString(str: string): Either<Error, EthereumAddress> {\n try {\n return right(new EthereumAddress(str));\n } catch (e) {\n return left(e as Error);\n }\n }\n}\n\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n describe(\"EthereumAddress\", () => {\n it(\"should create a valid EthereumAddress with correct format\", () => {\n const address = new EthereumAddress(\n \"0x1234567890123456789012345678901234567890\",\n );\n expect(address.getAddress()).toBe(\n \"0x1234567890123456789012345678901234567890\",\n );\n });\n\n it(\"should throw an error for an invalid Ethereum address\", () => {\n expect(() => new EthereumAddress(\"invalid_address\")).toThrow(\n \"Invalid Ethereum address\",\n );\n });\n\n it(\"should enforce lowercase addresses\", () => {\n const mixedCaseAddress =\n \"0xaaBbccDdEeff1234567890123456789012345678\".toLowerCase();\n const address = new EthereumAddress(mixedCaseAddress);\n expect(address.getAddress()).toBe(\n \"0xaabbccddeeff1234567890123456789012345678\",\n );\n });\n\n it(\"should correctly serialize and deserialize to/from JSON\", () => {\n const originalAddress = \"0x1234567890123456789012345678901234567890\";\n const address = new EthereumAddress(originalAddress);\n const json = address.toJSON();\n const deserializedAddress = EthereumAddress.fromJSON(json);\n expect(deserializedAddress.getAddress()).toBe(originalAddress);\n });\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,oBAAoC;AADpC;AAGO,IAAM,kBAAN,MAAM,iBAAgB;AAAA,EACV;AAAA,EACA,mBAA4B;AAAA,EAE7C,YAAY,SAAiB;AAC3B,cAAU,QAAQ,YAAY;AAC9B,QAAI,CAAC,QAAQ,WAAW,IAAI,GAAG;AAC7B,gBAAU,OAAO;AAAA,IACnB;AAEA,QAAI,CAAC,KAAK,wBAAwB,OAAO,GAAG;AAC1C,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,SAAK,UAAU;AACf,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEQ,wBAAwB,SAA0B;AACxD,WAAO,uBAAuB,KAAK,OAAO;AAAA,EAC5C;AAAA,EAEO,aAAqB;AAC1B,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,WAAuB;AAC5B,WAAO,IAAI,YAAY,EAAE,OAAO,KAAK,WAAW,CAAC;AAAA,EACnD;AAAA,EAEO,SAAiB;AACtB,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA,EAEA,OAAc,SAAS,MAA+B;AACpD,WAAO,IAAI,iBAAgB,IAAI;AAAA,EACjC;AAAA,EAEA,OAAc,UAAU,OAAmD;AACzE,QAAI;AACF,iBAAO,qBAAM,IAAI,iBAAgB,qBAAO,QAAQ,KAAK,CAAC,CAAC;AAAA,IACzD,SAAS,GAAG;AACV,iBAAO,oBAAK,CAAU;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAc,WAAW,KAA6C;AACpE,QAAI;AACF,iBAAO,qBAAM,IAAI,iBAAgB,GAAG,CAAC;AAAA,IACvC,SAAS,GAAG;AACV,iBAAO,oBAAK,CAAU;AAAA,IACxB;AAAA,EACF;AACF;AAEA,IAAI,YAAY,QAAQ;AACtB,QAAM,EAAE,UAAU,IAAI,OAAO,IAAI,YAAY;AAC7C,WAAS,mBAAmB,MAAM;AAChC,OAAG,6DAA6D,MAAM;AACpE,YAAM,UAAU,IAAI;AAAA,QAClB;AAAA,MACF;AACA,aAAO,QAAQ,WAAW,CAAC,EAAE;AAAA,QAC3B;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,yDAAyD,MAAM;AAChE,aAAO,MAAM,IAAI,gBAAgB,iBAAiB,CAAC,EAAE;AAAA,QACnD;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,sCAAsC,MAAM;AAC7C,YAAM,mBACJ,6CAA6C,YAAY;AAC3D,YAAM,UAAU,IAAI,gBAAgB,gBAAgB;AACpD,aAAO,QAAQ,WAAW,CAAC,EAAE;AAAA,QAC3B;AAAA,MACF;AAAA,IACF,CAAC;AAED,OAAG,2DAA2D,MAAM;AAClE,YAAM,kBAAkB;AACxB,YAAM,UAAU,IAAI,gBAAgB,eAAe;AACnD,YAAM,OAAO,QAAQ,OAAO;AAC5B,YAAM,sBAAsB,gBAAgB,SAAS,IAAI;AACzD,aAAO,oBAAoB,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IAC/D,CAAC;AAAA,EACH,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/util/StreamId.ts
21
+ var StreamId_exports = {};
22
+ __export(StreamId_exports, {
23
+ StreamId: () => StreamId
24
+ });
25
+ module.exports = __toCommonJS(StreamId_exports);
26
+ var import_crypto_hash = require("crypto-hash");
27
+ var import_monads_io = require("monads-io");
28
+ var import_meta = {};
29
+ var StreamId = class _StreamId {
30
+ id;
31
+ correctlyCreated = false;
32
+ constructor(id) {
33
+ this.id = id;
34
+ this.correctlyCreated = true;
35
+ }
36
+ getId() {
37
+ if (!this.correctlyCreated) {
38
+ throw new Error("StreamId not correctly created");
39
+ }
40
+ return this.id;
41
+ }
42
+ validate() {
43
+ return this.id.length === 32 && this.id.startsWith("st");
44
+ }
45
+ toJSON() {
46
+ return this.getId();
47
+ }
48
+ static fromJSON(json) {
49
+ return new _StreamId(json);
50
+ }
51
+ static async generate(s) {
52
+ if (s.length === 32 && s.startsWith("st")) {
53
+ return new _StreamId(s);
54
+ }
55
+ const hash = await (0, import_crypto_hash.sha256)(s);
56
+ const streamIdStr = "st" + hash.slice(0, 30);
57
+ return new _StreamId(streamIdStr);
58
+ }
59
+ static fromString(s) {
60
+ try {
61
+ return import_monads_io.Either.right(new _StreamId(s));
62
+ } catch (e) {
63
+ return import_monads_io.Either.left(e);
64
+ }
65
+ }
66
+ };
67
+ if (import_meta.vitest) {
68
+ const { describe, it, expect } = import_meta.vitest;
69
+ describe("StreamId", () => {
70
+ it("should generate a valid StreamId", async () => {
71
+ const streamId = await StreamId.generate("cpi_india_1.1.01");
72
+ expect(streamId.validate()).toBe(true);
73
+ expect(streamId.getId()).toBe("st39830c44932bc42a3bffef72310948");
74
+ });
75
+ });
76
+ }
77
+ //# sourceMappingURL=StreamId.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/StreamId.ts"],
4
+ "sourcesContent": ["import { sha256 } from \"crypto-hash\";\nimport { Either } from \"monads-io\";\n\nexport class StreamId {\n private readonly id: string;\n private readonly correctlyCreated: boolean = false;\n\n private constructor(id: string) {\n this.id = id;\n this.correctlyCreated = true;\n }\n\n public getId(): string {\n if (!this.correctlyCreated) {\n throw new Error(\"StreamId not correctly created\");\n }\n\n return this.id;\n }\n\n public validate(): boolean {\n return this.id.length === 32 && this.id.startsWith(\"st\");\n }\n\n public toJSON(): string {\n return this.getId();\n }\n\n public static fromJSON(json: string): StreamId {\n return new StreamId(json);\n }\n\n public static async generate(s: string): Promise<StreamId> {\n // If the string is already a valid StreamId, return it\n if (s.length === 32 && s.startsWith(\"st\")) {\n return new StreamId(s);\n }\n\n // Compute SHA-256 hash of the input string\n const hash = await sha256(s);\n\n // Take the first 30 characters of the hash and prepend \"st\"\n const streamIdStr = \"st\" + hash.slice(0, 30);\n\n return new StreamId(streamIdStr);\n }\n\n public static fromString(s: string): Either<Error, StreamId> {\n try {\n return Either.right(new StreamId(s));\n } catch (e) {\n return Either.left(e as Error);\n }\n }\n}\n\nif (import.meta.vitest) {\n const { describe, it, expect } = import.meta.vitest;\n describe(\"StreamId\", () => {\n it(\"should generate a valid StreamId\", async () => {\n const streamId = await StreamId.generate(\"cpi_india_1.1.01\");\n expect(streamId.validate()).toBe(true);\n expect(streamId.getId()).toBe(\"st39830c44932bc42a3bffef72310948\");\n });\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,uBAAuB;AADvB;AAGO,IAAM,WAAN,MAAM,UAAS;AAAA,EACH;AAAA,EACA,mBAA4B;AAAA,EAErC,YAAY,IAAY;AAC9B,SAAK,KAAK;AACV,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEO,QAAgB;AACrB,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,WAAoB;AACzB,WAAO,KAAK,GAAG,WAAW,MAAM,KAAK,GAAG,WAAW,IAAI;AAAA,EACzD;AAAA,EAEO,SAAiB;AACtB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,OAAc,SAAS,MAAwB;AAC7C,WAAO,IAAI,UAAS,IAAI;AAAA,EAC1B;AAAA,EAEA,aAAoB,SAAS,GAA8B;AAEzD,QAAI,EAAE,WAAW,MAAM,EAAE,WAAW,IAAI,GAAG;AACzC,aAAO,IAAI,UAAS,CAAC;AAAA,IACvB;AAGA,UAAM,OAAO,UAAM,2BAAO,CAAC;AAG3B,UAAM,cAAc,OAAO,KAAK,MAAM,GAAG,EAAE;AAE3C,WAAO,IAAI,UAAS,WAAW;AAAA,EACjC;AAAA,EAEA,OAAc,WAAW,GAAoC;AAC3D,QAAI;AACF,aAAO,wBAAO,MAAM,IAAI,UAAS,CAAC,CAAC;AAAA,IACrC,SAAS,GAAG;AACV,aAAO,wBAAO,KAAK,CAAU;AAAA,IAC/B;AAAA,EACF;AACF;AAEA,IAAI,YAAY,QAAQ;AACtB,QAAM,EAAE,UAAU,IAAI,OAAO,IAAI,YAAY;AAC7C,WAAS,YAAY,MAAM;AACzB,OAAG,oCAAoC,YAAY;AACjD,YAAM,WAAW,MAAM,SAAS,SAAS,kBAAkB;AAC3D,aAAO,SAAS,SAAS,CAAC,EAAE,KAAK,IAAI;AACrC,aAAO,SAAS,MAAM,CAAC,EAAE,KAAK,kCAAkC;AAAA,IAClE,CAAC;AAAA,EACH,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/util/head.ts
21
+ var head_exports = {};
22
+ __export(head_exports, {
23
+ head: () => head
24
+ });
25
+ module.exports = __toCommonJS(head_exports);
26
+ var import_monads_io = require("monads-io");
27
+ function head(array) {
28
+ return import_monads_io.Maybe.fromNullable(array[0]);
29
+ }
30
+ //# sourceMappingURL=head.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/head.ts"],
4
+ "sourcesContent": ["import { Maybe } from \"monads-io\";\n\nexport function head<T>(array: T[]): Maybe<T> {\n return Maybe.fromNullable(array[0]);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AAEf,SAAS,KAAQ,OAAsB;AAC5C,SAAO,uBAAM,aAAa,MAAM,CAAC,CAAC;AACpC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/util/visibility.ts
21
+ var visibility_exports = {};
22
+ __export(visibility_exports, {
23
+ getVisibility: () => getVisibility,
24
+ toVisibilityEnum: () => toVisibilityEnum,
25
+ visibility: () => visibility
26
+ });
27
+ module.exports = __toCommonJS(visibility_exports);
28
+ var visibility = {
29
+ public: 0,
30
+ private: 1
31
+ };
32
+ var toVisibilityEnum = (input) => {
33
+ const value = +input;
34
+ if (value !== 0 && value !== 1) {
35
+ throw new Error("Invalid visibility value");
36
+ }
37
+ return value;
38
+ };
39
+ var getVisibility = (input) => {
40
+ return input === visibility.public ? "public" : "private";
41
+ };
42
+ //# sourceMappingURL=visibility.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/visibility.ts"],
4
+ "sourcesContent": ["export type VisibilityEnum = number & { __brand: \"VisibilityEnum\" };\n\nexport const visibility = {\n public: 0 as VisibilityEnum,\n private: 1 as VisibilityEnum,\n};\n\nexport const toVisibilityEnum = (input: string | number): VisibilityEnum => {\n const value = +input;\n if (value !== 0 && value !== 1) {\n throw new Error(\"Invalid visibility value\");\n }\n return value as VisibilityEnum;\n};\n\nexport const getVisibility = (input: VisibilityEnum): string => {\n return input === visibility.public ? \"public\" : \"private\";\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,aAAa;AAAA,EACxB,QAAQ;AAAA,EACR,SAAS;AACX;AAEO,IAAM,mBAAmB,CAAC,UAA2C;AAC1E,QAAM,QAAQ,CAAC;AACf,MAAI,UAAU,KAAK,UAAU,GAAG;AAC9B,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AACA,SAAO;AACT;AAEO,IAAM,gBAAgB,CAAC,UAAkC;AAC9D,SAAO,UAAU,WAAW,SAAS,WAAW;AAClD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ // src/client/browserClient.ts
2
+ import { WebKwil } from "@kwilteam/kwil-js";
3
+ import { BaseTNClient } from "./client.mjs";
4
+ var BrowserTNClient = class extends BaseTNClient {
5
+ constructor(options) {
6
+ super(options);
7
+ this.kwilClient = new WebKwil({
8
+ ...options,
9
+ kwilProvider: options.endpoint
10
+ });
11
+ }
12
+ };
13
+ var browserClient_default = BrowserTNClient;
14
+ export {
15
+ BrowserTNClient,
16
+ browserClient_default as default
17
+ };
18
+ //# sourceMappingURL=browserClient.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/client/browserClient.ts"],
4
+ "sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { WebKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\n\nexport class BrowserTNClient extends BaseTNClient<EnvironmentType.BROWSER> {\n constructor(options: TNClientOptions) {\n super(options);\n this.kwilClient = new WebKwil({\n ...options,\n kwilProvider: options.endpoint,\n });\n }\n}\n\nexport default BrowserTNClient;\n"],
5
+ "mappings": ";AACA,SAAS,eAAe;AACxB,SAAS,oBAAqC;AAEvC,IAAM,kBAAN,cAA8B,aAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,QAAQ;AAAA,MAC5B,GAAG;AAAA,MACH,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,wBAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,183 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // src/client/client.ts
6
+ import { Client, KwilSigner } from "@kwilteam/kwil-js";
7
+ import { ComposedStream } from "../contracts-api/composedStream.mjs";
8
+ import { deployStream } from "../contracts-api/deployStream.mjs";
9
+ import { destroyStream } from "../contracts-api/destroyStream.mjs";
10
+ import { PrimitiveStream } from "../contracts-api/primitiveStream.mjs";
11
+ import { Stream } from "../contracts-api/stream.mjs";
12
+ import { EthereumAddress } from "../util/EthereumAddress.mjs";
13
+ import { listAllStreams } from "./listAllStreams.mjs";
14
+ var BaseTNClient = class {
15
+ constructor(options) {
16
+ __publicField(this, "kwilClient");
17
+ __publicField(this, "signerInfo");
18
+ this.signerInfo = options.signerInfo;
19
+ }
20
+ /**
21
+ * Waits for a transaction to be mined by TN.
22
+ * @param txHash - The transaction hash to wait for.
23
+ * @param timeout - The timeout in milliseconds.
24
+ * @returns A promise that resolves to the transaction info receipt.
25
+ */
26
+ async waitForTx(txHash, timeout = 12e3) {
27
+ return new Promise(async (resolve, reject) => {
28
+ const interval = setInterval(async () => {
29
+ const receipt = await this.getKwilClient()["txInfoClient"](txHash).catch(() => ({ data: void 0, status: void 0 }));
30
+ switch (receipt.status) {
31
+ case 200:
32
+ if (receipt.data?.tx_result.log === "success") {
33
+ resolve(receipt.data);
34
+ } else {
35
+ reject(
36
+ new Error(
37
+ `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`
38
+ )
39
+ );
40
+ }
41
+ break;
42
+ case void 0:
43
+ break;
44
+ default:
45
+ reject(
46
+ new Error(
47
+ `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`
48
+ )
49
+ );
50
+ }
51
+ }, 1e3);
52
+ setTimeout(() => {
53
+ clearInterval(interval);
54
+ reject(new Error("Transaction failed: Timeout"));
55
+ }, timeout);
56
+ });
57
+ }
58
+ /**
59
+ * Returns the Kwil signer used by the client.
60
+ * @returns An instance of KwilSigner.
61
+ */
62
+ getKwilSigner() {
63
+ return new KwilSigner(
64
+ this.signerInfo.signer,
65
+ this.address().getAddress()
66
+ );
67
+ }
68
+ /**
69
+ * Returns the Kwil client used by the client.
70
+ * @returns An instance of Kwil.
71
+ * @throws If the Kwil client is not initialized.
72
+ */
73
+ getKwilClient() {
74
+ if (!this.kwilClient) {
75
+ throw new Error("Kwil client not initialized");
76
+ }
77
+ return this.kwilClient;
78
+ }
79
+ /**
80
+ * Deploys a new stream.
81
+ * @param streamId - The ID of the stream to deploy.
82
+ * @param streamType - The type of the stream.
83
+ * @param synchronous - Whether the deployment should be synchronous.
84
+ * @returns A promise that resolves to a generic response containing the transaction receipt.
85
+ */
86
+ async deployStream(streamId, streamType, synchronous) {
87
+ return await deployStream({
88
+ streamId,
89
+ streamType,
90
+ synchronous,
91
+ kwilClient: this.getKwilClient(),
92
+ kwilSigner: this.getKwilSigner()
93
+ });
94
+ }
95
+ /**
96
+ * Destroys a stream.
97
+ * @param streamId - The ID of the stream to destroy.
98
+ * @param synchronous - Whether the destruction should be synchronous.
99
+ * @returns A promise that resolves to a generic response containing the transaction receipt.
100
+ */
101
+ async destroyStream(streamId, synchronous) {
102
+ return await destroyStream({
103
+ streamId,
104
+ synchronous,
105
+ kwilClient: this.getKwilClient(),
106
+ kwilSigner: this.getKwilSigner()
107
+ });
108
+ }
109
+ /**
110
+ * Loads an already deployed stream, permitting its API usage.
111
+ * @param stream - The locator of the stream to load.
112
+ * @returns An instance of IStream.
113
+ */
114
+ loadStream(stream) {
115
+ return new Stream(
116
+ this.getKwilClient(),
117
+ this.getKwilSigner(),
118
+ stream
119
+ );
120
+ }
121
+ /**
122
+ * Loads a primitive stream.
123
+ * @param stream - The locator of the primitive stream to load.
124
+ * @returns An instance of IPrimitiveStream.
125
+ */
126
+ loadPrimitiveStream(stream) {
127
+ return PrimitiveStream.fromStream(this.loadStream(stream));
128
+ }
129
+ /**
130
+ * Loads a composed stream.
131
+ * @param stream - The locator of the composed stream to load.
132
+ * @returns An instance of IComposedStream.
133
+ */
134
+ loadComposedStream(stream) {
135
+ return new ComposedStream(
136
+ this.getKwilClient(),
137
+ this.getKwilSigner(),
138
+ stream
139
+ );
140
+ }
141
+ /**
142
+ * Creates a new stream locator.
143
+ * @param streamId - The ID of the stream.
144
+ * @returns A StreamLocator object.
145
+ */
146
+ ownStreamLocator(streamId) {
147
+ return {
148
+ streamId,
149
+ dataProvider: this.address()
150
+ };
151
+ }
152
+ /**
153
+ * Returns the address of the signer used by the client.
154
+ * @returns An instance of EthereumAddress.
155
+ */
156
+ address() {
157
+ return new EthereumAddress(this.signerInfo.address);
158
+ }
159
+ /**
160
+ * Returns all streams from the TN network.
161
+ * @param owner - The owner of the streams. If not provided, all streams will be returned.
162
+ * @returns A promise that resolves to a list of stream locators.
163
+ */
164
+ async getAllStreams(owner) {
165
+ return listAllStreams(this.getKwilClient(), owner);
166
+ }
167
+ /**
168
+ * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.
169
+ * @param provider - The provider URL.
170
+ * @returns A promise that resolves to the chain ID.
171
+ */
172
+ static async getDefaultChainId(provider) {
173
+ const kwilClient = new Client({
174
+ kwilProvider: provider
175
+ });
176
+ const chainInfo = await kwilClient["chainInfoClient"]();
177
+ return chainInfo.data?.chain_id;
178
+ }
179
+ };
180
+ export {
181
+ BaseTNClient
182
+ };
183
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/client/client.ts"],
4
+ "sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { KwilConfig } from \"@kwilteam/kwil-js/dist/api_client/config\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EthSigner } from \"@kwilteam/kwil-js/dist/core/builders\";\nimport { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { TxInfoReceipt } from \"@kwilteam/kwil-js/dist/core/txQuery\";\nimport { ComposedStream } from \"../contracts-api/composedStream\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { destroyStream } from \"../contracts-api/destroyStream\";\nimport { PrimitiveStream } from \"../contracts-api/primitiveStream\";\nimport { Stream } from \"../contracts-api/stream\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listAllStreams } from \"./listAllStreams\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n} & Omit<KwilConfig, \"kwilProvider\">;\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<TxInfoReceipt> {\n return new Promise<TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result.log === \"success\") {\n resolve(receipt.data);\n } else {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param streamId - The ID of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n streamId: StreamId,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await destroyStream({\n streamId,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @param stream - The locator of the stream to load.\n * @returns An instance of IStream.\n */\n loadStream(stream: StreamLocator): Stream {\n return new Stream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n );\n }\n\n /**\n * Loads a primitive stream.\n * @param stream - The locator of the primitive stream to load.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveStream(stream: StreamLocator): PrimitiveStream {\n return PrimitiveStream.fromStream(this.loadStream(stream));\n }\n\n /**\n * Loads a composed stream.\n * @param stream - The locator of the composed stream to load.\n * @returns An instance of IComposedStream.\n */\n loadComposedStream(stream: StreamLocator): ComposedStream {\n return new ComposedStream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n );\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param owner - The owner of the streams. If not provided, all streams will be returned.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getAllStreams(owner?: EthereumAddress): Promise<StreamLocator[]> {\n return listAllStreams(this.getKwilClient(), owner);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n}\n"],
5
+ "mappings": ";;;;;AAAA,SAAS,QAAQ,kBAAqC;AAQtD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,cAAc;AAGvB,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAaxB,IAAe,eAAf,MAAuD;AAAA,EAIlD,YAAY,SAA0B;AAHhD,wBAAU;AACV,wBAAU;AAGR,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UAAU,QAAgB,UAAU,MAA+B;AACvE,WAAO,IAAI,QAAuB,OAAO,SAAS,WAAW;AAC3D,YAAM,WAAW,YAAY,YAAY;AACvC,cAAM,UAAU,MAAM,KAAK,cAAc,EACtC,cAAc,EAAE,MAAM,EACtB,MAAM,OAAO,EAAE,MAAM,QAAW,QAAQ,OAAU,EAAE;AACvD,gBAAQ,QAAQ,QAAQ;AAAA,UACtB,KAAK;AACH,gBAAI,QAAQ,MAAM,UAAU,QAAQ,WAAW;AAC7C,sBAAQ,QAAQ,IAAI;AAAA,YACtB,OAAO;AACL;AAAA,gBACE,IAAI;AAAA,kBACF,8BAA8B,QAAQ,MAAM,kBAAkB,QAAQ,MAAM,UAAU,GAAG;AAAA,gBAC3F;AAAA,cACF;AAAA,YACF;AACA;AAAA,UACF,KAAK;AACH;AAAA,UACF;AACE;AAAA,cACE,IAAI;AAAA,gBACF,8BAA8B,QAAQ,MAAM,kBAAkB,QAAQ,MAAM,UAAU,GAAG;AAAA,cAC3F;AAAA,YACF;AAAA,QACJ;AAAA,MACF,GAAG,GAAI;AACP,iBAAW,MAAM;AACf,sBAAc,QAAQ;AACtB,eAAO,IAAI,MAAM,6BAA6B,CAAC;AAAA,MACjD,GAAG,OAAO;AAAA,IACZ,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAA4B;AAC1B,WAAO,IAAI;AAAA,MACT,KAAK,WAAW;AAAA,MAChB,KAAK,QAAQ,EAAE,WAAW;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,gBAAuC;AACrC,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,aACJ,UACA,YACA,aACqC;AACrC,WAAO,MAAM,aAAa;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY,KAAK,cAAc;AAAA,MAC/B,YAAY,KAAK,cAAc;AAAA,IACjC,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,cACJ,UACA,aACqC;AACrC,WAAO,MAAM,cAAc;AAAA,MACzB;AAAA,MACA;AAAA,MACA,YAAY,KAAK,cAAc;AAAA,MAC/B,YAAY,KAAK,cAAc;AAAA,IACjC,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,QAA+B;AACxC,WAAO,IAAI;AAAA,MACT,KAAK,cAAc;AAAA,MACnB,KAAK,cAAc;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,oBAAoB,QAAwC;AAC1D,WAAO,gBAAgB,WAAW,KAAK,WAAW,MAAM,CAAC;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,mBAAmB,QAAuC;AACxD,WAAO,IAAI;AAAA,MACT,KAAK,cAAc;AAAA,MACnB,KAAK,cAAc;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,iBAAiB,UAAmC;AAClD,WAAO;AAAA,MACL;AAAA,MACA,cAAc,KAAK,QAAQ;AAAA,IAC7B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAA2B;AACzB,WAAO,IAAI,gBAAgB,KAAK,WAAW,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAc,OAAmD;AACrE,WAAO,eAAe,KAAK,cAAc,GAAG,KAAK;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAoB,kBAAkB,UAAkB;AACtD,UAAM,aAAa,IAAI,OAAO;AAAA,MAC5B,cAAc;AAAA,IAChB,CAAC;AACD,UAAM,YAAY,MAAM,WAAW,iBAAiB,EAAE;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,30 @@
1
+ // src/client/client.test.ts
2
+ import { describe, expect, it } from "vitest";
3
+ import { ethers } from "ethers";
4
+ import { NodeTNClient } from "./nodeClient.mjs";
5
+ describe.sequential("Client", { timeout: 3e4 }, () => {
6
+ it.skipIf(process.env.CI);
7
+ const wallet = new ethers.Wallet(
8
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
9
+ );
10
+ it("should create a client", async () => {
11
+ const chainId = await NodeTNClient.getDefaultChainId(
12
+ "http://localhost:8484"
13
+ );
14
+ if (!chainId) {
15
+ throw new Error("Chain id not found");
16
+ }
17
+ const client = new NodeTNClient({
18
+ endpoint: "http://localhost:8484",
19
+ signerInfo: {
20
+ address: wallet.address,
21
+ signer: wallet
22
+ },
23
+ chainId
24
+ });
25
+ const kwilClient = client.getKwilClient();
26
+ const chainInfo = await kwilClient.chainInfo();
27
+ expect(chainInfo.data?.chain_id).toBeDefined();
28
+ });
29
+ });
30
+ //# sourceMappingURL=client.test.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/client/client.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from \"vitest\";\nimport { ethers } from \"ethers\";\nimport { NodeTNClient } from \"./nodeClient\";\n\ndescribe.sequential(\"Client\", { timeout: 30000 }, () => {\n // Skip in CI, because it needs a local node\n it.skipIf(process.env.CI);\n\n const wallet = new ethers.Wallet(\n \"0x0000000000000000000000000000000000000000000000000000000000000001\",\n );\n it(\"should create a client\", async () => {\n const chainId = await NodeTNClient.getDefaultChainId(\n \"http://localhost:8484\",\n );\n if (!chainId) {\n throw new Error(\"Chain id not found\");\n }\n const client = new NodeTNClient({\n endpoint: \"http://localhost:8484\",\n signerInfo: {\n address: wallet.address,\n signer: wallet,\n },\n chainId,\n });\n const kwilClient = client.getKwilClient();\n const chainInfo = await kwilClient.chainInfo();\n expect(chainInfo.data?.chain_id).toBeDefined();\n });\n});\n"],
5
+ "mappings": ";AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAE7B,SAAS,WAAW,UAAU,EAAE,SAAS,IAAM,GAAG,MAAM;AAEtD,KAAG,OAAO,QAAQ,IAAI,EAAE;AAExB,QAAM,SAAS,IAAI,OAAO;AAAA,IACxB;AAAA,EACF;AACA,KAAG,0BAA0B,YAAY;AACvC,UAAM,UAAU,MAAM,aAAa;AAAA,MACjC;AAAA,IACF;AACA,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,oBAAoB;AAAA,IACtC;AACA,UAAM,SAAS,IAAI,aAAa;AAAA,MAC9B,UAAU;AAAA,MACV,YAAY;AAAA,QACV,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MACV;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa,OAAO,cAAc;AACxC,UAAM,YAAY,MAAM,WAAW,UAAU;AAC7C,WAAO,UAAU,MAAM,QAAQ,EAAE,YAAY;AAAA,EAC/C,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,30 @@
1
+ // src/client/listAllStreams.ts
2
+ import { EthereumAddress } from "../util/EthereumAddress.mjs";
3
+ import { StreamId } from "../util/StreamId.mjs";
4
+ async function listAllStreams(kwilClient, owner) {
5
+ const databases = await kwilClient.listDatabases(owner?.getAddress());
6
+ const schemas = await Promise.all(
7
+ databases.data?.map(async (database) => {
8
+ const schema = await kwilClient.getSchema(database.dbid);
9
+ if (schema.status === 200 && schema.data && isStream(schema.data)) {
10
+ return schema.data;
11
+ }
12
+ return void 0;
13
+ }) ?? []
14
+ );
15
+ return schemas.filter((schema) => schema !== void 0).map((schema) => ({
16
+ streamId: StreamId.fromString(schema.name).throw(),
17
+ dataProvider: EthereumAddress.fromBytes(schema.owner).throw()
18
+ }));
19
+ }
20
+ var isStream = (schema) => {
21
+ const requiredProcedures = ["get_index", "get_record", "get_metadata"];
22
+ return requiredProcedures.every(
23
+ (procedure) => schema.procedures.some((p) => p.name === procedure)
24
+ );
25
+ };
26
+ export {
27
+ isStream,
28
+ listAllStreams
29
+ };
30
+ //# sourceMappingURL=listAllStreams.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/client/listAllStreams.ts"],
4
+ "sourcesContent": ["import { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { Database } from \"@kwilteam/kwil-js/dist/core/database\";\n\n/**\n * List all streams from the TN network.\n * @param kwilClient - The Kwil client.\n * @param owner - The owner of the streams. If not provided, all streams will be returned.\n * @returns A list of stream locators.\n */\nexport async function listAllStreams(\n kwilClient: Kwil<EnvironmentType>,\n owner?: EthereumAddress,\n): Promise<StreamLocator[]> {\n const databases = await kwilClient.listDatabases(owner?.getAddress());\n const schemas = await Promise.all(\n databases.data?.map(async (database) => {\n const schema = await kwilClient.getSchema(database.dbid);\n if (schema.status === 200 && schema.data && isStream(schema.data)) {\n return schema.data;\n }\n return undefined;\n }) ?? [],\n );\n return schemas\n .filter((schema) => schema !== undefined)\n .map((schema) => ({\n streamId: StreamId.fromString(schema.name).throw(),\n dataProvider: EthereumAddress.fromBytes(schema.owner).throw(),\n }));\n}\n\nexport const isStream = (schema: Database) => {\n const requiredProcedures = [\"get_index\", \"get_record\", \"get_metadata\"];\n return requiredProcedures.every((procedure) =>\n schema.procedures.some((p) => p.name === procedure),\n );\n};\n"],
5
+ "mappings": ";AAGA,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AASzB,eAAsB,eACpB,YACA,OAC0B;AAC1B,QAAM,YAAY,MAAM,WAAW,cAAc,OAAO,WAAW,CAAC;AACpE,QAAM,UAAU,MAAM,QAAQ;AAAA,IAC5B,UAAU,MAAM,IAAI,OAAO,aAAa;AACtC,YAAM,SAAS,MAAM,WAAW,UAAU,SAAS,IAAI;AACvD,UAAI,OAAO,WAAW,OAAO,OAAO,QAAQ,SAAS,OAAO,IAAI,GAAG;AACjE,eAAO,OAAO;AAAA,MAChB;AACA,aAAO;AAAA,IACT,CAAC,KAAK,CAAC;AAAA,EACT;AACA,SAAO,QACJ,OAAO,CAAC,WAAW,WAAW,MAAS,EACvC,IAAI,CAAC,YAAY;AAAA,IAChB,UAAU,SAAS,WAAW,OAAO,IAAI,EAAE,MAAM;AAAA,IACjD,cAAc,gBAAgB,UAAU,OAAO,KAAK,EAAE,MAAM;AAAA,EAC9D,EAAE;AACN;AAEO,IAAM,WAAW,CAAC,WAAqB;AAC5C,QAAM,qBAAqB,CAAC,aAAa,cAAc,cAAc;AACrE,SAAO,mBAAmB;AAAA,IAAM,CAAC,cAC/B,OAAO,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AAAA,EACpD;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ // src/client/nodeClient.ts
2
+ import { NodeKwil } from "@kwilteam/kwil-js";
3
+ import { BaseTNClient } from "./client.mjs";
4
+ var NodeTNClient = class extends BaseTNClient {
5
+ constructor(options) {
6
+ super(options);
7
+ this.kwilClient = new NodeKwil({
8
+ ...options,
9
+ kwilProvider: options.endpoint
10
+ });
11
+ }
12
+ };
13
+ var nodeClient_default = NodeTNClient;
14
+ export {
15
+ NodeTNClient,
16
+ nodeClient_default as default
17
+ };
18
+ //# sourceMappingURL=nodeClient.mjs.map