@fastnear/api 0.1.0 → 0.4.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/dist/cjs/cryptoUtils.js +89 -0
- package/dist/cjs/cryptoUtils.js.map +7 -0
- package/dist/cjs/index.esm.js +1219 -0
- package/dist/cjs/index.esm.js.map +7 -0
- package/dist/cjs/index.js +1274 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/near.js +1219 -0
- package/dist/cjs/near.js.map +7 -0
- package/dist/cjs/transaction.js +360 -0
- package/dist/cjs/transaction.js.map +7 -0
- package/dist/cjs/utils.js +105 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/chunk-2SCAGR3F.js +68 -0
- package/dist/esm/chunk-2SCAGR3F.js.map +7 -0
- package/dist/esm/chunk-OR3WITSY.js +842 -0
- package/dist/esm/chunk-OR3WITSY.js.map +7 -0
- package/dist/esm/chunk-S5Q2EM2B.js +48 -0
- package/dist/esm/chunk-S5Q2EM2B.js.map +7 -0
- package/{src/transaction.js → dist/esm/chunk-YKPILPMX.js} +113 -99
- package/dist/esm/chunk-YKPILPMX.js.map +7 -0
- package/dist/esm/cryptoUtils.js +21 -0
- package/dist/esm/cryptoUtils.js.map +7 -0
- package/dist/esm/index.esm.js +13 -0
- package/dist/esm/index.esm.js.map +7 -0
- package/dist/esm/index.js +63 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/near.js +15 -0
- package/dist/esm/near.js.map +7 -0
- package/dist/esm/transaction.js +16 -0
- package/dist/esm/transaction.js.map +7 -0
- package/dist/esm/utils.js +24 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/umd/index.js +4227 -0
- package/dist/umd/index.js.map +7 -0
- package/package.json +35 -25
- package/README.md +0 -76
- package/dist/fastnear.cjs +0 -35
- package/dist/fastnear.ejs +0 -24
- package/dist/fastnear.js +0 -35
- package/src/crypto.js +0 -37
- package/src/index.esm.js +0 -3
- package/src/index.js +0 -8
- package/src/near.js +0 -566
- package/src/utils.js +0 -48
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* ⋈ 🏃🏻💨 FastNEAR API - https://github.com/fastnear */
|
|
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/cryptoUtils.ts
|
|
31
|
+
var cryptoUtils_exports = {};
|
|
32
|
+
__export(cryptoUtils_exports, {
|
|
33
|
+
keyFromString: () => keyFromString,
|
|
34
|
+
keyToString: () => keyToString,
|
|
35
|
+
privateKeyFromRandom: () => privateKeyFromRandom,
|
|
36
|
+
publicKeyFromPrivate: () => publicKeyFromPrivate,
|
|
37
|
+
sha256: () => import_sha2.sha256,
|
|
38
|
+
signBytes: () => signBytes,
|
|
39
|
+
signHash: () => signHash
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(cryptoUtils_exports);
|
|
42
|
+
var import_ed25519 = require("@noble/curves/ed25519");
|
|
43
|
+
var import_sha2 = require("@noble/hashes/sha2");
|
|
44
|
+
|
|
45
|
+
// src/utils.ts
|
|
46
|
+
var import_base58_js = require("base58-js");
|
|
47
|
+
var import_big = __toESM(require("big.js"), 1);
|
|
48
|
+
var import_js_base64 = require("js-base64");
|
|
49
|
+
|
|
50
|
+
// src/cryptoUtils.ts
|
|
51
|
+
var keyFromString = (key) => (0, import_base58_js.base58_to_binary)(
|
|
52
|
+
key.includes(":") ? (() => {
|
|
53
|
+
const [curve, keyPart] = key.split(":");
|
|
54
|
+
if (curve !== "ed25519") {
|
|
55
|
+
throw new Error(`Unsupported curve: ${curve}`);
|
|
56
|
+
}
|
|
57
|
+
return keyPart;
|
|
58
|
+
})() : key
|
|
59
|
+
);
|
|
60
|
+
var keyToString = (key) => `ed25519:${(0, import_base58_js.binary_to_base58)(key)}`;
|
|
61
|
+
function publicKeyFromPrivate(privateKey) {
|
|
62
|
+
privateKey = keyFromString(privateKey).slice(0, 32);
|
|
63
|
+
const publicKey = import_ed25519.ed25519.getPublicKey(privateKey);
|
|
64
|
+
return keyToString(publicKey);
|
|
65
|
+
}
|
|
66
|
+
function privateKeyFromRandom() {
|
|
67
|
+
const privateKey = crypto.getRandomValues(new Uint8Array(64));
|
|
68
|
+
return keyToString(privateKey);
|
|
69
|
+
}
|
|
70
|
+
function signHash(hash, privateKey) {
|
|
71
|
+
privateKey = keyFromString(privateKey).slice(0, 32);
|
|
72
|
+
const signature = import_ed25519.ed25519.sign((0, import_base58_js.base58_to_binary)(hash), privateKey);
|
|
73
|
+
return (0, import_base58_js.binary_to_base58)(signature);
|
|
74
|
+
}
|
|
75
|
+
function signBytes(bytes, privateKey) {
|
|
76
|
+
const hash = (0, import_sha2.sha256)(bytes);
|
|
77
|
+
return signHash((0, import_base58_js.binary_to_base58)(hash), privateKey);
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
keyFromString,
|
|
82
|
+
keyToString,
|
|
83
|
+
privateKeyFromRandom,
|
|
84
|
+
publicKeyFromPrivate,
|
|
85
|
+
sha256,
|
|
86
|
+
signBytes,
|
|
87
|
+
signHash
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=cryptoUtils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/cryptoUtils.ts", "../../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import { ed25519 } from \"@noble/curves/ed25519\";\nimport { sha256 } from \"@noble/hashes/sha2\";\nimport { fromBase58, toBase58 } from \"./utils.js\";\n\nexport { sha256 };\n\nexport const keyFromString = (key) =>\n fromBase58(\n key.includes(\":\")\n ? (() => {\n const [curve, keyPart] = key.split(\":\");\n if (curve !== \"ed25519\") {\n throw new Error(`Unsupported curve: ${curve}`);\n }\n return keyPart;\n })()\n : key,\n );\n\nexport const keyToString = (key) => `ed25519:${toBase58(key)}`;\n\nexport function publicKeyFromPrivate(privateKey) {\n privateKey = keyFromString(privateKey).slice(0, 32);\n const publicKey = ed25519.getPublicKey(privateKey);\n return keyToString(publicKey);\n}\n\nexport function privateKeyFromRandom() {\n const privateKey = crypto.getRandomValues(new Uint8Array(64));\n return keyToString(privateKey);\n}\n\nexport function signHash(hash, privateKey) {\n privateKey = keyFromString(privateKey).slice(0, 32);\n const signature = ed25519.sign(fromBase58(hash), privateKey);\n return toBase58(signature);\n}\n\nexport function signBytes(bytes, privateKey) {\n const hash = sha256(bytes);\n return signHash(toBase58(hash), privateKey);\n}\n", "import {\n binary_to_base58 as toBase58,\n base58_to_binary as fromBase58,\n} from \"base58-js\";\nimport Big from \"big.js\";\nimport { encode, decode } from 'js-base64';\n\nexport { toBase58, fromBase58 };\n\nconst LsPrefix = \"__fastnear_\";\n\nexport function toBase64(data) {\n if (typeof data === 'string') {\n return encode(data);\n } else {\n const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);\n const str = String.fromCharCode(...bytes);\n return encode(str);\n }\n}\n\nexport function fromBase64(str) {\n const binaryString = decode(str);\n const len = binaryString.length;\n const bytes = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n return bytes;\n}\n\nexport function lsSet(key, value) {\n if (value === null || value === undefined) {\n localStorage.removeItem(LsPrefix + key);\n } else {\n localStorage.setItem(LsPrefix + key, JSON.stringify(value));\n }\n}\n\nexport function lsGet(key) {\n const value = localStorage.getItem(LsPrefix + key);\n return tryParseJson(value, null);\n}\n\nexport function deepCopy(obj) {\n return JSON.parse(JSON.stringify(obj));\n}\n\nexport function tryParseJson(...args) {\n try {\n return JSON.parse(args[0]);\n } catch {\n if (args.length > 1) {\n return args[1];\n }\n return args[0];\n }\n}\n\nexport function canSignWithLAK(actions) {\n return (\n actions.length === 1 &&\n actions[0].type === \"FunctionCall\" &&\n Big(actions[0]?.deposit ?? \"0\").eq(0)\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AACxB,kBAAuB;;;ACDvB,uBAGO;AACP,iBAAgB;AAChB,uBAA+B;;;ADCxB,IAAM,gBAAgB,CAAC,YAC5B,iBAAAA;AAAA,EACE,IAAI,SAAS,GAAG,KACX,MAAM;AACL,UAAM,CAAC,OAAO,OAAO,IAAI,IAAI,MAAM,GAAG;AACtC,QAAI,UAAU,WAAW;AACvB,YAAM,IAAI,MAAM,sBAAsB,KAAK,EAAE;AAAA,IAC/C;AACA,WAAO;AAAA,EACT,GAAG,IACH;AACN;AAEK,IAAM,cAAc,CAAC,QAAQ,eAAW,iBAAAC,kBAAS,GAAG,CAAC;AAErD,SAAS,qBAAqB,YAAY;AAC/C,eAAa,cAAc,UAAU,EAAE,MAAM,GAAG,EAAE;AAClD,QAAM,YAAY,uBAAQ,aAAa,UAAU;AACjD,SAAO,YAAY,SAAS;AAC9B;AAEO,SAAS,uBAAuB;AACrC,QAAM,aAAa,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC;AAC5D,SAAO,YAAY,UAAU;AAC/B;AAEO,SAAS,SAAS,MAAM,YAAY;AACzC,eAAa,cAAc,UAAU,EAAE,MAAM,GAAG,EAAE;AAClD,QAAM,YAAY,uBAAQ,SAAK,iBAAAD,kBAAW,IAAI,GAAG,UAAU;AAC3D,aAAO,iBAAAC,kBAAS,SAAS;AAC3B;AAEO,SAAS,UAAU,OAAO,YAAY;AAC3C,QAAM,WAAO,oBAAO,KAAK;AACzB,SAAO,aAAS,iBAAAA,kBAAS,IAAI,GAAG,UAAU;AAC5C;",
|
|
6
|
+
"names": ["fromBase58", "toBase58"]
|
|
7
|
+
}
|