@fastnear/utils 0.6.3 → 0.7.1

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.
@@ -0,0 +1,81 @@
1
+ /* ⋈ 🏃🏻💨 FastNEAR Utils - CJS (@fastnear/utils version 0.7.0) */
2
+ /* https://www.npmjs.com/package/@fastnear/utils/v/0.7.0 */
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var crypto_exports = {};
23
+ __export(crypto_exports, {
24
+ keyFromString: () => keyFromString,
25
+ keyToString: () => keyToString,
26
+ privateKeyFromRandom: () => privateKeyFromRandom,
27
+ publicKeyFromPrivate: () => publicKeyFromPrivate,
28
+ sha256: () => import_sha2.sha256,
29
+ signBytes: () => signBytes,
30
+ signHash: () => signHash
31
+ });
32
+ module.exports = __toCommonJS(crypto_exports);
33
+ var import_ed25519 = require("@noble/curves/ed25519");
34
+ var import_sha2 = require("@noble/hashes/sha2");
35
+ var import_misc = require("./misc.js");
36
+ const keyFromString = /* @__PURE__ */ __name((key) => (0, import_misc.fromBase58)(
37
+ key.includes(":") ? (() => {
38
+ const [curve, keyPart] = key.split(":");
39
+ if (curve !== "ed25519") {
40
+ throw new Error(`Unsupported curve: ${curve}`);
41
+ }
42
+ return keyPart;
43
+ })() : key
44
+ ), "keyFromString");
45
+ const keyToString = /* @__PURE__ */ __name((key) => `ed25519:${(0, import_misc.toBase58)(key)}`, "keyToString");
46
+ function publicKeyFromPrivate(privateKey) {
47
+ const secret = keyFromString(privateKey).slice(0, 32);
48
+ const publicKey = import_ed25519.ed25519.getPublicKey(secret);
49
+ return keyToString(publicKey);
50
+ }
51
+ __name(publicKeyFromPrivate, "publicKeyFromPrivate");
52
+ function privateKeyFromRandom() {
53
+ const privateKey = crypto.getRandomValues(new Uint8Array(64));
54
+ return keyToString(privateKey);
55
+ }
56
+ __name(privateKeyFromRandom, "privateKeyFromRandom");
57
+ function signHash(hashBytes, privateKey, opts) {
58
+ const secret = keyFromString(privateKey).slice(0, 32);
59
+ const signature = import_ed25519.ed25519.sign(hashBytes, secret);
60
+ if (opts?.returnBase58) {
61
+ return (0, import_misc.toBase58)(signature);
62
+ }
63
+ return signature;
64
+ }
65
+ __name(signHash, "signHash");
66
+ function signBytes(bytes, privateKey) {
67
+ const hash = (0, import_sha2.sha256)(bytes);
68
+ return signHash(hash, privateKey);
69
+ }
70
+ __name(signBytes, "signBytes");
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ keyFromString,
74
+ keyToString,
75
+ privateKeyFromRandom,
76
+ publicKeyFromPrivate,
77
+ sha256,
78
+ signBytes,
79
+ signHash
80
+ });
81
+ //# sourceMappingURL=crypto.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/crypto.ts"],"sourcesContent":["import { ed25519 } from \"@noble/curves/ed25519\";\nimport { sha256 } from \"@noble/hashes/sha2\";\nimport { fromBase58, toBase58 } from \"./misc.js\";\nimport {Hex} from \"@noble/curves/abstract/utils\";\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: Uint8Array) => `ed25519:${toBase58(key)}`;\n\nexport function publicKeyFromPrivate(privateKey: string) {\n const secret = keyFromString(privateKey).slice(0, 32);\n const publicKey = ed25519.getPublicKey(secret);\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(hashBytes: Uint8Array, privateKey: string, opts?: any): Hex {\n const secret = keyFromString(privateKey).slice(0, 32);\n const signature = ed25519.sign(hashBytes, secret);\n\n if (opts?.returnBase58) {\n return toBase58(signature);\n }\n\n return signature;\n}\n\nexport function signBytes(bytes: Uint8Array, privateKey: string) {\n const hash = sha256(bytes);\n return signHash(hash, privateKey);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AACxB,kBAAuB;AACvB,kBAAqC;AAK9B,MAAM,gBAAgB,wBAAC,YAC5B;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,GAX2B;AAatB,MAAM,cAAc,wBAAC,QAAoB,eAAW,sBAAS,GAAG,CAAC,IAA7C;AAEpB,SAAS,qBAAqB,YAAoB;AACvD,QAAM,SAAS,cAAc,UAAU,EAAE,MAAM,GAAG,EAAE;AACpD,QAAM,YAAY,uBAAQ,aAAa,MAAM;AAC7C,SAAO,YAAY,SAAS;AAC9B;AAJgB;AAMT,SAAS,uBAAuB;AACrC,QAAM,aAAa,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC;AAC5D,SAAO,YAAY,UAAU;AAC/B;AAHgB;AAKT,SAAS,SAAS,WAAuB,YAAoB,MAAiB;AACnF,QAAM,SAAS,cAAc,UAAU,EAAE,MAAM,GAAG,EAAE;AACpD,QAAM,YAAY,uBAAQ,KAAK,WAAW,MAAM;AAEhD,MAAI,MAAM,cAAc;AACtB,eAAO,sBAAS,SAAS;AAAA,EAC3B;AAEA,SAAO;AACT;AATgB;AAWT,SAAS,UAAU,OAAmB,YAAoB;AAC/D,QAAM,WAAO,oBAAO,KAAK;AACzB,SAAO,SAAS,MAAM,UAAU;AAClC;AAHgB;","names":[]}
@@ -1,5 +1,6 @@
1
- /* ⋈ 🏃🏻💨 FastNEAR Utils - CJS (@fastnear/utils version 0.6.3) */
2
- /* https://www.npmjs.com/package/@fastnear/utils/v/0.6.3 */
1
+ /* ⋈ 🏃🏻💨 FastNEAR Utils - CJS (@fastnear/utils version 0.7.0) */
2
+ /* https://www.npmjs.com/package/@fastnear/utils/v/0.7.0 */
3
+ "use strict";
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -30,18 +31,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
32
  var src_exports = {};
