@certik/skynet 0.23.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 (56) hide show
  1. package/CHANGELOG.md +11 -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 -12
  6. package/src/graphql.ts +14 -4
  7. package/src/por.ts +18 -23
  8. package/src/slack.ts +16 -12
  9. package/.vscode/settings.json +0 -5
  10. package/dist/abi.d.ts +0 -111
  11. package/dist/abi.js +0 -571
  12. package/dist/address.d.ts +0 -2
  13. package/dist/address.js +0 -24
  14. package/dist/api.d.ts +0 -31
  15. package/dist/api.js +0 -260
  16. package/dist/app.d.ts +0 -101
  17. package/dist/app.js +0 -2077
  18. package/dist/availability.d.ts +0 -23
  19. package/dist/availability.js +0 -133
  20. package/dist/cli.d.ts +0 -5
  21. package/dist/cli.js +0 -41
  22. package/dist/const.d.ts +0 -34
  23. package/dist/const.js +0 -162
  24. package/dist/databricks.d.ts +0 -3
  25. package/dist/databricks.js +0 -208
  26. package/dist/date.d.ts +0 -5
  27. package/dist/date.js +0 -56
  28. package/dist/deploy.d.ts +0 -75
  29. package/dist/deploy.js +0 -587
  30. package/dist/dynamodb.d.ts +0 -16
  31. package/dist/dynamodb.js +0 -479
  32. package/dist/env.d.ts +0 -6
  33. package/dist/env.js +0 -26
  34. package/dist/goalert.d.ts +0 -19
  35. package/dist/goalert.js +0 -43
  36. package/dist/graphql.d.ts +0 -5
  37. package/dist/graphql.js +0 -28
  38. package/dist/indexer.d.ts +0 -69
  39. package/dist/indexer.js +0 -1099
  40. package/dist/log.d.ts +0 -13
  41. package/dist/log.js +0 -63
  42. package/dist/object-hash.d.ts +0 -1
  43. package/dist/object-hash.js +0 -61
  44. package/dist/por.d.ts +0 -37
  45. package/dist/por.js +0 -120
  46. package/dist/s3.d.ts +0 -20
  47. package/dist/s3.js +0 -122
  48. package/dist/search.d.ts +0 -5
  49. package/dist/search.js +0 -105
  50. package/dist/selector.d.ts +0 -17
  51. package/dist/selector.js +0 -44
  52. package/dist/slack.d.ts +0 -9
  53. package/dist/slack.js +0 -32
  54. package/dist/util.d.ts +0 -4
  55. package/dist/util.js +0 -27
  56. package/src/databricks.ts +0 -82
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
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
+
8
+ ## 0.24.0
9
+
10
+ - BREAKING: `slack` `postMessageToConversation` no longer accepts `ChatPostMessageArguments` when `conversationId` is provided; pass a full `ChatPostMessageArguments` payload with `conversationId` omitted instead
11
+ - `slack`: improve type-safety for `postMessageToConversation` and post the payload directly
12
+ - Remove unused `md5` dependency and `@types/md5`
13
+
3
14
  ## 0.23.0
4
15
 
5
16
  - Added `goalert` module with `sendGoAlertAlert` helper
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.23.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,14 +110,12 @@
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",
121
116
  "chalk": "^5.6.2",
122
117
  "execa": "^9.6.1",
123
118
  "express": "^5.2.1",
124
- "md5": "^2.3.0",
125
119
  "meow": "^14.0.0",
126
120
  "p-memoize": "^8.0.0",
127
121
  "p-throttle": "^8.1.0",
@@ -133,7 +127,6 @@
133
127
  "@eslint/js": "^9.39.2",
134
128
  "@types/bun": "^1.3.6",
135
129
  "@types/express": "^5.0.6",
136
- "@types/md5": "^2.3.6",
137
130
  "@types/which": "^3.0.4",
138
131
  "eslint": "^9.39.2",
139
132
  "eslint-plugin-import": "^2.32.0",
@@ -147,9 +140,5 @@
147
140
  "license": "MIT",
148
141
  "publishConfig": {
149
142
  "access": "public"
150
- },
151
- "patchedDependencies": {
152
- "@databricks/sql@1.9.0": "patches/@databricks%2Fsql@1.9.0.patch",
153
- "@databricks/sql@1.12.0": "patches/@databricks%2Fsql@1.12.0.patch"
154
143
  }
155
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);
package/src/slack.ts CHANGED
@@ -11,12 +11,19 @@ async function postMessageToConversation({
11
11
  message,
12
12
  token,
13
13
  verbose,
14
- }: {
15
- conversationId: string;
16
- message: string | ChatPostMessageArguments;
17
- token?: string;
18
- verbose?: boolean;
19
- }) {
14
+ }:
15
+ | {
16
+ conversationId: string;
17
+ message: string;
18
+ token?: string;
19
+ verbose?: boolean;
20
+ }
21
+ | {
22
+ conversationId?: undefined;
23
+ message: ChatPostMessageArguments;
24
+ token?: string;
25
+ verbose?: boolean;
26
+ }) {
20
27
  if (!token) {
21
28
  throw new Error("missing slack token");
22
29
  }
@@ -24,16 +31,13 @@ async function postMessageToConversation({
24
31
  try {
25
32
  const client = getClient(token);
26
33
 
27
- const post = typeof message === "string" ? { text: message } : message;
34
+ const post = typeof conversationId === "string" ? { channel: conversationId, text: message } : message;
28
35
 
29
36
  if (verbose) {
30
- console.log(`posting to slack conversation ${conversationId}:`, JSON.stringify(post, null, 2));
37
+ console.log(`posting to slack:`, JSON.stringify(post, null, 2));
31
38
  }
32
39
 
33
- await client.chat.postMessage({
34
- channel: conversationId,
35
- ...post,
36
- });
40
+ await client.chat.postMessage(post);
37
41
  } catch (error) {
38
42
  console.error("failed to post slack message", error);
39
43
 
@@ -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
- })[];