@certik/skynet 0.24.0 → 0.25.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 (55) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/examples/api.ts +0 -0
  3. package/examples/indexer.ts +0 -0
  4. package/examples/mode-indexer.ts +0 -0
  5. package/package.json +1 -10
  6. package/src/graphql.ts +14 -4
  7. package/src/por.ts +18 -23
  8. package/.vscode/settings.json +0 -5
  9. package/dist/abi.d.ts +0 -111
  10. package/dist/abi.js +0 -571
  11. package/dist/address.d.ts +0 -2
  12. package/dist/address.js +0 -24
  13. package/dist/api.d.ts +0 -31
  14. package/dist/api.js +0 -260
  15. package/dist/app.d.ts +0 -101
  16. package/dist/app.js +0 -2077
  17. package/dist/availability.d.ts +0 -23
  18. package/dist/availability.js +0 -133
  19. package/dist/cli.d.ts +0 -5
  20. package/dist/cli.js +0 -41
  21. package/dist/const.d.ts +0 -34
  22. package/dist/const.js +0 -162
  23. package/dist/databricks.d.ts +0 -3
  24. package/dist/databricks.js +0 -208
  25. package/dist/date.d.ts +0 -5
  26. package/dist/date.js +0 -56
  27. package/dist/deploy.d.ts +0 -75
  28. package/dist/deploy.js +0 -587
  29. package/dist/dynamodb.d.ts +0 -16
  30. package/dist/dynamodb.js +0 -479
  31. package/dist/env.d.ts +0 -6
  32. package/dist/env.js +0 -26
  33. package/dist/goalert.d.ts +0 -19
  34. package/dist/goalert.js +0 -43
  35. package/dist/graphql.d.ts +0 -5
  36. package/dist/graphql.js +0 -28
  37. package/dist/indexer.d.ts +0 -69
  38. package/dist/indexer.js +0 -1099
  39. package/dist/log.d.ts +0 -13
  40. package/dist/log.js +0 -63
  41. package/dist/object-hash.d.ts +0 -1
  42. package/dist/object-hash.js +0 -61
  43. package/dist/por.d.ts +0 -37
  44. package/dist/por.js +0 -120
  45. package/dist/s3.d.ts +0 -20
  46. package/dist/s3.js +0 -122
  47. package/dist/search.d.ts +0 -5
  48. package/dist/search.js +0 -105
  49. package/dist/selector.d.ts +0 -17
  50. package/dist/selector.js +0 -44
  51. package/dist/slack.d.ts +0 -14
  52. package/dist/slack.js +0 -29
  53. package/dist/util.d.ts +0 -4
  54. package/dist/util.js +0 -27
  55. package/src/databricks.ts +0 -82
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.25.0
4
+
5
+ - Added support for GraphQL v2 with `version` parameter to `gql` function
6
+ - Removed `executeSql` function in `databricks` library
7
+
3
8
  ## 0.24.0
4
9
 
5
10
  - BREAKING: `slack` `postMessageToConversation` no longer accepts `ChatPostMessageArguments` when `conversationId` is provided; pass a full `ChatPostMessageArguments` payload with `conversationId` omitted instead
package/examples/api.ts CHANGED
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "exports": {
@@ -32,10 +32,6 @@
32
32
  "import": "./dist/const.js",
33
33
  "types": "./dist/const.d.ts"
34
34
  },
