@tychilabs/stonfi-gasless-sdk 0.0.1 → 0.0.2
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
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
DEFAULT_CONFIG: () => DEFAULT_CONFIG,
|
|
34
|
+
GasLimitExceededError: () => GasLimitExceededError,
|
|
35
|
+
InsufficientBalanceError: () => InsufficientBalanceError,
|
|
36
|
+
InvalidChainError: () => InvalidChainError,
|
|
37
|
+
InvalidPaymentCoinError: () => InvalidPaymentCoinError,
|
|
38
|
+
InvalidSignatureError: () => InvalidSignatureError,
|
|
39
|
+
MissingDigestError: () => MissingDigestError,
|
|
40
|
+
NetworkError: () => NetworkError,
|
|
41
|
+
PayerMismatchError: () => PayerMismatchError,
|
|
42
|
+
QuoteExpiredError: () => QuoteExpiredError,
|
|
43
|
+
QuoteNotFoundError: () => QuoteNotFoundError,
|
|
44
|
+
StatusNotFoundError: () => StatusNotFoundError,
|
|
45
|
+
UGFClient: () => UGFClient,
|
|
46
|
+
UGFError: () => UGFError,
|
|
47
|
+
UnauthorizedError: () => UnauthorizedError,
|
|
48
|
+
formatSTON: () => formatSTON,
|
|
49
|
+
fromNano: () => fromNano,
|
|
50
|
+
isValidBufferPct: () => isValidBufferPct,
|
|
51
|
+
isValidGasEstimate: () => isValidGasEstimate,
|
|
52
|
+
isValidHex: () => isValidHex,
|
|
53
|
+
isValidTONAddress: () => isValidTONAddress,
|
|
54
|
+
parseBackendError: () => parseBackendError,
|
|
55
|
+
signDigest: () => signDigest,
|
|
56
|
+
toNano: () => toNano,
|
|
57
|
+
verifySignature: () => verifySignature
|
|
58
|
+
});
|
|
59
|
+
module.exports = __toCommonJS(index_exports);
|
|
60
|
+
|
|
1
61
|
// src/utils/errors.ts
|
|
2
62
|
var UGFError = class extends Error {
|
|
3
63
|
constructor(message, code) {
|
|
@@ -236,10 +296,10 @@ function formatSTON(amount, decimals = 2) {
|
|
|
236
296
|
}
|
|
237
297
|
|
|
238
298
|
// src/utils/validation.ts
|
|
239
|
-
|
|
299
|
+
var import_core = require("@ton/core");
|
|
240
300
|
function isValidTONAddress(address) {
|
|
241
301
|
try {
|
|
242
|
-
Address.parse(address);
|
|
302
|
+
import_core.Address.parse(address);
|
|
243
303
|
return true;
|
|
244
304
|
} catch {
|
|
245
305
|
return false;
|
|
@@ -256,18 +316,18 @@ function isValidBufferPct(pct) {
|
|
|
256
316
|
}
|
|
257
317
|
|
|
258
318
|
// src/crypto/signature.ts
|
|
259
|
-
|
|
319
|
+
var import_tweetnacl = __toESM(require("tweetnacl"));
|
|
260
320
|
function signDigest(digestHex, privateKeyHex) {
|
|
261
321
|
const digest = hexToBytes(digestHex);
|
|
262
322
|
const secretKey = hexToBytes(privateKeyHex);
|
|
263
|
-
const signature =
|
|
323
|
+
const signature = import_tweetnacl.default.sign.detached(digest, secretKey);
|
|
264
324
|
return bytesToHex(signature);
|
|
265
325
|
}
|
|
266
326
|
function verifySignature(digestHex, signatureHex, publicKeyHex) {
|
|
267
327
|
const digest = hexToBytes(digestHex);
|
|
268
328
|
const signature = hexToBytes(signatureHex);
|
|
269
329
|
const publicKey = hexToBytes(publicKeyHex);
|
|
270
|
-
return
|
|
330
|
+
return import_tweetnacl.default.sign.detached.verify(digest, signature, publicKey);
|
|
271
331
|
}
|
|
272
332
|
function hexToBytes(hex) {
|
|
273
333
|
const bytes = new Uint8Array(hex.length / 2);
|
|
@@ -279,7 +339,8 @@ function hexToBytes(hex) {
|
|
|
279
339
|
function bytesToHex(bytes) {
|
|
280
340
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
281
341
|
}
|
|
282
|
-
export
|
|
342
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
343
|
+
0 && (module.exports = {
|
|
283
344
|
DEFAULT_CONFIG,
|
|
284
345
|
GasLimitExceededError,
|
|
285
346
|
InsufficientBalanceError,
|
|
@@ -305,4 +366,4 @@ export {
|
|
|
305
366
|
signDigest,
|
|
306
367
|
toNano,
|
|
307
368
|
verifySignature
|
|
308
|
-
};
|
|
369
|
+
});
|
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
DEFAULT_CONFIG: () => DEFAULT_CONFIG,
|
|
34
|
-
GasLimitExceededError: () => GasLimitExceededError,
|
|
35
|
-
InsufficientBalanceError: () => InsufficientBalanceError,
|
|
36
|
-
InvalidChainError: () => InvalidChainError,
|
|
37
|
-
InvalidPaymentCoinError: () => InvalidPaymentCoinError,
|
|
38
|
-
InvalidSignatureError: () => InvalidSignatureError,
|
|
39
|
-
MissingDigestError: () => MissingDigestError,
|
|
40
|
-
NetworkError: () => NetworkError,
|
|
41
|
-
PayerMismatchError: () => PayerMismatchError,
|
|
42
|
-
QuoteExpiredError: () => QuoteExpiredError,
|
|
43
|
-
QuoteNotFoundError: () => QuoteNotFoundError,
|
|
44
|
-
StatusNotFoundError: () => StatusNotFoundError,
|
|
45
|
-
UGFClient: () => UGFClient,
|
|
46
|
-
UGFError: () => UGFError,
|
|
47
|
-
UnauthorizedError: () => UnauthorizedError,
|
|
48
|
-
formatSTON: () => formatSTON,
|
|
49
|
-
fromNano: () => fromNano,
|
|
50
|
-
isValidBufferPct: () => isValidBufferPct,
|
|
51
|
-
isValidGasEstimate: () => isValidGasEstimate,
|
|
52
|
-
isValidHex: () => isValidHex,
|
|
53
|
-
isValidTONAddress: () => isValidTONAddress,
|
|
54
|
-
parseBackendError: () => parseBackendError,
|
|
55
|
-
signDigest: () => signDigest,
|
|
56
|
-
toNano: () => toNano,
|
|
57
|
-
verifySignature: () => verifySignature
|
|
58
|
-
});
|
|
59
|
-
module.exports = __toCommonJS(index_exports);
|
|
60
|
-
|
|
61
1
|
// src/utils/errors.ts
|
|
62
2
|
var UGFError = class extends Error {
|
|
63
3
|
constructor(message, code) {
|
|
@@ -296,10 +236,10 @@ function formatSTON(amount, decimals = 2) {
|
|
|
296
236
|
}
|
|
297
237
|
|
|
298
238
|
// src/utils/validation.ts
|
|
299
|
-
|
|
239
|
+
import { Address } from "@ton/core";
|
|
300
240
|
function isValidTONAddress(address) {
|
|
301
241
|
try {
|
|
302
|
-
|
|
242
|
+
Address.parse(address);
|
|
303
243
|
return true;
|
|
304
244
|
} catch {
|
|
305
245
|
return false;
|
|
@@ -316,18 +256,18 @@ function isValidBufferPct(pct) {
|
|
|
316
256
|
}
|
|
317
257
|
|
|
318
258
|
// src/crypto/signature.ts
|
|
319
|
-
|
|
259
|
+
import nacl from "tweetnacl";
|
|
320
260
|
function signDigest(digestHex, privateKeyHex) {
|
|
321
261
|
const digest = hexToBytes(digestHex);
|
|
322
262
|
const secretKey = hexToBytes(privateKeyHex);
|
|
323
|
-
const signature =
|
|
263
|
+
const signature = nacl.sign.detached(digest, secretKey);
|
|
324
264
|
return bytesToHex(signature);
|
|
325
265
|
}
|
|
326
266
|
function verifySignature(digestHex, signatureHex, publicKeyHex) {
|
|
327
267
|
const digest = hexToBytes(digestHex);
|
|
328
268
|
const signature = hexToBytes(signatureHex);
|
|
329
269
|
const publicKey = hexToBytes(publicKeyHex);
|
|
330
|
-
return
|
|
270
|
+
return nacl.sign.detached.verify(digest, signature, publicKey);
|
|
331
271
|
}
|
|
332
272
|
function hexToBytes(hex) {
|
|
333
273
|
const bytes = new Uint8Array(hex.length / 2);
|
|
@@ -339,8 +279,7 @@ function hexToBytes(hex) {
|
|
|
339
279
|
function bytesToHex(bytes) {
|
|
340
280
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
341
281
|
}
|
|
342
|
-
|
|
343
|
-
0 && (module.exports = {
|
|
282
|
+
export {
|
|
344
283
|
DEFAULT_CONFIG,
|
|
345
284
|
GasLimitExceededError,
|
|
346
285
|
InsufficientBalanceError,
|
|
@@ -366,4 +305,4 @@ function bytesToHex(bytes) {
|
|
|
366
305
|
signDigest,
|
|
367
306
|
toNano,
|
|
368
307
|
verifySignature
|
|
369
|
-
}
|
|
308
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tychilabs/stonfi-gasless-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Universal Gas Framework SDK for gasless payments - pay TON transaction fees with STON token",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"author": "yash@tychilabs.com",
|
|
35
|
-
"type": "module",
|
|
36
35
|
"scripts": {
|
|
37
36
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
38
37
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
File without changes
|