@sentio/sdk 1.26.4 → 1.27.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/aptos/aptos-processor.d.ts +1 -1
- package/lib/aptos/aptos-processor.js +2 -2
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -1
- package/lib/aptos/index.js +2 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos-codegen/codegen.js +6 -18
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/builtin/aptos/0x1.d.ts +18 -18
- package/lib/builtin/aptos/0x1.js.map +1 -1
- package/lib/builtin/aptos/0x3.d.ts +14 -3
- package/lib/builtin/aptos/0x3.js.map +1 -1
- package/lib/cli/cli.js +3 -3
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/commands/login-server.d.ts +7 -0
- package/lib/cli/commands/login-server.js +134 -0
- package/lib/cli/commands/login-server.js.map +1 -0
- package/lib/cli/commands/run-login.js +77 -27
- package/lib/cli/commands/run-login.js.map +1 -1
- package/lib/cli/config.d.ts +5 -0
- package/lib/cli/config.js +28 -1
- package/lib/cli/config.js.map +1 -1
- package/package.json +7 -2
- package/src/aptos/aptos-processor.ts +2 -2
- package/src/aptos/index.ts +1 -1
- package/src/aptos-codegen/codegen.ts +7 -23
- package/src/builtin/aptos/0x1.ts +19 -18
- package/src/builtin/aptos/0x3.ts +14 -6
- package/src/cli/cli.ts +3 -3
- package/src/cli/commands/login-server.ts +120 -0
- package/src/cli/commands/run-login.ts +59 -28
- package/src/cli/config.ts +29 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.startServer = void 0;
|
30
|
+
const express_1 = __importDefault(require("express"));
|
31
|
+
const config_1 = require("../config");
|
32
|
+
const url_1 = __importStar(require("url"));
|
33
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
34
|
+
const utils_1 = require("../utils");
|
35
|
+
const key_1 = require("../key");
|
36
|
+
const chalk_1 = __importDefault(require("chalk"));
|
37
|
+
const os_1 = __importDefault(require("os"));
|
38
|
+
const crypto = __importStar(require("crypto"));
|
39
|
+
const app = (0, express_1.default)();
|
40
|
+
let server;
|
41
|
+
let authParams;
|
42
|
+
function startServer(params) {
|
43
|
+
authParams = params;
|
44
|
+
server = app.listen(params.serverPort);
|
45
|
+
}
|
46
|
+
exports.startServer = startServer;
|
47
|
+
app.get('/callback', async (req, res) => {
|
48
|
+
res.end('login success, please go back to CLI to continue');
|
49
|
+
const host = authParams.sentioHost;
|
50
|
+
const code = req.query.code;
|
51
|
+
if (!code || code.length == 0) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
// exchange token
|
55
|
+
const tokenResRaw = await getToken(host, code);
|
56
|
+
if (!tokenResRaw.ok) {
|
57
|
+
console.error(chalk_1.default.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText));
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
const tokenRes = await tokenResRaw.json();
|
61
|
+
const accessToken = tokenRes['access_token'];
|
62
|
+
// check if the account is ready
|
63
|
+
const realHost = (0, config_1.getFinalizedHost)(host);
|
64
|
+
const userResRaw = await getUser(realHost, accessToken);
|
65
|
+
if (!userResRaw.ok) {
|
66
|
+
if (userResRaw.status == 401) {
|
67
|
+
console.error(chalk_1.default.red('please sign up on sentio first'));
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
console.error(chalk_1.default.red('get user error, code:', userResRaw.status, userResRaw.statusText));
|
71
|
+
}
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
const userRes = await userResRaw.json();
|
75
|
+
if (!userRes.emailVerified) {
|
76
|
+
console.error(chalk_1.default.red('please verify your email first'));
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
// create API key
|
80
|
+
const apiKeyName = `${os_1.default.hostname()}-${crypto.randomBytes(4).toString('hex')}`;
|
81
|
+
const createApiKeyResRaw = await createApiKey(realHost, apiKeyName, 'sdk_generated', accessToken);
|
82
|
+
if (!createApiKeyResRaw.ok) {
|
83
|
+
console.error(chalk_1.default.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText));
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
const createApiKeyRes = await createApiKeyResRaw.json();
|
87
|
+
const apiKey = createApiKeyRes['key'];
|
88
|
+
(0, key_1.WriteKey)(realHost, apiKey);
|
89
|
+
console.log(chalk_1.default.green('login success, new API key: ' + apiKey));
|
90
|
+
server.close();
|
91
|
+
});
|
92
|
+
async function getToken(host, code) {
|
93
|
+
const authConf = (0, config_1.getAuthConfig)(host);
|
94
|
+
const params = new url_1.default.URLSearchParams({
|
95
|
+
grant_type: 'authorization_code',
|
96
|
+
client_id: authConf.clientId,
|
97
|
+
code_verifier: authParams.codeVerifier,
|
98
|
+
code: code,
|
99
|
+
redirect_uri: `http://localhost:${authParams.serverPort}/callback`,
|
100
|
+
});
|
101
|
+
return (0, node_fetch_1.default)(`${authConf.domain}/oauth/token`, {
|
102
|
+
method: 'POST',
|
103
|
+
headers: {
|
104
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
105
|
+
},
|
106
|
+
body: params.toString(),
|
107
|
+
});
|
108
|
+
}
|
109
|
+
async function createApiKey(host, name, source, accessToken) {
|
110
|
+
const createApiKeyUrl = new url_1.URL('/api/v1/keys', host);
|
111
|
+
return (0, node_fetch_1.default)(createApiKeyUrl, {
|
112
|
+
method: 'POST',
|
113
|
+
headers: {
|
114
|
+
Authorization: 'Bearer ' + accessToken,
|
115
|
+
version: (0, utils_1.getCliVersion)(),
|
116
|
+
},
|
117
|
+
body: JSON.stringify({
|
118
|
+
name: name,
|
119
|
+
scopes: ['write:project'],
|
120
|
+
source: source,
|
121
|
+
}),
|
122
|
+
});
|
123
|
+
}
|
124
|
+
async function getUser(host, accessToken) {
|
125
|
+
const getUserUrl = new url_1.URL('/api/v1/users', host);
|
126
|
+
return (0, node_fetch_1.default)(getUserUrl, {
|
127
|
+
method: 'GET',
|
128
|
+
headers: {
|
129
|
+
Authorization: 'Bearer ' + accessToken,
|
130
|
+
version: (0, utils_1.getCliVersion)(),
|
131
|
+
},
|
132
|
+
});
|
133
|
+
}
|
134
|
+
//# sourceMappingURL=login-server.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../../src/cli/commands/login-server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA6B;AAC7B,sCAA2D;AAC3D,2CAA8B;AAC9B,4DAA8B;AAC9B,oCAAwC;AACxC,gCAAiC;AACjC,kDAAyB;AAEzB,4CAAmB;AACnB,+CAAg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AE;YACP,aAAa,EAAE,SAAS,GAAG,WAAW;YACtC,OAAO,EAAE,IAAA,qBAAa,GAAE;SACzB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import express from 'express'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport url, { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from '../utils'\nimport { WriteKey } from '../key'\nimport chalk from 'chalk'\nimport http from 'http'\nimport os from 'os'\nimport * as crypto from 'crypto'\n\ninterface AuthParams {\n serverPort: number\n sentioHost: string\n codeVerifier: string\n}\n\nconst app = express()\n\nlet server: http.Server\nlet authParams: AuthParams\n\nexport function startServer(params: AuthParams) {\n authParams = params\n server = app.listen(params.serverPort)\n}\n\napp.get('/callback', async (req, res) => {\n res.end('login success, please go back to CLI to continue')\n const host = authParams.sentioHost\n const code = req.query.code\n if (!code || (code as string).length == 0) {\n return\n }\n\n // exchange token\n const tokenResRaw = await getToken(host, code as string)\n if (!tokenResRaw.ok) {\n console.error(chalk.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText))\n return\n }\n const tokenRes = await tokenResRaw.json()\n const accessToken = tokenRes['access_token']\n\n // check if the account is ready\n const realHost = getFinalizedHost(host)\n const userResRaw = await getUser(realHost, accessToken)\n if (!userResRaw.ok) {\n if (userResRaw.status == 401) {\n console.error(chalk.red('please sign up on sentio first'))\n } else {\n console.error(chalk.red('get user error, code:', userResRaw.status, userResRaw.statusText))\n }\n return\n }\n const userRes = await userResRaw.json()\n if (!userRes.emailVerified) {\n console.error(chalk.red('please verify your email first'))\n return\n }\n\n // create API key\n const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`\n const createApiKeyResRaw = await createApiKey(realHost, apiKeyName, 'sdk_generated', accessToken)\n if (!createApiKeyResRaw.ok) {\n console.error(chalk.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText))\n return\n }\n const createApiKeyRes = await createApiKeyResRaw.json()\n const apiKey = createApiKeyRes['key']\n WriteKey(realHost, apiKey)\n console.log(chalk.green('login success, new API key: ' + apiKey))\n\n server.close()\n})\n\nasync function getToken(host: string, code: string) {\n const authConf = getAuthConfig(host)\n const params = new url.URLSearchParams({\n grant_type: 'authorization_code',\n client_id: authConf.clientId,\n code_verifier: authParams.codeVerifier,\n code: code,\n redirect_uri: `http://localhost:${authParams.serverPort}/callback`,\n })\n return fetch(`${authConf.domain}/oauth/token`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: params.toString(),\n })\n}\n\nasync function createApiKey(host: string, name: string, source: string, accessToken: string) {\n const createApiKeyUrl = new URL('/api/v1/keys', host)\n return fetch(createApiKeyUrl, {\n method: 'POST',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n body: JSON.stringify({\n name: name,\n scopes: ['write:project'],\n source: source,\n }),\n })\n}\n\nasync function getUser(host: string, accessToken: string) {\n const getUserUrl = new URL('/api/v1/users', host)\n return fetch(getUserUrl, {\n method: 'GET',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n })\n}\n"]}
|
@@ -1,4 +1,27 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
27
|
};
|
@@ -7,10 +30,13 @@ exports.runLogin = void 0;
|
|
7
30
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
8
31
|
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
9
32
|
const config_1 = require("../config");
|
33
|
+
const login_server_1 = require("./login-server");
|
34
|
+
const url_1 = __importStar(require("url"));
|
35
|
+
const crypto = __importStar(require("crypto"));
|
10
36
|
const chalk_1 = __importDefault(require("chalk"));
|
11
|
-
const https_1 = __importDefault(require("https"));
|
12
|
-
const http_1 = __importDefault(require("http"));
|
13
37
|
const key_1 = require("../key");
|
38
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
39
|
+
const port = 20000;
|
14
40
|
function runLogin(argv) {
|
15
41
|
const optionDefinitions = [
|
16
42
|
{
|
@@ -20,22 +46,22 @@ function runLogin(argv) {
|
|
20
46
|
description: 'Display this usage guide.',
|
21
47
|
},
|
22
48
|
{
|
23
|
-
name: '
|
49
|
+
name: 'host',
|
50
|
+
description: '(Optional) Override Sentio Host name',
|
24
51
|
type: String,
|
25
|
-
description: '(Required) Your API key',
|
26
52
|
},
|
27
53
|
{
|
28
|
-
name: '
|
29
|
-
description: '(Optional) Override Sentio Host name',
|
54
|
+
name: 'api-key',
|
30
55
|
type: String,
|
56
|
+
description: '(Optional) Your API key',
|
31
57
|
},
|
32
58
|
];
|
33
59
|
const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
|
34
|
-
if (options.help
|
60
|
+
if (options.help) {
|
35
61
|
const usage = (0, command_line_usage_1.default)([
|
36
62
|
{
|
37
63
|
header: 'Login to Sentio',
|
38
|
-
content: 'sentio login
|
64
|
+
content: 'sentio login',
|
39
65
|
},
|
40
66
|
{
|
41
67
|
header: 'Options',
|
@@ -44,34 +70,58 @@ function runLogin(argv) {
|
|
44
70
|
]);
|
45
71
|
console.log(usage);
|
46
72
|
}
|
47
|
-
else {
|
73
|
+
else if (options['api-key']) {
|
48
74
|
const host = (0, config_1.getFinalizedHost)(options.host);
|
49
75
|
console.log(chalk_1.default.blue('login to ' + host));
|
50
|
-
const
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
path: '/api/v1/processors/check_key',
|
55
|
-
method: 'HEAD',
|
56
|
-
headers: {
|
57
|
-
'api-key': options['api-key'],
|
58
|
-
},
|
59
|
-
};
|
60
|
-
const h = url.protocol == 'https:' ? https_1.default : http_1.default;
|
61
|
-
const req = h.request(reqOptions, (res) => {
|
62
|
-
if (res.statusCode == 200) {
|
63
|
-
(0, key_1.WriteKey)(host, options['api-key']);
|
76
|
+
const apiKey = options['api-key'];
|
77
|
+
checkKey(host, apiKey).then((res) => {
|
78
|
+
if (res.status == 200) {
|
79
|
+
(0, key_1.WriteKey)(host, apiKey);
|
64
80
|
console.log(chalk_1.default.green('login success'));
|
65
81
|
}
|
66
82
|
else {
|
67
|
-
console.error(chalk_1.default.red('login failed, code:', res.
|
83
|
+
console.error(chalk_1.default.red('login failed, code:', res.status, res.statusText));
|
68
84
|
}
|
69
85
|
});
|
70
|
-
|
71
|
-
|
86
|
+
}
|
87
|
+
else {
|
88
|
+
// https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce
|
89
|
+
const verifier = base64URLEncode(crypto.randomBytes(32));
|
90
|
+
const challenge = base64URLEncode(sha256(verifier));
|
91
|
+
const conf = (0, config_1.getAuthConfig)(options.host);
|
92
|
+
const authURL = new url_1.URL(conf.domain + `/authorize?`);
|
93
|
+
const params = new url_1.default.URLSearchParams({
|
94
|
+
response_type: 'code',
|
95
|
+
code_challenge: challenge,
|
96
|
+
code_challenge_method: 'S256',
|
97
|
+
client_id: conf.clientId,
|
98
|
+
redirect_uri: `http://localhost:${port}/callback`,
|
99
|
+
audience: conf.audience,
|
100
|
+
prompt: 'login',
|
101
|
+
});
|
102
|
+
authURL.search = params.toString();
|
103
|
+
console.log('Continue your authorization here: ' + authURL.toString());
|
104
|
+
(0, login_server_1.startServer)({
|
105
|
+
serverPort: port,
|
106
|
+
sentioHost: options.host,
|
107
|
+
codeVerifier: verifier,
|
72
108
|
});
|
73
|
-
req.end();
|
74
109
|
}
|
75
110
|
}
|
76
111
|
exports.runLogin = runLogin;
|
112
|
+
function base64URLEncode(str) {
|
113
|
+
return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
114
|
+
}
|
115
|
+
function sha256(str) {
|
116
|
+
return crypto.createHash('sha256').update(str).digest();
|
117
|
+
}
|
118
|
+
async function checkKey(host, apiKey) {
|
119
|
+
const checkApiKeyUrl = new url_1.URL('/api/v1/processors/check_key', host);
|
120
|
+
return (0, node_fetch_1.default)(checkApiKeyUrl, {
|
121
|
+
method: 'HEAD',
|
122
|
+
headers: {
|
123
|
+
'api-key': apiKey,
|
124
|
+
},
|
125
|
+
});
|
126
|
+
}
|
77
127
|
//# sourceMappingURL=run-login.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run-login.js","sourceRoot":"","sources":["../../../src/cli/commands/run-login.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"run-login.js","sourceRoot":"","sources":["../../../src/cli/commands/run-login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,sCAA2D;AAC3D,iDAA4C;AAC5C,2CAA8B;AAC9B,+CAAgC;AAChC,kDAAyB;AACzB,gCAAiC;AACjC,4D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AAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACzF,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAA;AACzD,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAc;IAClD,MAAM,cAAc,GAAG,IAAI,SAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAA;IACpE,OAAO,IAAA,oBAAK,EAAC,cAAc,EAAE;QAC3B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport { startServer } from './login-server'\nimport url, { URL } from 'url'\nimport * as crypto from 'crypto'\nimport chalk from 'chalk'\nimport { WriteKey } from '../key'\nimport fetch from 'node-fetch'\n\nconst port = 20000\n\nexport function runLogin(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Your API key',\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Login to Sentio',\n content: 'sentio login',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else if (options['api-key']) {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const apiKey = options['api-key']\n checkKey(host, apiKey).then((res) => {\n if (res.status == 200) {\n WriteKey(host, apiKey)\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.status, res.statusText))\n }\n })\n } else {\n // https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce\n const verifier = base64URLEncode(crypto.randomBytes(32))\n const challenge = base64URLEncode(sha256(verifier))\n\n const conf = getAuthConfig(options.host)\n const authURL = new URL(conf.domain + `/authorize?`)\n const params = new url.URLSearchParams({\n response_type: 'code',\n code_challenge: challenge,\n code_challenge_method: 'S256',\n client_id: conf.clientId,\n redirect_uri: `http://localhost:${port}/callback`,\n audience: conf.audience,\n prompt: 'login',\n })\n authURL.search = params.toString()\n console.log('Continue your authorization here: ' + authURL.toString())\n\n startServer({\n serverPort: port,\n sentioHost: options.host,\n codeVerifier: verifier,\n })\n }\n}\n\nfunction base64URLEncode(str: Buffer) {\n return str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n}\n\nfunction sha256(str: string) {\n return crypto.createHash('sha256').update(str).digest()\n}\n\nasync function checkKey(host: string, apiKey: string) {\n const checkApiKeyUrl = new URL('/api/v1/processors/check_key', host)\n return fetch(checkApiKeyUrl, {\n method: 'HEAD',\n headers: {\n 'api-key': apiKey,\n },\n })\n}\n"]}
|
package/lib/cli/config.d.ts
CHANGED
@@ -4,5 +4,10 @@ export interface SentioProjectConfig {
|
|
4
4
|
build: boolean;
|
5
5
|
}
|
6
6
|
export declare function getFinalizedHost(host: string): string;
|
7
|
+
export declare function getAuthConfig(host: string): {
|
8
|
+
domain: string;
|
9
|
+
clientId: string;
|
10
|
+
audience: string;
|
11
|
+
};
|
7
12
|
export declare function finalizeHost(config: SentioProjectConfig): void;
|
8
13
|
export declare function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined): void;
|
package/lib/cli/config.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FinalizeProjectName = exports.finalizeHost = exports.getFinalizedHost = void 0;
|
3
|
+
exports.FinalizeProjectName = exports.finalizeHost = exports.getAuthConfig = exports.getFinalizedHost = void 0;
|
4
4
|
function getFinalizedHost(host) {
|
5
5
|
switch (host) {
|
6
6
|
case undefined:
|
@@ -17,6 +17,33 @@ function getFinalizedHost(host) {
|
|
17
17
|
return host;
|
18
18
|
}
|
19
19
|
exports.getFinalizedHost = getFinalizedHost;
|
20
|
+
function getAuthConfig(host) {
|
21
|
+
let domain = '', clientId = '', audience = '';
|
22
|
+
switch (host) {
|
23
|
+
case 'local':
|
24
|
+
domain = 'https://sentio-dev.us.auth0.com';
|
25
|
+
clientId = 'qGDisObqQbcPeRA8k02POPZ2Df4KVCna';
|
26
|
+
audience = 'http://localhost:8080/v1';
|
27
|
+
break;
|
28
|
+
case '':
|
29
|
+
case undefined:
|
30
|
+
case 'prod':
|
31
|
+
domain = 'https://auth.sentio.xyz';
|
32
|
+
clientId = 'xd80PeuvuZVHpBFh7yEdlSZdtE5mTpGe';
|
33
|
+
audience = 'https://app.sentio.xyz/api/v1';
|
34
|
+
break;
|
35
|
+
case 'test':
|
36
|
+
case 'staging':
|
37
|
+
domain = 'https://auth.test.sentio.xyz';
|
38
|
+
clientId = 'qXVvovHaOE37SndxTZJxCKgZjw1axPax';
|
39
|
+
audience = 'https://test.sentio.xyz/api/v1';
|
40
|
+
break;
|
41
|
+
default:
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
return { domain, clientId, audience };
|
45
|
+
}
|
46
|
+
exports.getAuthConfig = getAuthConfig;
|
20
47
|
function finalizeHost(config) {
|
21
48
|
config.host = getFinalizedHost(config.host);
|
22
49
|
}
|
package/lib/cli/config.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,SAAS,CAAC;QACf,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,OAAO,wBAAwB,CAAA;QACjC,KAAK,MAAM;YACT,OAAO,yBAAyB,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,4BAA4B,CAAA;QACrC,KAAK,OAAO;YACV,OAAO,wBAAwB,CAAA;KAClC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAdD,4CAcC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAED,4BAA4B;AAC5B,kBAAkB;AAClB,qBAAqB;AACrB,IAAI;AACJ,EAAE;AACF,wCAAwC;AACxC,2BAA2B;AAC3B,iCAAiC","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n // source: string\n build: boolean\n // targets: Target[]\n}\n\nexport function getFinalizedHost(host: string): string {\n switch (host) {\n case undefined:\n case '':\n case 'prod':\n return 'https://app.sentio.xyz'\n case 'test':\n return 'https://test.sentio.xyz'\n case 'staging':\n return 'https://staging.sentio.xyz'\n case 'local':\n return 'http://localhost:10000'\n }\n return host\n}\n\nexport function finalizeHost(config: SentioProjectConfig) {\n config.host = getFinalizedHost(config.host)\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\n// export interface Target {\n// chain: string\n// abisDir?: string\n// }\n//\n// // Supported target chain, lower case\n// export const EVM = 'evm'\n// export const SOLANA = 'solana'\n"]}
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,SAAS,CAAC;QACf,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,OAAO,wBAAwB,CAAA;QACjC,KAAK,MAAM;YACT,OAAO,yBAAyB,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,4BAA4B,CAAA;QACrC,KAAK,OAAO;YACV,OAAO,wBAAwB,CAAA;KAClC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAdD,4CAcC;AAED,SAAgB,aAAa,CAAC,IAAY;IACxC,IAAI,MAAM,GAAG,EAAE,EACb,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,EAAE,CAAA;IACf,QAAQ,IAAI,EAAE;QACZ,KAAK,OAAO;YACV,MAAM,GAAG,iCAAiC,CAAA;YAC1C,QAAQ,GAAG,kCAAkC,CAAA;YAC7C,QAAQ,GAAG,0BAA0B,CAAA;YACrC,MAAK;QACP,KAAK,EAAE,CAAC;QACR,KAAK,SAAS,CAAC;QACf,KAAK,MAAM;YACT,MAAM,GAAG,yBAAyB,CAAA;YAClC,QAAQ,GAAG,kCAAkC,CAAA;YAC7C,QAAQ,GAAG,+BAA+B,CAAA;YAC1C,MAAK;QACP,KAAK,MAAM,CAAC;QACZ,KAAK,SAAS;YACZ,MAAM,GAAG,8BAA8B,CAAA;YACvC,QAAQ,GAAG,kCAAkC,CAAA;YAC7C,QAAQ,GAAG,gCAAgC,CAAA;YAC3C,MAAK;QACP;YACE,MAAK;KACR;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA;AACvC,CAAC;AA3BD,sCA2BC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAED,4BAA4B;AAC5B,kBAAkB;AAClB,qBAAqB;AACrB,IAAI;AACJ,EAAE;AACF,wCAAwC;AACxC,2BAA2B;AAC3B,iCAAiC","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n // source: string\n build: boolean\n // targets: Target[]\n}\n\nexport function getFinalizedHost(host: string): string {\n switch (host) {\n case undefined:\n case '':\n case 'prod':\n return 'https://app.sentio.xyz'\n case 'test':\n return 'https://test.sentio.xyz'\n case 'staging':\n return 'https://staging.sentio.xyz'\n case 'local':\n return 'http://localhost:10000'\n }\n return host\n}\n\nexport function getAuthConfig(host: string): { domain: string; clientId: string; audience: string } {\n let domain = '',\n clientId = '',\n audience = ''\n switch (host) {\n case 'local':\n domain = 'https://sentio-dev.us.auth0.com'\n clientId = 'qGDisObqQbcPeRA8k02POPZ2Df4KVCna'\n audience = 'http://localhost:8080/v1'\n break\n case '':\n case undefined:\n case 'prod':\n domain = 'https://auth.sentio.xyz'\n clientId = 'xd80PeuvuZVHpBFh7yEdlSZdtE5mTpGe'\n audience = 'https://app.sentio.xyz/api/v1'\n break\n case 'test':\n case 'staging':\n domain = 'https://auth.test.sentio.xyz'\n clientId = 'qXVvovHaOE37SndxTZJxCKgZjw1axPax'\n audience = 'https://test.sentio.xyz/api/v1'\n break\n default:\n break\n }\n return { domain, clientId, audience }\n}\n\nexport function finalizeHost(config: SentioProjectConfig) {\n config.host = getFinalizedHost(config.host)\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\n// export interface Target {\n// chain: string\n// abisDir?: string\n// }\n//\n// // Supported target chain, lower case\n// export const EVM = 'evm'\n// export const SOLANA = 'solana'\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.27.1",
|
5
5
|
"scripts": {
|
6
6
|
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
|
7
7
|
"compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli && cp src/utils/*.csv lib/utils",
|
@@ -25,6 +25,7 @@
|
|
25
25
|
"@solana/web3.js": "^1.47.3",
|
26
26
|
"@typechain/ethers-v5": "^10.0.0",
|
27
27
|
"@types/bn.js": "^5.1.0",
|
28
|
+
"@types/express": "^4.17.14",
|
28
29
|
"@types/node-fetch": "^2.6.2",
|
29
30
|
"aptos-sdk": "npm:aptos@^1.3.16",
|
30
31
|
"bignumber.js": "^9.1.0",
|
@@ -34,6 +35,7 @@
|
|
34
35
|
"command-line-usage": "^6.1.3",
|
35
36
|
"csv-parse": "^5.3.0",
|
36
37
|
"ethers": "~5.7.1",
|
38
|
+
"express": "^4.18.2",
|
37
39
|
"form-data": "^4.0.0",
|
38
40
|
"fs-extra": "^10.1.0",
|
39
41
|
"google-protobuf": "^3.15.8",
|
@@ -78,5 +80,8 @@
|
|
78
80
|
"lib/**/*",
|
79
81
|
"src/**/*",
|
80
82
|
"templates/**/*"
|
81
|
-
]
|
83
|
+
],
|
84
|
+
"engines": {
|
85
|
+
"node": ">=16"
|
86
|
+
}
|
82
87
|
}
|
@@ -251,9 +251,9 @@ export class AptosAccountProcessor {
|
|
251
251
|
public onTimeInterval(
|
252
252
|
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
253
253
|
timeIntervalInMinutes = 60,
|
254
|
-
|
254
|
+
type?: string
|
255
255
|
) {
|
256
|
-
return this.onInterval(handler, timeIntervalInMinutes, undefined,
|
256
|
+
return this.onInterval(handler, timeIntervalInMinutes, undefined, type)
|
257
257
|
}
|
258
258
|
|
259
259
|
public onVersionInterval(
|
package/src/aptos/index.ts
CHANGED
@@ -3,5 +3,5 @@ export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload } fro
|
|
3
3
|
export { TYPE_REGISTRY, TypeRegistry } from './types'
|
4
4
|
export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'
|
5
5
|
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'
|
6
|
-
export { AptosContext } from './context'
|
6
|
+
export { AptosContext, AptosResourceContext } from './context'
|
7
7
|
export { AptosBindOptions, AptosNetwork, getRpcClient } from './network'
|
@@ -56,7 +56,7 @@ export async function generateForNetwork(srcDir: string, outputDir: string, netw
|
|
56
56
|
|
57
57
|
while (loader.pendingAccounts.size > 0) {
|
58
58
|
for (const account of loader.pendingAccounts) {
|
59
|
-
console.log(`download
|
59
|
+
console.log(`download dependent module for account ${account} at ${getChainName(network)}`)
|
60
60
|
|
61
61
|
try {
|
62
62
|
const modules = await client.getAccountModules(account)
|
@@ -326,7 +326,12 @@ function generateCallArgsStructs(module: MoveModule, func: MoveFunction) {
|
|
326
326
|
|
327
327
|
// the first param is always signer so ignore
|
328
328
|
// TODO check if there is any edge case
|
329
|
-
|
329
|
+
let params = func.params
|
330
|
+
if (func.params[0] === '&signer') {
|
331
|
+
params = params.slice(1)
|
332
|
+
}
|
333
|
+
|
334
|
+
const fields = params.map((param) => {
|
330
335
|
return `${generateType(param)}`
|
331
336
|
})
|
332
337
|
|
@@ -387,27 +392,6 @@ function getEventStructs(module: MoveModule) {
|
|
387
392
|
return eventMap
|
388
393
|
}
|
389
394
|
|
390
|
-
function isEvent(struct: MoveStruct, module: MoveModule) {
|
391
|
-
const hasAbility = struct.abilities.includes('drop') && struct.abilities.includes('store')
|
392
|
-
|
393
|
-
if (!hasAbility) {
|
394
|
-
return false
|
395
|
-
}
|
396
|
-
if (struct.name.endsWith('Event')) {
|
397
|
-
return true
|
398
|
-
}
|
399
|
-
|
400
|
-
// for (const struct of module.structs) {
|
401
|
-
// for (const field of struct.fields) {
|
402
|
-
// if (field.type.startsWith('0x1::event::EventHandle')
|
403
|
-
// }
|
404
|
-
// }
|
405
|
-
|
406
|
-
return false
|
407
|
-
|
408
|
-
//&&
|
409
|
-
}
|
410
|
-
|
411
395
|
function generateOnEvents(module: MoveModule, struct: MoveStruct): string {
|
412
396
|
// for struct that has drop + store
|
413
397
|
// if (!isEvent(struct, module)) {
|
package/src/builtin/aptos/0x1.ts
CHANGED
@@ -282,8 +282,8 @@ export namespace coin {
|
|
282
282
|
}
|
283
283
|
|
284
284
|
export interface FreezeCoinStorePayload
|
285
|
-
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
286
|
-
arguments_typed: [Address];
|
285
|
+
extends aptos.TypedEntryFunctionPayload<[Address, Address]> {
|
286
|
+
arguments_typed: [Address, Address];
|
287
287
|
type_arguments: [string];
|
288
288
|
}
|
289
289
|
|
@@ -294,8 +294,8 @@ export namespace coin {
|
|
294
294
|
}
|
295
295
|
|
296
296
|
export interface UnfreezeCoinStorePayload
|
297
|
-
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
298
|
-
arguments_typed: [Address];
|
297
|
+
extends aptos.TypedEntryFunctionPayload<[Address, Address]> {
|
298
|
+
arguments_typed: [Address, Address];
|
299
299
|
type_arguments: [string];
|
300
300
|
}
|
301
301
|
|
@@ -2163,8 +2163,8 @@ export namespace vesting {
|
|
2163
2163
|
}
|
2164
2164
|
|
2165
2165
|
export interface DistributePayload
|
2166
|
-
extends aptos.TypedEntryFunctionPayload<[]> {
|
2167
|
-
arguments_typed: [];
|
2166
|
+
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
2167
|
+
arguments_typed: [Address];
|
2168
2168
|
type_arguments: [];
|
2169
2169
|
}
|
2170
2170
|
|
@@ -2205,8 +2205,8 @@ export namespace vesting {
|
|
2205
2205
|
}
|
2206
2206
|
|
2207
2207
|
export interface UnlockRewardsPayload
|
2208
|
-
extends aptos.TypedEntryFunctionPayload<[]> {
|
2209
|
-
arguments_typed: [];
|
2208
|
+
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
2209
|
+
arguments_typed: [Address];
|
2210
2210
|
type_arguments: [];
|
2211
2211
|
}
|
2212
2212
|
|
@@ -2228,8 +2228,9 @@ export namespace vesting {
|
|
2228
2228
|
type_arguments: [];
|
2229
2229
|
}
|
2230
2230
|
|
2231
|
-
export interface VestPayload
|
2232
|
-
|
2231
|
+
export interface VestPayload
|
2232
|
+
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
2233
|
+
arguments_typed: [Address];
|
2233
2234
|
type_arguments: [];
|
2234
2235
|
}
|
2235
2236
|
|
@@ -2486,8 +2487,8 @@ export namespace aptos_coin {
|
|
2486
2487
|
}
|
2487
2488
|
|
2488
2489
|
export interface DelegateMintCapabilityPayload
|
2489
|
-
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
2490
|
-
arguments_typed: [Address];
|
2490
|
+
extends aptos.TypedEntryFunctionPayload<[Address, Address]> {
|
2491
|
+
arguments_typed: [Address, Address];
|
2491
2492
|
type_arguments: [];
|
2492
2493
|
}
|
2493
2494
|
|
@@ -2869,8 +2870,8 @@ export class aptos_account extends aptos.AptosBaseProcessor {
|
|
2869
2870
|
|
2870
2871
|
export namespace aptos_account {
|
2871
2872
|
export interface CreateAccountPayload
|
2872
|
-
extends aptos.TypedEntryFunctionPayload<[]> {
|
2873
|
-
arguments_typed: [];
|
2873
|
+
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
2874
|
+
arguments_typed: [Address];
|
2874
2875
|
type_arguments: [];
|
2875
2876
|
}
|
2876
2877
|
|
@@ -3414,8 +3415,8 @@ export namespace aptos_governance {
|
|
3414
3415
|
}
|
3415
3416
|
|
3416
3417
|
export interface AddApprovedScriptHashScriptPayload
|
3417
|
-
extends aptos.TypedEntryFunctionPayload<[]> {
|
3418
|
-
arguments_typed: [];
|
3418
|
+
extends aptos.TypedEntryFunctionPayload<[bigint]> {
|
3419
|
+
arguments_typed: [bigint];
|
3419
3420
|
type_arguments: [];
|
3420
3421
|
}
|
3421
3422
|
|
@@ -3982,8 +3983,8 @@ export namespace staking_contract {
|
|
3982
3983
|
}
|
3983
3984
|
|
3984
3985
|
export interface DistributePayload
|
3985
|
-
extends aptos.TypedEntryFunctionPayload<[Address]> {
|
3986
|
-
arguments_typed: [Address];
|
3986
|
+
extends aptos.TypedEntryFunctionPayload<[Address, Address]> {
|
3987
|
+
arguments_typed: [Address, Address];
|
3987
3988
|
type_arguments: [];
|
3988
3989
|
}
|
3989
3990
|
|
package/src/builtin/aptos/0x3.ts
CHANGED
@@ -837,25 +837,33 @@ export namespace token_transfers {
|
|
837
837
|
|
838
838
|
export interface CancelOfferScriptPayload
|
839
839
|
extends aptos.TypedEntryFunctionPayload<
|
840
|
-
[Address, Address, string, string, bigint]
|
840
|
+
[Address, Address, Address, string, string, bigint]
|
841
841
|
> {
|
842
|
-
arguments_typed: [Address, Address, string, string, bigint];
|
842
|
+
arguments_typed: [Address, Address, Address, string, string, bigint];
|
843
843
|
type_arguments: [];
|
844
844
|
}
|
845
845
|
|
846
846
|
export interface ClaimScriptPayload
|
847
847
|
extends aptos.TypedEntryFunctionPayload<
|
848
|
-
[Address, Address, string, string, bigint]
|
848
|
+
[Address, Address, Address, string, string, bigint]
|
849
849
|
> {
|
850
|
-
arguments_typed: [Address, Address, string, string, bigint];
|
850
|
+
arguments_typed: [Address, Address, Address, string, string, bigint];
|
851
851
|
type_arguments: [];
|
852
852
|
}
|
853
853
|
|
854
854
|
export interface OfferScriptPayload
|
855
855
|
extends aptos.TypedEntryFunctionPayload<
|
856
|
-
[Address, Address, string, string, bigint, bigint]
|
856
|
+
[Address, Address, Address, string, string, bigint, bigint]
|
857
857
|
> {
|
858
|
-
arguments_typed: [
|
858
|
+
arguments_typed: [
|
859
|
+
Address,
|
860
|
+
Address,
|
861
|
+
Address,
|
862
|
+
string,
|
863
|
+
string,
|
864
|
+
bigint,
|
865
|
+
bigint
|
866
|
+
];
|
859
867
|
type_arguments: [];
|
860
868
|
}
|
861
869
|
|