@weilliptic/weil-sdk 1.0.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.
- package/README.md +111 -0
- package/dist/contracts.d.ts +19 -0
- package/dist/contracts.js +86 -0
- package/dist/contracts.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.js +2 -0
- package/dist/json.js.map +1 -0
- package/dist/podTypes.d.ts +2 -0
- package/dist/podTypes.js +2 -0
- package/dist/podTypes.js.map +1 -0
- package/dist/pods/selectPod.d.ts +2 -0
- package/dist/pods/selectPod.js +25 -0
- package/dist/pods/selectPod.js.map +1 -0
- package/dist/schema.d.ts +29 -0
- package/dist/schema.js +48 -0
- package/dist/schema.js.map +1 -0
- package/dist/transactions/signature.d.ts +33 -0
- package/dist/transactions/signature.js +10 -0
- package/dist/transactions/signature.js.map +1 -0
- package/dist/types.d.ts +110 -0
- package/dist/utils/common.d.ts +8 -0
- package/dist/utils/common.js +45 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/contract.d.ts +5 -0
- package/dist/utils/contract.js +30 -0
- package/dist/utils/contract.js.map +1 -0
- package/dist/utils/formats.d.ts +6 -0
- package/dist/utils/formats.js +26 -0
- package/dist/utils/formats.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/keys.d.ts +6 -0
- package/dist/utils/keys.js +12 -0
- package/dist/utils/keys.js.map +1 -0
- package/dist/utils/numberToBytes.d.ts +1 -0
- package/dist/utils/numberToBytes.js +15 -0
- package/dist/utils/numberToBytes.js.map +1 -0
- package/dist/utils/utils.test.d.ts +1 -0
- package/dist/utils/utils.test.js +23 -0
- package/dist/utils/utils.test.js.map +1 -0
- package/dist/wallet.d.ts +98 -0
- package/dist/wallet.js +248 -0
- package/dist/wallet.js.map +1 -0
- package/dist/walletCommon.d.ts +66 -0
- package/dist/walletCommon.js +92 -0
- package/dist/walletCommon.js.map +1 -0
- package/dist/walletConnection.d.ts +13 -0
- package/dist/walletConnection.js +31 -0
- package/dist/walletConnection.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isNonSenatePodId, isSenatePodId } from './utils/common.js';
|
|
2
|
+
import { selectPod } from './pods/selectPod.js';
|
|
3
|
+
export class WeilWalletCommon {
|
|
4
|
+
_axiosInstance;
|
|
5
|
+
async getAxiosInstance() {
|
|
6
|
+
return this._axiosInstance;
|
|
7
|
+
}
|
|
8
|
+
podsCache;
|
|
9
|
+
constructor() { }
|
|
10
|
+
async listPods() {
|
|
11
|
+
const response = await (await this.getAxiosInstance()).post('', {
|
|
12
|
+
request_id: '987654321',
|
|
13
|
+
category: 'ClusterManagement',
|
|
14
|
+
request_type: 'GetPodInfo',
|
|
15
|
+
});
|
|
16
|
+
return response.data.result.podDetails;
|
|
17
|
+
}
|
|
18
|
+
async submitTransaction(_params) {
|
|
19
|
+
throw new Error('Method not implemented');
|
|
20
|
+
}
|
|
21
|
+
pods = {
|
|
22
|
+
list: async () => {
|
|
23
|
+
if (!this.podsCache) {
|
|
24
|
+
const pods = await this.listPods();
|
|
25
|
+
const podSortFn = (a, b) => a.counter - b.counter;
|
|
26
|
+
const nodeSortFn = (a, b) => {
|
|
27
|
+
if (a.host === b.host) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
return a.host > b.host ? 1 : -1;
|
|
31
|
+
};
|
|
32
|
+
this.podsCache = pods.toSorted(podSortFn).map(pod => ({
|
|
33
|
+
...pod,
|
|
34
|
+
activeNodes: pod.activeNodes.toSorted(nodeSortFn),
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return [...this.podsCache];
|
|
38
|
+
},
|
|
39
|
+
listNonSenate: async () => {
|
|
40
|
+
return (await this.pods.list()).filter(pod => isNonSenatePodId(pod.podId));
|
|
41
|
+
},
|
|
42
|
+
listSenate: async () => {
|
|
43
|
+
return (await this.pods.list()).filter(pod => isSenatePodId(pod.podId));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
transactions = {
|
|
47
|
+
submit: async (params) => {
|
|
48
|
+
return this.submitTransaction(params);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
contracts = {
|
|
52
|
+
deploy: async (body, widl, { name = null, pods: podsSpecifier = 'default', upgrade = false, logo, author, description, organization, config, context, outcall = false, auditLog = false, }) => {
|
|
53
|
+
const pods = await this.pods.list();
|
|
54
|
+
let targetPods = selectPod(pods.map(pod => pod.podId), podsSpecifier);
|
|
55
|
+
// console.log(`Deploying to pods: ${targetPods.join(', ')}`)
|
|
56
|
+
return await Promise.all(targetPods.map(podId => this.transactions.submit({
|
|
57
|
+
toAddress: '',
|
|
58
|
+
contract: {
|
|
59
|
+
type: 'SmartContractCreator',
|
|
60
|
+
body,
|
|
61
|
+
name,
|
|
62
|
+
pod: podId,
|
|
63
|
+
widl,
|
|
64
|
+
upgrade,
|
|
65
|
+
logo,
|
|
66
|
+
author,
|
|
67
|
+
description,
|
|
68
|
+
organization,
|
|
69
|
+
config,
|
|
70
|
+
context,
|
|
71
|
+
outcall,
|
|
72
|
+
auditLog,
|
|
73
|
+
},
|
|
74
|
+
})));
|
|
75
|
+
},
|
|
76
|
+
execute: (contractAddress, method, params = {}, options = {}) => {
|
|
77
|
+
const toAddress = typeof params.to_addr === 'string' ? params.to_addr : '';
|
|
78
|
+
return this.transactions.submit({
|
|
79
|
+
toAddress,
|
|
80
|
+
contract: {
|
|
81
|
+
address: contractAddress,
|
|
82
|
+
arguments: params || {},
|
|
83
|
+
method,
|
|
84
|
+
type: 'SmartContractExecutor',
|
|
85
|
+
},
|
|
86
|
+
stream: options?.stream,
|
|
87
|
+
headers: options?.headers,
|
|
88
|
+
});
|
|
89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,EAAE,OAAO;aAC1B,CAAQ,CAAA;QACX,CAAC;KACF,CAAA;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WeilWalletProvider } from './types';
|
|
2
|
+
import { SubmitTransactionParams, WeilWalletCommon } from './walletCommon';
|
|
3
|
+
interface WeilWalletConnectionConstructorOptions {
|
|
4
|
+
walletProvider: WeilWalletProvider;
|
|
5
|
+
}
|
|
6
|
+
type WeilWalletConfig = WeilWalletConnectionConstructorOptions;
|
|
7
|
+
export declare class WeilWalletConnection extends WeilWalletCommon {
|
|
8
|
+
config: WeilWalletConfig;
|
|
9
|
+
constructor(options: WeilWalletConnectionConstructorOptions);
|
|
10
|
+
getAxiosInstance(): Promise<import("axios").AxiosInstance>;
|
|
11
|
+
submitTransaction(params: SubmitTransactionParams): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WeilWalletCommon } from './walletCommon.js';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { constructRestEndpoint } from './utils/index.js';
|
|
4
|
+
export class WeilWalletConnection extends WeilWalletCommon {
|
|
5
|
+
config;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super();
|
|
8
|
+
this.config = {
|
|
9
|
+
...options,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async getAxiosInstance() {
|
|
13
|
+
if (!this._axiosInstance) {
|
|
14
|
+
const settings = await this.config.walletProvider.request({
|
|
15
|
+
method: 'wallet_getSettings',
|
|
16
|
+
});
|
|
17
|
+
this._axiosInstance = axios.create({
|
|
18
|
+
baseURL: constructRestEndpoint(settings.sentinelEndpoint),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return this._axiosInstance;
|
|
22
|
+
}
|
|
23
|
+
async submitTransaction(params) {
|
|
24
|
+
const { walletProvider } = this.config;
|
|
25
|
+
return walletProvider.request({
|
|
26
|
+
method: 'weil_sendTransaction',
|
|
27
|
+
params: [params],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=walletConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletConnection.js","sourceRoot":"","sources":["../src/walletConnection.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAQrD,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IACxD,MAAM,CAAkB;IAExB,YAAY,OAA+C;QACzD,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,OAAO;SACX,CAAA;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;gBACxD,MAAM,EAAE,oBAAoB;aAC7B,CAAC,CAAA;YAEF,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC;gBACjC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,gBAAgB,CAAC;aAC1D,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,MAA+B;QACrD,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAEtC,OAAO,cAAc,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE,CAAC,MAAM,CAAC;SACjB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@weilliptic/weil-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"gen:contracts": "tsc && node dist/cli/contracts-gen.js",
|
|
9
|
+
"example": "tsx src/example.js",
|
|
10
|
+
"copy-d-ts": "cp src/types.d.ts dist",
|
|
11
|
+
"prepare": "tsc && npm run copy-d-ts && node helpers/fix-imports.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/*"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.1.0",
|
|
23
|
+
"@types/pako": "^2.0.4",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
25
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
26
|
+
"eslint-config-next": "^16.0.3",
|
|
27
|
+
"eslint-config-prettier": "^10.1.8",
|
|
28
|
+
"eslint-plugin-import": "^2.32.0",
|
|
29
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
30
|
+
"eslint-plugin-react": "^7.37.5",
|
|
31
|
+
"eslint-plugin-security": "^3.0.1",
|
|
32
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
33
|
+
"prettier": "^3.6.2",
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"typescript-transform-paths": "^3.5.5"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@noble/curves": "^2.0.1",
|
|
39
|
+
"@noble/hashes": "^2.0.1",
|
|
40
|
+
"@scure/bip32": "^2.0.1",
|
|
41
|
+
"axios": "^1.13.2",
|
|
42
|
+
"base32-decode": "^1.0.0",
|
|
43
|
+
"base32-encode": "^2.0.0",
|
|
44
|
+
"pako": "^2.1.0",
|
|
45
|
+
"ts-patch": "^3.3.0",
|
|
46
|
+
"zod": "^4.1.12"
|
|
47
|
+
},
|
|
48
|
+
"overrides": {
|
|
49
|
+
"@scure/base": "1.2.1"
|
|
50
|
+
}
|
|
51
|
+
}
|