@xyo-network/elliptic 7.0.12 → 7.0.13

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/README.md CHANGED
@@ -1,3 +1,49 @@
1
+ [![logo][]](https://xyo.network)
2
+
1
3
  # @xyo-network/elliptic
2
4
 
3
- Deprecated compatibility stub. Use `@xyo-network/sdk-protocol/elliptic` instead.
5
+ [![npm][npm-badge]][npm-link]
6
+ [![license][license-badge]][license-link]
7
+
8
+ > Primary SDK for using XYO Protocol 2.0
9
+
10
+ ## Install
11
+
12
+ Using npm:
13
+
14
+ ```sh
15
+ npm install {{name}}
16
+ ```
17
+
18
+ Using yarn:
19
+
20
+ ```sh
21
+ yarn add {{name}}
22
+ ```
23
+
24
+ Using pnpm:
25
+
26
+ ```sh
27
+ pnpm add {{name}}
28
+ ```
29
+
30
+ Using bun:
31
+
32
+ ```sh
33
+ bun add {{name}}
34
+ ```
35
+
36
+
37
+ ## License
38
+
39
+ See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
40
+
41
+ ## Credits
42
+
43
+ [Made with 🔥 and ❄️ by XYO Foundation](https://xyo.network)
44
+
45
+ [npm-badge]: https://img.shields.io/npm/v/@xyo-network/elliptic.svg
46
+ [npm-link]: https://www.npmjs.com/package/@xyo-network/elliptic
47
+ [license-badge]: https://img.shields.io/npm/l/@xyo-network/elliptic.svg
48
+ [license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
49
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -0,0 +1,15 @@
1
+ import type { Secp256k1 } from '@bitauth/libauth';
2
+ import { WasmSupport } from '@xyo-network/wasm';
3
+ export declare class Elliptic {
4
+ static readonly wasmSupport: WasmSupport;
5
+ protected static _secp256k1: Secp256k1 | undefined;
6
+ private static _secp256k1Mutex;
7
+ static addressFromPublicKey(key: ArrayBufferLike): ArrayBufferLike;
8
+ static initialize(): Promise<Secp256k1>;
9
+ static publicKeyFromPrivateKey(privateKey: ArrayBufferLike, prefix?: boolean): Promise<ArrayBufferLike>;
10
+ static ready(): boolean;
11
+ static secp256k1(): Promise<Secp256k1>;
12
+ static sign(hash: ArrayBufferLike, key: ArrayBufferLike): Promise<ArrayBufferLike>;
13
+ static verify(msg: ArrayBufferLike, signature: ArrayBufferLike, address: ArrayBufferLike): Promise<boolean>;
14
+ }
15
+ //# sourceMappingURL=Elliptic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Elliptic.d.ts","sourceRoot":"","sources":["../../src/Elliptic.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAuB/C,qBAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,WAAW,cAAoB;IAC/C,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,CAAA;IAClD,OAAO,CAAC,MAAM,CAAC,eAAe,CAAc;IAE5C,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,eAAe,GAAG,eAAe;IAKlE,MAAM,CAAC,UAAU;WAIJ,uBAAuB,CAAC,UAAU,EAAE,eAAe,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAU3G,MAAM,CAAC,KAAK;WAIC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;WAW/B,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe;WAMhD,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe;CAuB/F"}
@@ -1,6 +1,2 @@
1
- /**
2
- * @deprecated Use `@xyo-network/sdk-protocol/elliptic` instead.
3
- * `@xyo-network/elliptic` is a backward-compatibility re-export stub.
4
- */
5
- export * from '@xyo-network/sdk-protocol/elliptic';
1
+ export * from './Elliptic.ts';
6
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oCAAoC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -1,3 +1,89 @@
1
- // src/index.ts
2
- export * from "@xyo-network/sdk-protocol/elliptic";
1
+ // src/Elliptic.ts
2
+ import {
3
+ assertEx,
4
+ toHex,
5
+ toUint8Array
6
+ } from "@ariestools/sdk";
7
+ import { instantiateSecp256k1 } from "@bitauth/libauth";
8
+ import { Data } from "@xyo-network/data";
9
+ import { WasmSupport } from "@xyo-network/wasm";
10
+ import { Mutex } from "async-mutex";
11
+ var wasmSupportStatic = new WasmSupport(["bigInt", "mutableGlobals", "referenceTypes", "saturatedFloatToInt", "signExtensions", "simd"]);
12
+ var recoveryIds = [0, 1, 2, 3];
13
+ function compareArrayBuffers(b1, b2) {
14
+ if (b1.byteLength !== b2.byteLength) {
15
+ return false;
16
+ }
17
+ const a1 = new Uint8Array(b1);
18
+ const a2 = new Uint8Array(b2);
19
+ for (let i = 0; i < b1.byteLength; i++) {
20
+ if (a1[i] !== a2[i]) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+ var Elliptic = class {
27
+ static wasmSupport = wasmSupportStatic;
28
+ static _secp256k1;
29
+ static _secp256k1Mutex = new Mutex();
30
+ static addressFromPublicKey(key) {
31
+ const data = new Data(64, key);
32
+ return data.keccak256.slice(12);
33
+ }
34
+ static initialize() {
35
+ return this.secp256k1();
36
+ }
37
+ static async publicKeyFromPrivateKey(privateKey, prefix = false) {
38
+ const { derivePublicKeyUncompressed } = await this.secp256k1();
39
+ if (BigInt(toHex(privateKey, { prefix: true })) === 0n) {
40
+ throw new Error(`Invalid private key [${toHex(privateKey)}]`);
41
+ }
42
+ const derivedPublicKey = derivePublicKeyUncompressed(new Uint8Array(privateKey));
43
+ const fullPublicKey = typeof derivedPublicKey === "string" ? toUint8Array(derivedPublicKey) : derivedPublicKey;
44
+ return (prefix ? fullPublicKey : fullPublicKey.slice(1)).buffer;
45
+ }
46
+ static ready() {
47
+ return !!this._secp256k1;
48
+ }
49
+ static async secp256k1() {
50
+ return await this._secp256k1Mutex.runExclusive(async () => {
51
+ if (this._secp256k1) return this._secp256k1;
52
+ await wasmSupportStatic.initialize();
53
+ const secp256k1 = assertEx(await instantiateSecp256k1(), () => "No Wasm Support");
54
+ this._secp256k1 = secp256k1;
55
+ return secp256k1;
56
+ });
57
+ }
58
+ static async sign(hash, key) {
59
+ const { signMessageHashCompact } = await this.secp256k1();
60
+ const signature = signMessageHashCompact(new Uint8Array(key), toUint8Array(hash));
61
+ return (typeof signature === "string" ? toUint8Array(signature) : signature).buffer;
62
+ }
63
+ static async verify(msg, signature, address) {
64
+ const verifier = await this.secp256k1();
65
+ if (this.wasmSupport.canUseWasm) {
66
+ for (const recoveryId of recoveryIds) {
67
+ try {
68
+ const rawRecoveredPublicKey = verifier.recoverPublicKeyUncompressed(toUint8Array(signature), recoveryId, toUint8Array(msg));
69
+ const recoveredPublicKey = (typeof rawRecoveredPublicKey === "string" ? toUint8Array(rawRecoveredPublicKey) : rawRecoveredPublicKey).slice(1).buffer;
70
+ const recoveredAddress = this.addressFromPublicKey(recoveredPublicKey);
71
+ if (compareArrayBuffers(address, recoveredAddress)) {
72
+ return true;
73
+ }
74
+ } catch (ex) {
75
+ const error = ex;
76
+ console.log(error.message);
77
+ console.log(error.stack);
78
+ continue;
79
+ }
80
+ }
81
+ return false;
82
+ }
83
+ throw new Error("No wasm support");
84
+ }
85
+ };
86
+ export {
87
+ Elliptic
88
+ };
3
89
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["/**\n * @deprecated Use `@xyo-network/sdk-protocol/elliptic` instead.\n * `@xyo-network/elliptic` is a backward-compatibility re-export stub.\n */\nexport * from '@xyo-network/sdk-protocol/elliptic'\n"],
5
- "mappings": ";AAIA,cAAc;",
3
+ "sources": ["../../src/Elliptic.ts"],
4
+ "sourcesContent": ["import {\n assertEx, toHex, toUint8Array,\n} from '@ariestools/sdk'\nimport type { Secp256k1 } from '@bitauth/libauth'\nimport { instantiateSecp256k1 } from '@bitauth/libauth'\nimport { Data } from '@xyo-network/data'\nimport { WasmSupport } from '@xyo-network/wasm'\nimport { Mutex } from 'async-mutex'\n\nconst wasmSupportStatic = new WasmSupport(['bigInt', 'mutableGlobals', 'referenceTypes', 'saturatedFloatToInt', 'signExtensions', 'simd'])\nconst recoveryIds = [0, 1, 2, 3] as const\n\nfunction compareArrayBuffers(b1: ArrayBufferLike, b2: ArrayBufferLike) {\n if (b1.byteLength !== b2.byteLength) {\n return false\n }\n\n const a1 = new Uint8Array(b1)\n const a2 = new Uint8Array(b2)\n\n for (let i = 0; i < b1.byteLength; i++) {\n if (a1[i] !== a2[i]) {\n return false\n }\n }\n\n return true\n}\n\nexport class Elliptic {\n static readonly wasmSupport = wasmSupportStatic\n protected static _secp256k1: Secp256k1 | undefined\n private static _secp256k1Mutex = new Mutex()\n\n static addressFromPublicKey(key: ArrayBufferLike): ArrayBufferLike {\n const data = new Data(64, key)\n return data.keccak256.slice(12)\n }\n\n static initialize() {\n return this.secp256k1()\n }\n\n static async publicKeyFromPrivateKey(privateKey: ArrayBufferLike, prefix = false): Promise<ArrayBufferLike> {\n const { derivePublicKeyUncompressed } = await this.secp256k1()\n if (BigInt(toHex(privateKey, { prefix: true })) === 0n) {\n throw new Error(`Invalid private key [${toHex(privateKey)}]`)\n }\n const derivedPublicKey = derivePublicKeyUncompressed(new Uint8Array(privateKey))\n const fullPublicKey = typeof derivedPublicKey === 'string' ? toUint8Array(derivedPublicKey) : derivedPublicKey\n return (prefix ? fullPublicKey : fullPublicKey.slice(1)).buffer\n }\n\n static ready() {\n return !!this._secp256k1\n }\n\n static async secp256k1(): Promise<Secp256k1> {\n return await this._secp256k1Mutex.runExclusive(async () => {\n if (this._secp256k1) return this._secp256k1\n\n await wasmSupportStatic.initialize()\n const secp256k1 = assertEx(await instantiateSecp256k1(), () => 'No Wasm Support')\n this._secp256k1 = secp256k1\n return secp256k1\n })\n }\n\n static async sign(hash: ArrayBufferLike, key: ArrayBufferLike) {\n const { signMessageHashCompact } = await this.secp256k1()\n const signature = signMessageHashCompact(new Uint8Array(key), toUint8Array(hash))\n return (typeof signature === 'string' ? toUint8Array(signature) : signature).buffer\n }\n\n static async verify(msg: ArrayBufferLike, signature: ArrayBufferLike, address: ArrayBufferLike) {\n const verifier = await this.secp256k1()\n if (this.wasmSupport.canUseWasm) {\n for (const recoveryId of recoveryIds) {\n try {\n const rawRecoveredPublicKey = verifier.recoverPublicKeyUncompressed(toUint8Array(signature), recoveryId, toUint8Array(msg))\n const recoveredPublicKey = (typeof rawRecoveredPublicKey === 'string' ? toUint8Array(rawRecoveredPublicKey) : rawRecoveredPublicKey).slice(1).buffer\n const recoveredAddress = this.addressFromPublicKey(recoveredPublicKey)\n if (compareArrayBuffers(address, recoveredAddress)) {\n return true\n }\n } catch (ex) {\n const error = ex as Error\n console.log(error.message)\n console.log(error.stack)\n continue\n }\n }\n return false\n }\n // In all failure modes default to the JS implementation\n throw new Error('No wasm support')\n }\n}\n"],
5
+ "mappings": ";AAAA;AAAA,EACE;AAAA,EAAU;AAAA,EAAO;AAAA,OACZ;AAEP,SAAS,4BAA4B;AACrC,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AAEtB,IAAM,oBAAoB,IAAI,YAAY,CAAC,UAAU,kBAAkB,kBAAkB,uBAAuB,kBAAkB,MAAM,CAAC;AACzI,IAAM,cAAc,CAAC,GAAG,GAAG,GAAG,CAAC;AAE/B,SAAS,oBAAoB,IAAqB,IAAqB;AACrE,MAAI,GAAG,eAAe,GAAG,YAAY;AACnC,WAA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AClB,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EAEA,aAAa,KAAK,MAAuB,KAAsB;AAC7D,UAAM,EAAE,uBAAuB,IAAI,MAAM,KAAK,UAAU;AACxD,UAAM,YAAY,uBAAuB,IAAI,WAAW,GAAG,GAAG,aAAa,IAAI,CAAC;AAChF,YAAQ,OAAO,cAAc,WAAW,aAAa,SAAS,IAAI,WAAW;AAAA,EAC/E;AAAA,EAEA,aAAa,OAAO,KAAsB,WAA4B,SAA0B;AAC9F,UAAM,WAAW,MAAM,KAAK,UAAU;AACtC,QAAI,KAAK,YAAY,YAAY;AAC/B,iBAAW,cAAc,aAAa;AACpC,YAAI;AACF,gBAAM,wBAAwB,SAAS,6BAA6B,aAAa,SAAS,GAAG,YAAY,aAAa,GAAG,CAAC;AAC1H,gBAAM,sBAAsB,OAAO,0BAA0B,WAAW,aAAa,qBAAqB,IAAI,uBAAuB,MAAM,CAAC,EAAE;AAC9I,gBAAM,mBAAmB,KAAK,qBAAqB,kBAAkB;AACrE,cAAI,oBAAoB,SAAS,gBAAgB,GAAG;AAClD,mBAAO;AAAA,UACT;AAAA,QACF,SAAS,IAAI;AACX,gBAAM,QAAQ;AACd,kBAAQ,IAAI,MAAM,OAAO;AACzB,kBAAQ,IAAI,MAAM,KAAK;AACvB;AAAA,QACF;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@xyo-network/elliptic",
3
- "version": "7.0.12",
4
- "description": "DEPRECATED - use @xyo-network/sdk-protocol/elliptic. Backward-compatibility re-export stub for @xyo-network/elliptic.",
5
- "deprecated": "Use @xyo-network/sdk-protocol/elliptic instead. @xyo-network/elliptic is a backward-compatibility re-export stub and will not receive further updates.",
3
+ "version": "7.0.13",
4
+ "description": "Primary SDK for using XYO Protocol 2.0",
6
5
  "homepage": "https://xyo.network",
7
6
  "bugs": {
8
7
  "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues",
@@ -35,34 +34,32 @@
35
34
  "README.md"
36
35
  ],
37
36
  "dependencies": {
38
- "@xyo-network/sdk-protocol": "~7.0.12"
37
+ "@xyo-network/data": "~7.0.13",
38
+ "@xyo-network/wasm": "~7.0.13"
39
39
  },
40
40
  "devDependencies": {
41
- "@xylabs/toolchain": "~8.5.15",
42
- "@xylabs/tsconfig": "~8.5.15",
43
- "browserslist": "4.28.4",
44
- "eslint": "^10.6.0",
45
- "eslint-import-resolver-typescript": "^4.4.5",
46
- "typescript": "~6.0.3"
41
+ "@ariestools/sdk": "~7.0.8",
42
+ "@bitauth/libauth": "~3.0.0",
43
+ "@opentelemetry/api": "~1.9.1",
44
+ "@opentelemetry/sdk-trace-base": "~2.9.0",
45
+ "@scure/base": "~2.2.0",
46
+ "@xylabs/toolchain": "~8.6.2",
47
+ "@xylabs/tsconfig": "~8.6.2",
48
+ "async-mutex": "~0.5.0",
49
+ "browserslist": "~4.28.4",
50
+ "eslint": "~10.6.0",
51
+ "eslint-import-resolver-typescript": "~4.4.5",
52
+ "typescript": "~6.0.3",
53
+ "zod": "~4.4.3"
47
54
  },
48
55
  "peerDependencies": {
49
- "@ariestools/sdk": "^7.0.4",
50
- "@bitauth/libauth": "~3.0",
51
- "@noble/post-quantum": "~0.6.1",
52
- "@opentelemetry/api": "^1.9",
53
- "@opentelemetry/sdk-trace-base": "^2.7",
54
- "@scure/base": "~2.2",
55
- "@scure/bip39": "~2.2",
56
- "@xylabs/geo": "^7.0",
57
- "@xylabs/threads": "^7.0",
58
- "ajv": "^8.20",
59
- "async-mutex": "^0.5",
60
- "debug": "^4.4",
61
- "ethers": "^6.16",
62
- "hash-wasm": "~4.12",
63
- "idb": "^8.0",
64
- "observable-fns": "^0.6",
65
- "zod": "^4.4"
56
+ "@ariestools/sdk": "^7.0.8",
57
+ "@bitauth/libauth": "^3.0.0",
58
+ "@opentelemetry/api": "^1.9.1",
59
+ "@opentelemetry/sdk-trace-base": "^2.9.0",
60
+ "@scure/base": "^2.2.0",
61
+ "async-mutex": "^0.5.0",
62
+ "zod": "^4.4.3"
66
63
  },
67
64
  "engines": {
68
65
  "node": "^24"