32
33
  __export(src_exports, {
33
- reExportBorshSchema: () => reExportBorshSchema
34
+ exp: () => exp
34
35
  });
35
36
  module.exports = __toCommonJS(src_exports);
36
37
  __reExport(src_exports, require("./crypto.js"), module.exports);
37
38
  __reExport(src_exports, require("./transaction.js"), module.exports);
38
39
  __reExport(src_exports, require("./misc.js"), module.exports);
39
- var reExportBorshSchema = __toESM(require("@fastnear/borsh-schema"), 1);
40
+ __reExport(src_exports, require("./storage.js"), module.exports);
41
+ var import_borsh = require("borsh");
42
+ var borshSchema = __toESM(require("@fastnear/borsh-schema"), 1);
43
+ const exp = {
44
+ borsh: {
45
+ serialize: import_borsh.serialize,
46
+ deserialize: import_borsh.deserialize
47
+ },
48
+ borshSchema
49
+ };
40
50
  // Annotate the CommonJS export names for ESM import in node:
41
51
  0 && (module.exports = {
42
- reExportBorshSchema,
52
+ exp,
43
53
  ...require("./crypto.js"),
44
54
  ...require("./transaction.js"),
45
- ...require("./misc.js")
55
+ ...require("./misc.js"),
56
+ ...require("./storage.js")
46
57
  });
47
58
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./crypto.js\";\nexport * from \"./transaction.js\";\nexport * from \"./misc.js\";\n\nexport * as reExportBorshSchema from \"@fastnear/borsh-schema\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,6BADd;AAEA,wBAAc,sBAFd;AAIA,0BAAqC;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./crypto.js\";\nexport * from \"./transaction.js\";\nexport * from \"./misc.js\";\nexport * from \"./storage.js\";\n\nimport { serialize, deserialize } from \"borsh\";\nimport * as borshSchema from \"@fastnear/borsh-schema\";\n\n// exports (or re-exports as well)\nconst exp = {\n borsh: {\n serialize,\n deserialize\n },\n borshSchema,\n}\n\nexport { exp }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,6BADd;AAEA,wBAAc,sBAFd;AAGA,wBAAc,yBAHd;AAKA,mBAAuC;AACvC,kBAA6B;AAG7B,MAAM,MAAM;AAAA,EACV,OAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AAAA,EACA;AACF;","names":[]}