@fastnear/api 0.3.0 → 0.5.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.
Files changed (40) hide show
  1. package/dist/cjs/index.cjs +40 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs/index.d.cts +3339 -0
  4. package/dist/esm/index.d.ts +3339 -0
  5. package/dist/esm/index.js +9 -60
  6. package/dist/esm/index.js.map +1 -7
  7. package/dist/umd/{index.js → browser.global.js} +416 -219
  8. package/dist/umd/browser.global.js.map +1 -0
  9. package/package.json +13 -10
  10. package/dist/cjs/cryptoUtils.js +0 -89
  11. package/dist/cjs/cryptoUtils.js.map +0 -7
  12. package/dist/cjs/index.esm.js +0 -1191
  13. package/dist/cjs/index.esm.js.map +0 -7
  14. package/dist/cjs/index.js +0 -1246
  15. package/dist/cjs/index.js.map +0 -7
  16. package/dist/cjs/near.js +0 -1191
  17. package/dist/cjs/near.js.map +0 -7
  18. package/dist/cjs/transaction.js +0 -360
  19. package/dist/cjs/transaction.js.map +0 -7
  20. package/dist/cjs/utils.js +0 -105
  21. package/dist/cjs/utils.js.map +0 -7
  22. package/dist/esm/chunk-2SCAGR3F.js +0 -68
  23. package/dist/esm/chunk-2SCAGR3F.js.map +0 -7
  24. package/dist/esm/chunk-B2HMQPYI.js +0 -814
  25. package/dist/esm/chunk-B2HMQPYI.js.map +0 -7
  26. package/dist/esm/chunk-S5Q2EM2B.js +0 -48
  27. package/dist/esm/chunk-S5Q2EM2B.js.map +0 -7
  28. package/dist/esm/chunk-YKPILPMX.js +0 -301
  29. package/dist/esm/chunk-YKPILPMX.js.map +0 -7
  30. package/dist/esm/cryptoUtils.js +0 -21
  31. package/dist/esm/cryptoUtils.js.map +0 -7
  32. package/dist/esm/index.esm.js +0 -13
  33. package/dist/esm/index.esm.js.map +0 -7
  34. package/dist/esm/near.js +0 -15
  35. package/dist/esm/near.js.map +0 -7
  36. package/dist/esm/transaction.js +0 -16
  37. package/dist/esm/transaction.js.map +0 -7
  38. package/dist/esm/utils.js +0 -24
  39. package/dist/esm/utils.js.map +0 -7
  40. package/dist/umd/index.js.map +0 -7
package/package.json CHANGED
@@ -1,33 +1,35 @@
1
1
  {
2
2
  "name": "@fastnear/api",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Interact with NEAR Protocol blockchain including transaction signing, utilities, and more.",
5
5
  "type": "module",
6
- "main": "./dist/cjs/index.js",
6
+ "types": "./dist/esm/index.d.ts",
7
+ "main": "./dist/cjs/index.cjs",
7
8
  "module": "./dist/esm/index.js",
8
- "browser": "./dist/umd/index.js",
9
+ "browser": "./dist/umd/browser.global.js",
9
10
  "scripts": {
10
- "build": "node esbuild.config.mjs",
11
+ "build": "tsup",
11
12
  "publish": "yarn npm publish",
12
- "clean": "yarn rimraf dist node_modules"
13
+ "clean": "yarn rimraf dist node_modules",
14
+ "type-check": "tsc --noEmit"
13
15
  },
16
+ "author": "FastNEAR",
14
17
  "keywords": [
15
18
  "near-protocol",
16
19
  "blockchain",
17
20
  "fastnear"
18
21
  ],
19
- "author": "FastNEAR",
20
22
  "files": [
21
23
  "dist"
22
24
  ],
23
25
  "exports": {
24
26
  ".": {
25
- "require": "./dist/cjs/index.js",
27
+ "require": "./dist/cjs/index.cjs",
26
28
  "import": "./dist/esm/index.js"
27
29
  }
28
30
  },
29
31
  "dependencies": {
30
- "@fastnear/wallet-adapter": "0.3.0",
32
+ "@fastnear/wallet-adapter": "0.5.0",
31
33
  "@noble/curves": "*",
32
34
  "@noble/hashes": "*",
33
35
  "base58-js": "*",
@@ -35,7 +37,8 @@
35
37
  "borsh": "*"
36
38
  },
37
39
  "devDependencies": {
38
- "glob": "*",
39
- "rimraf": "*"
40
+ "rimraf": "*",
41
+ "tsup": "*",
42
+ "typescript": "*"
40
43
  }
41
44
  }
@@ -1,89 +0,0 @@
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
@@ -1,7 +0,0 @@
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
- }