35
- "./databricks": {
36
- "import": "./dist/databricks.js",
37
- "types": "./dist/databricks.d.ts"
38
- },
39
35
  "./date": {
40
36
  "import": "./dist/date.js",
41
37
  "types": "./dist/date.d.ts"
@@ -114,7 +110,6 @@
114
110
  "@aws-sdk/client-s3": "^3.975.0",
115
111
  "@aws-sdk/client-sqs": "^3.975.0",
116
112
  "@aws-sdk/lib-dynamodb": "^3.975.0",
117
- "@databricks/sql": "^1.12.0",
118
113
  "@elastic/elasticsearch": "^8.19.1",
119
114
  "@node-rs/xxhash": "^1.7.6",
120
115
  "@slack/web-api": "^7.13.0",
@@ -145,9 +140,5 @@
145
140
  "license": "MIT",
146
141
  "publishConfig": {
147
142
  "access": "public"
148
- },
149
- "patchedDependencies": {
150
- "@databricks/sql@1.9.0": "patches/@databricks%2Fsql@1.9.0.patch",
151
- "@databricks/sql@1.12.0": "patches/@databricks%2Fsql@1.12.0.patch"
152
143
  }
153
144
  }
package/src/graphql.ts CHANGED
@@ -12,12 +12,22 @@ type GraphQLResponse<TData> = {
12
12
  errors?: GraphQLError[];
13
13
  };
14
14
 
