@xyo-network/elliptic 5.3.22 → 5.3.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/elliptic",
3
- "version": "5.3.22",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,7 +30,6 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
35
  "!**/*.test.*",
@@ -38,26 +37,27 @@
38
37
  ],
39
38
  "dependencies": {
40
39
  "@bitauth/libauth": "~3.0.0",
41
- "@xyo-network/data": "~5.3.22",
42
- "@xyo-network/wasm": "~5.3.22",
43
- "async-mutex": "~0.5.0"
40
+ "async-mutex": "~0.5.0",
41
+ "@xyo-network/data": "~5.3.24",
42
+ "@xyo-network/wasm": "~5.3.24"
44
43
  },
45
44
  "devDependencies": {
45
+ "@bitauth/libauth": "~3.0.0",
46
46
  "@opentelemetry/api": "^1.9.1",
47
47
  "@types/node": "^25.5.0",
48
- "@xylabs/sdk-js": "^5.0.91",
49
- "@xylabs/ts-scripts-common": "~7.6.8",
50
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
51
- "@xylabs/tsconfig": "~7.6.8",
48
+ "@xylabs/sdk-js": "^5.0.93",
49
+ "@xylabs/ts-scripts-common": "~7.6.16",
50
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
51
+ "@xylabs/tsconfig": "~7.6.16",
52
52
  "acorn": "^8.16.0",
53
+ "async-mutex": "~0.5.0",
53
54
  "axios": "^1.14.0",
54
- "cosmiconfig": "^9.0.1",
55
- "esbuild": "^0.27.4",
56
- "eslint": "^10.1.0",
55
+ "esbuild": "^0.28.0",
57
56
  "ethers": "^6.16.0",
58
- "rollup": "^4.60.1",
59
57
  "typescript": "~5.9.3",
60
- "zod": "^4.3.6"
58
+ "zod": "^4.3.6",
59
+ "@xyo-network/data": "~5.3.24",
60
+ "@xyo-network/wasm": "~5.3.24"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@xylabs/sdk-js": "^5",
@@ -66,4 +66,4 @@
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  }
69
- }
69
+ }
package/src/Elliptic.ts DELETED
@@ -1,97 +0,0 @@
1
- import type { Secp256k1 } from '@bitauth/libauth'
2
- import { instantiateSecp256k1 } from '@bitauth/libauth'
3
- import {
4
- assertEx, toHex, toUint8Array,
5
- } from '@xylabs/sdk-js'
6
- import { Data } from '@xyo-network/data'
7
- import { WasmSupport } from '@xyo-network/wasm'
8
- import { Mutex } from 'async-mutex'
9
-
10
- const wasmSupportStatic = new WasmSupport(['bigInt', 'mutableGlobals', 'referenceTypes', 'saturatedFloatToInt', 'signExtensions', 'simd'])
11
- const recoveryIds = [0, 1, 2, 3] as const
12
-
13
- function compareArrayBuffers(b1: ArrayBufferLike, b2: ArrayBufferLike) {
14
- if (b1.byteLength !== b2.byteLength) {
15
- return false
16
- }
17
-
18
- const a1 = new Uint8Array(b1)
19
- const a2 = new Uint8Array(b2)
20
-
21
- for (let i = 0; i < b1.byteLength; i++) {
22
- if (a1[1] !== a2[1]) {
23
- return false
24
- }
25
- }
26
-
27
- return true
28
- }
29
-
30
- export class Elliptic {
31
- static readonly wasmSupport = wasmSupportStatic
32
- protected static _secp256k1: Secp256k1 | undefined
33
- private static _secp256k1Mutex = new Mutex()
34
-
35
- static addressFromPublicKey(key: ArrayBufferLike): ArrayBufferLike {
36
- return new Data(64, key).keccak256.slice(12)
37
- }
38
-
39
- static initialize() {
40
- return this.secp256k1()
41
- }
42
-
43
- static async publicKeyFromPrivateKey(privateKey: ArrayBufferLike, prefix = false): Promise<ArrayBufferLike> {
44
- const { derivePublicKeyUncompressed } = await this.secp256k1()
45
- if (BigInt(toHex(privateKey, { prefix: true })) === 0n) {
46
- throw new Error(`Invalid private key [${toHex(privateKey)}]`)
47
- }
48
- const derivedPublicKey = derivePublicKeyUncompressed(new Uint8Array(privateKey))
49
- const fullPublicKey = typeof derivedPublicKey === 'string' ? toUint8Array(derivedPublicKey) : derivedPublicKey
50
- return (prefix ? fullPublicKey : fullPublicKey.slice(1)).buffer
51
- }
52
-
53
- static ready() {
54
- return !!this._secp256k1
55
- }
56
-
57
- static async secp256k1(): Promise<Secp256k1> {
58
- return await this._secp256k1Mutex.runExclusive(async () => {
59
- if (this._secp256k1) return this._secp256k1
60
-
61
- await wasmSupportStatic.initialize()
62
- const secp256k1 = assertEx(await instantiateSecp256k1(), () => 'No Wasm Support')
63
- this._secp256k1 = secp256k1
64
- return secp256k1
65
- })
66
- }
67
-
68
- static async sign(hash: ArrayBufferLike, key: ArrayBufferLike) {
69
- const { signMessageHashCompact } = await this.secp256k1()
70
- const signature = signMessageHashCompact(new Uint8Array(key), toUint8Array(hash))
71
- return (typeof signature === 'string' ? toUint8Array(signature) : signature).buffer
72
- }
73
-
74
- static async verify(msg: ArrayBufferLike, signature: ArrayBufferLike, address: ArrayBufferLike) {
75
- const verifier = await this.secp256k1()
76
- if (verifier && this.wasmSupport.canUseWasm) {
77
- for (const recoveryId of recoveryIds) {
78
- try {
79
- const rawRecoveredPublicKey = verifier.recoverPublicKeyUncompressed(toUint8Array(signature), recoveryId, toUint8Array(msg))
80
- const recoveredPublicKey = (typeof rawRecoveredPublicKey === 'string' ? toUint8Array(rawRecoveredPublicKey) : rawRecoveredPublicKey).slice(1).buffer
81
- const recoveredAddress = this.addressFromPublicKey(recoveredPublicKey)
82
- if (compareArrayBuffers(address, recoveredAddress)) {
83
- return true
84
- }
85
- } catch (ex) {
86
- const error = ex as Error
87
- console.log(error.message)
88
- console.log(error.stack)
89
- continue
90
- }
91
- }
92
- return false
93
- }
94
- // In all failure modes default to the JS implementation
95
- throw new Error('No wasm support')
96
- }
97
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Elliptic.ts'