@bytexbyte/nxtlinq-ai-agent-sdk 1.0.3 → 1.0.4
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.
- package/dist/index.js +28 -19
- package/package.json +1 -1
- package/tsconfig.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NxtlinqAIAgent = exports.NxtlinqAITSDK = exports.ChatBot = void 0;
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
9
|
+
const nxtlinq_api_1 = require("./api/nxtlinq-api");
|
|
10
|
+
var ChatBot_1 = require("./components/ChatBot");
|
|
11
|
+
Object.defineProperty(exports, "ChatBot", { enumerable: true, get: function () { return ChatBot_1.ChatBot; } });
|
|
12
|
+
class NxtlinqAITSDK {
|
|
6
13
|
constructor(serviceId, apiKey, apiSecret) {
|
|
7
14
|
this.signer = null;
|
|
8
15
|
this.walletAddress = null;
|
|
9
16
|
this.serviceId = serviceId;
|
|
10
|
-
this.api = createNxtlinqApi(apiKey, apiSecret);
|
|
17
|
+
this.api = (0, nxtlinq_api_1.createNxtlinqApi)(apiKey, apiSecret);
|
|
11
18
|
}
|
|
12
19
|
async connectWallet() {
|
|
13
20
|
if (typeof window === 'undefined' || !window.ethereum) {
|
|
14
21
|
throw new Error('MetaMask is not installed');
|
|
15
22
|
}
|
|
16
|
-
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
23
|
+
const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
|
|
17
24
|
this.signer = await provider.getSigner();
|
|
18
25
|
this.walletAddress = await this.signer.getAddress();
|
|
19
26
|
return this.walletAddress;
|
|
@@ -46,7 +53,7 @@ export class NxtlinqAITSDK {
|
|
|
46
53
|
code: nonceResponse.code,
|
|
47
54
|
timestamp: nonceResponse.timestamp
|
|
48
55
|
};
|
|
49
|
-
const stringToSign =
|
|
56
|
+
const stringToSign = (0, json_stable_stringify_1.default)(payload);
|
|
50
57
|
const signature = await this.signer.signMessage(stringToSign || '');
|
|
51
58
|
const response = await this.api.auth.signIn({
|
|
52
59
|
...payload,
|
|
@@ -72,8 +79,8 @@ export class NxtlinqAITSDK {
|
|
|
72
79
|
permissions,
|
|
73
80
|
issuedBy: this.walletAddress
|
|
74
81
|
};
|
|
75
|
-
const metadataStr =
|
|
76
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
|
|
82
|
+
const metadataStr = (0, json_stable_stringify_1.default)(metadata);
|
|
83
|
+
const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
|
|
77
84
|
// Upload metadata
|
|
78
85
|
const uploadResponse = await this.api.metadata.createMetadata({
|
|
79
86
|
...metadata,
|
|
@@ -84,8 +91,8 @@ export class NxtlinqAITSDK {
|
|
|
84
91
|
}
|
|
85
92
|
const { metadataCid } = uploadResponse;
|
|
86
93
|
// Sign the message
|
|
87
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, this.walletAddress, this.serviceId, metadataHash, timestamp]);
|
|
88
|
-
const signature = await this.signer.signMessage(ethers.getBytes(messageHash));
|
|
94
|
+
const messageHash = ethers_1.ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, this.walletAddress, this.serviceId, metadataHash, timestamp]);
|
|
95
|
+
const signature = await this.signer.signMessage(ethers_1.ethers.getBytes(messageHash));
|
|
89
96
|
// Register AIT
|
|
90
97
|
const response = await this.api.ait.createAIT({
|
|
91
98
|
aitId,
|
|
@@ -145,12 +152,13 @@ export class NxtlinqAITSDK {
|
|
|
145
152
|
return form.flatMap(group => group.options.filter((opt) => opt.isChecked).map((opt) => opt.value));
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
|
-
|
|
155
|
+
exports.NxtlinqAITSDK = NxtlinqAITSDK;
|
|
156
|
+
class NxtlinqAIAgent {
|
|
149
157
|
constructor(projectId, apiKey, apiSecret) {
|
|
150
158
|
this.permissions = [];
|
|
151
159
|
this.projectId = projectId;
|
|
152
160
|
this.apiKey = apiKey;
|
|
153
|
-
this.api = createNxtlinqApi(apiKey, apiSecret);
|
|
161
|
+
this.api = (0, nxtlinq_api_1.createNxtlinqApi)(apiKey, apiSecret);
|
|
154
162
|
}
|
|
155
163
|
setAIT(ait, signer) {
|
|
156
164
|
this.ait = ait;
|
|
@@ -207,8 +215,8 @@ export class NxtlinqAIAgent {
|
|
|
207
215
|
permissions,
|
|
208
216
|
issuedBy: hitAddress
|
|
209
217
|
};
|
|
210
|
-
const metadataStr =
|
|
211
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
|
|
218
|
+
const metadataStr = (0, json_stable_stringify_1.default)(metadata);
|
|
219
|
+
const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
|
|
212
220
|
// Upload metadata
|
|
213
221
|
const uploadResponse = await this.api.metadata.createMetadata({
|
|
214
222
|
...metadata,
|
|
@@ -219,8 +227,8 @@ export class NxtlinqAIAgent {
|
|
|
219
227
|
}
|
|
220
228
|
const { metadataCid } = uploadResponse;
|
|
221
229
|
// Sign the message
|
|
222
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
|
|
223
|
-
const signature = await signer.signMessage(ethers.getBytes(messageHash));
|
|
230
|
+
const messageHash = ethers_1.ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
|
|
231
|
+
const signature = await signer.signMessage(ethers_1.ethers.getBytes(messageHash));
|
|
224
232
|
// Register AIT
|
|
225
233
|
const response = await this.api.ait.createAIT({
|
|
226
234
|
aitId,
|
|
@@ -276,7 +284,7 @@ export class NxtlinqAIAgent {
|
|
|
276
284
|
throw new Error('请先连接钱包以访问权限');
|
|
277
285
|
}
|
|
278
286
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
279
|
-
const stringToSign =
|
|
287
|
+
const stringToSign = (0, json_stable_stringify_1.default)({
|
|
280
288
|
message,
|
|
281
289
|
aitId: this.ait.aitId,
|
|
282
290
|
controller: this.ait.controller,
|
|
@@ -299,3 +307,4 @@ export class NxtlinqAIAgent {
|
|
|
299
307
|
};
|
|
300
308
|
}
|
|
301
309
|
}
|
|
310
|
+
exports.NxtlinqAIAgent = NxtlinqAIAgent;
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2020",
|
|
4
|
-
"module": "
|
|
4
|
+
"module": "CommonJS",
|
|
5
5
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"outDir": "dist",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"esModuleInterop": true,
|
|
10
10
|
"skipLibCheck": true,
|
|
11
11
|
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"moduleResolution": "
|
|
12
|
+
"moduleResolution": "node",
|
|
13
13
|
"jsx": "react-jsx",
|
|
14
14
|
"isolatedModules": true,
|
|
15
15
|
"composite": false,
|