15
- export async function gql<T>(query: string, variables: GraphqlVariables = {}) {
16
- const endpoint = process.env["SKYNET_GRAPHQL_ENDPOINT"];
17
- const apiKey = process.env["SKYNET_GRAPHQL_API_KEY"];
15
+ type GraphQLVersion = "v1" | "v2";
16
+
17
+ export async function gql<T>(query: string, variables: GraphqlVariables = {}, version: GraphQLVersion = "v1") {
18
+ if (!["v1", "v2"].includes(version)) {
19
+ throw new Error(`Invalid GraphQL version: ${version}`);
20
+ }
21
+
22
+ let endpoint = process.env["SKYNET_GRAPHQL_ENDPOINT"];
23
+ let apiKey = process.env["SKYNET_GRAPHQL_API_KEY"];
24
+ if (version === "v2") {
25
+ endpoint = process.env["SKYNET_GRAPHQL_ENDPOINT_V2"];
26
+ apiKey = process.env["SKYNET_GRAPHQL_API_KEY_V2"];
27
+ }
18
28
 
19
29
  if (!endpoint || !apiKey) {
20
- throw new Error("SKYNET_GRAPHQL_ENDPOINT or SKYNET_GRAPHQL_API_KEY is not set");
30
+ throw new Error(`Missing GraphQL ${version} endpoint or API key`);
21
31
  }
22
32
 
23
33
  const res = await fetch(endpoint, {
package/src/por.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CryptoHasher } from "bun";
1
+ import { CryptoHasher } from "bun";
2
2
 
3
3
  export interface UserLiability {
4
4
  userHash: string;
@@ -11,7 +11,7 @@ export interface MerkleProof {
11
11
  balance: number;
12
12
  token?: string;
13
13
  proof: string[];
14
- positions: ('left' | 'right')[];
14
+ positions: ("left" | "right")[];
15
15
  rootHash: string;
16
16
  leafIndex: number;
17
17
  hashFunction?: (data: string) => string;
@@ -53,28 +53,27 @@ export class MerkleTreePoR {
53
53
  return this.hashFunction(data);
54
54
  }
55
55
 
56
-
57
56
  // hash user data
58
57
  private createLeafHash(user: UserLiability): string {
59
- const leafData = `${user.userHash}:${user.balance}:${user.token || ''}`;
58
+ const leafData = `${user.userHash}:${user.balance}:${user.token || ""}`;
60
59
  return this.hash(leafData);
61
60
  }
62
61
 
63
62
  private buildTree(): void {
64
63
  if (this.userData.length === 0) {
65
- throw new Error('Cannot build tree with empty user data');
64
+ throw new Error("Cannot build tree with empty user data");
66
65
  }
67
66
 
68
67
  // Create leaf hashes and store user mapping
69
68
  this.leaves = this.userData.map((user, index) => {
70
69
  const leafHash = this.createLeafHash(user);
71
- this.userMap.set(`${user.userHash}:${user.token || ''}`, index);
70
+ this.userMap.set(`${user.userHash}:${user.token || ""}`, index);
72
71
  return leafHash;
73
72
  });
74
73
 
75
74
  // Start with leaf level
76
75
  let currentLevel = this.leaves;
77
- this.tree.push(currentLevel.map(hash => ({ hash })));
76
+ this.tree.push(currentLevel.map((hash) => ({ hash })));
78
77
 
79
78
  // Build tree bottom-up
80
79
  while (currentLevel.length > 1) {
@@ -83,22 +82,18 @@ export class MerkleTreePoR {
83
82
 
84
83
  for (let i = 0; i < currentLevel.length; i += 2) {
85
84
  const left = currentLevel[i];
86
- const right = i + 1 < currentLevel.length
87
- ? currentLevel[i + 1]
88
- : left; // Duplicate if odd number
85
+ const right = i + 1 < currentLevel.length ? currentLevel[i + 1] : left; // Duplicate if odd number
89
86
 
90
87
  const parentHash = this.hash(left + right);
91
88
  nextLevel.push(parentHash);
92
89
 
93
90
  const leftNode = this.tree[this.tree.length - 1][i];
94
- const rightNode = i + 1 < currentLevel.length
95
- ? this.tree[this.tree.length - 1][i + 1]
96
- : leftNode;
91
+ const rightNode = i + 1 < currentLevel.length ? this.tree[this.tree.length - 1][i + 1] : leftNode;
97
92
 
98
93
  nextLevelNodes.push({
99
94
  hash: parentHash,
100
95
  left: leftNode,
101
- right: rightNode
96
+ right: rightNode,
102
97
  });
103
98
  }
104
99
 
@@ -110,14 +105,14 @@ export class MerkleTreePoR {
110
105
  // get root hash of created tree
111
106
  getRootHash(): string {
112
107
  if (this.tree.length === 0) {
113
- throw new Error('Merkle tree not built');
108
+ throw new Error("Merkle tree not built");
114
109
  }
115
110
  return this.tree[this.tree.length - 1][0].hash;
116
111
  }
117
112
 
118
113
  // generate merkle proof
119
114
  generateProof(userHash: string, token?: string): MerkleProof {
120
- const key = `${userHash}:${token || ''}`;
115
+ const key = `${userHash}:${token || ""}`;
121
116
  const leafIndex = this.userMap.get(key);
122
117
  if (leafIndex === undefined) {
123
118
  throw new Error(`${userHash} not found in merkle tree for token ${token}`);
@@ -125,7 +120,7 @@ export class MerkleTreePoR {
125
120
 
126
121
  const user = this.userData[leafIndex];
127
122
  const proof: string[] = [];
128
- const positions: ('left' | 'right')[] = [];
123
+ const positions: ("left" | "right")[] = [];
129
124
 
130
125
  let currentIndex = leafIndex;
131
126
 
@@ -137,11 +132,11 @@ export class MerkleTreePoR {
137
132
 
138
133
  if (siblingIndex < currentLevelSize) {
139
134
  proof.push(this.tree[level][siblingIndex].hash);
140
- positions.push(isRightNode ? 'left' : 'right');
135
+ positions.push(isRightNode ? "left" : "right");
141
136
  } else {
142
137
  // When odd number, the last node is duplicated
143
138
  proof.push(this.tree[level][currentIndex].hash);
144
- positions.push(isRightNode ? 'left' : 'right');
139
+ positions.push(isRightNode ? "left" : "right");
145
140
  }
146
141
 
147
142
  currentIndex = Math.floor(currentIndex / 2);
@@ -155,21 +150,21 @@ export class MerkleTreePoR {
155
150
  positions,
156
151
  rootHash: this.getRootHash(),
157
152
  leafIndex,
158
- hashFunction: this.hashFunction !== this.defaultSHA256Hash ? this.hashFunction : undefined
153
+ hashFunction: this.hashFunction !== this.defaultSHA256Hash ? this.hashFunction : undefined,
159
154
  };
160
155
  }
161
156
 
162
157
  // verify inclusion using proof
163
158
  static verifyProof(merkleProof: MerkleProof): boolean {
164
- const leafData = `${merkleProof.userHash}:${merkleProof.balance}:${merkleProof.token || ''}`;
159
+ const leafData = `${merkleProof.userHash}:${merkleProof.balance}:${merkleProof.token || ""}`;
165
160
  const hashFunction = merkleProof.hashFunction || MerkleTreePoR.defaultSHA256Hash;
166
161
  let currentHash = hashFunction(leafData);
167
-
162
+
168
163
  for (let i = 0; i < merkleProof.proof.length; i++) {
169
164
  const siblingHash = merkleProof.proof[i];
170
165
  const position = merkleProof.positions[i];
171
166
 
172
- if (position === 'left') {
167
+ if (position === "left") {
173
168
  currentHash = hashFunction(siblingHash + currentHash);
174
169
  } else {
175
170
  currentHash = hashFunction(currentHash + siblingHash);
@@ -1,5 +0,0 @@
1
- {
2
- "conventionalCommits.scopes": [
3
- "lib-skynet"
4
- ]
5
- }
package/dist/abi.d.ts DELETED
@@ -1,111 +0,0 @@
1
- export declare const ERC20: ({
2
- constant: boolean;
3
- inputs: {
4
- name: string;
5
- type: string;
6
- }[];
7
- name: string;
8
- outputs: {
9
- name: string;
10
- type: string;
11
- }[];
12
- payable: boolean;
13
- stateMutability: string;
14
- type: string;
15
- } | {
16
- name: string;
17
- payable: boolean;
18
- stateMutability: string;
19
- type: string;
20
- constant?: undefined;
21
- inputs?: undefined;
22
- outputs?: undefined;
23
- } | {
24
- inputs: {
25
- indexed: boolean;
26
- name: string;
27
- type: string;
28
- }[];
29
- name: string;
30
- type: string;
31
- constant?: undefined;
32
- outputs?: undefined;
33
- payable?: undefined;
34
- stateMutability?: undefined;
35
- })[];
36
- export declare const ERC721: ({
37
- inputs: {
38
- indexed: boolean;
39
- internalType: string;
40
- name: string;
41
- type: string;
42
- }[];
43
- name: string;
44
- type: string;
45
- constant?: undefined;
46
- outputs?: undefined;
47
- payable?: undefined;
48
- stateMutability?: undefined;
49
- } | {
50
- constant: boolean;
51
- inputs: never[];
52
- name: string;
53
- outputs: {
54
- name: string;
55
- type: string;
56
- }[];
57
- payable: boolean;
58
- stateMutability: string;
59
- type: string;
60
- } | {
61
- inputs: {
62
- internalType: string;
63
- name: string;
64
- type: string;
65
- }[];
66
- name: string;
67
- outputs: {
68
- internalType: string;
69
- name: string;
70
- type: string;
71
- }[];
72
- stateMutability: string;
73
- type: string;
74
- constant?: undefined;
75
- payable?: undefined;
76
- })[];
77
- export declare const BEP20: ({
78
- constant: boolean;
79
- inputs: {
80
- name: string;
81
- type: string;
82
- }[];
83
- name: string;
84
- outputs: {
85
- name: string;
86
- type: string;
87
- }[];
88
- payable: boolean;
89
- stateMutability: string;
90
- type: string;
91
- } | {
92
- name: string;
93
- payable: boolean;
94
- stateMutability: string;
95
- type: string;
96
- constant?: undefined;
97
- inputs?: undefined;
98
- outputs?: undefined;
99
- } | {
100
- inputs: {
101
- indexed: boolean;
102
- name: string;
103
- type: string;
104
- }[];
105
- name: string;
106
- type: string;
107
- constant?: undefined;
108
- outputs?: undefined;
109
- payable?: undefined;
110
- stateMutability?: undefined;
111
- })[];