@xyo-network/wallet 5.3.20 → 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/wallet",
3
- "version": "5.3.20",
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,28 +30,40 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
39
  "@scure/bip39": "~2.0.1",
40
- "@xyo-network/account": "~5.3.20",
41
- "@xyo-network/account-model": "~5.3.20",
42
- "@xyo-network/key-model": "~5.3.20",
43
- "@xyo-network/wallet-model": "~5.3.20"
40
+ "@xyo-network/account": "~5.3.24",
41
+ "@xyo-network/account-model": "~5.3.24",
42
+ "@xyo-network/key-model": "~5.3.24",
43
+ "@xyo-network/wallet-model": "~5.3.24"
44
44
  },
45
45
  "devDependencies": {
46
- "@xylabs/sdk-js": "^5.0.90",
47
- "@xylabs/ts-scripts-common": "~7.5.6",
48
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
49
- "@xylabs/tsconfig": "~7.5.6",
50
- "@xylabs/vitest-matchers": "~5.0.90",
46
+ "@opentelemetry/api": "^1.9.1",
47
+ "@scure/bip39": "~2.0.1",
48
+ "@types/node": "^25.5.0",
49
+ "@xylabs/sdk-js": "^5.0.93",
50
+ "@xylabs/ts-scripts-common": "~7.6.16",
51
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
52
+ "@xylabs/tsconfig": "~7.6.16",
53
+ "@xylabs/vitest-matchers": "~5.0.93",
54
+ "acorn": "^8.16.0",
55
+ "axios": "^1.14.0",
56
+ "esbuild": "^0.28.0",
51
57
  "ethers": "^6.16.0",
58
+ "tslib": "^2.8.1",
52
59
  "typescript": "~5.9.3",
60
+ "vite": "^8.0.3",
53
61
  "vitest": "~4.1.2",
54
- "zod": "^4.3.6"
62
+ "zod": "^4.3.6",
63
+ "@xyo-network/account-model": "~5.3.24",
64
+ "@xyo-network/key-model": "~5.3.24",
65
+ "@xyo-network/account": "~5.3.24",
66
+ "@xyo-network/wallet-model": "~5.3.24"
55
67
  },
56
68
  "peerDependencies": {
57
69
  "@xylabs/sdk-js": "^5",
@@ -62,4 +74,4 @@
62
74
  "publishConfig": {
63
75
  "access": "public"
64
76
  }
65
- }
77
+ }
package/src/HDWallet.ts DELETED
@@ -1,167 +0,0 @@
1
- import { generateMnemonic } from '@scure/bip39'
2
- import { wordlist as englishWordlist } from '@scure/bip39/wordlists/english.js'
3
- import {
4
- Address, asAddress, assertEx,
5
- globallyUnique,
6
- Hex, hexFromHexString, staticImplements,
7
- toUint8Array,
8
- } from '@xylabs/sdk-js'
9
- import { Account, PrivateKey } from '@xyo-network/account'
10
- import {
11
- AccountConfig,
12
- isMnemonicInitializationConfig,
13
- isPhraseInitializationConfig,
14
- isPrivateKeyInitializationConfig,
15
- } from '@xyo-network/account-model'
16
- import type { PrivateKeyInstance } from '@xyo-network/key-model'
17
- import { WalletInstance, WalletStatic } from '@xyo-network/wallet-model'
18
- import {
19
- defaultPath, HDNodeWallet, Mnemonic,
20
- } from 'ethers'
21
-
22
- @staticImplements<WalletStatic>()
23
- export class HDWallet extends Account implements WalletInstance {
24
- static override readonly uniqueName = globallyUnique('HDWallet', HDWallet, 'xyo')
25
- protected static override _addressMap: Record<Address, WeakRef<WalletInstance>> = {}
26
-
27
- protected readonly node: HDNodeWallet
28
-
29
- constructor(
30
- key: symbol,
31
- node: HDNodeWallet,
32
- privateKey: PrivateKeyInstance,
33
- ) {
34
- super(key, privateKey)
35
- this.node = node
36
- }
37
-
38
- override get address(): Address {
39
- return asAddress(hexFromHexString(this.node.address, { prefix: false }), true)
40
- }
41
-
42
- override get addressBytes(): ArrayBufferLike {
43
- return toUint8Array(this.address, undefined, 16).buffer
44
- }
45
-
46
- get chainCode(): string {
47
- return this.node.chainCode
48
- }
49
-
50
- get depth(): number {
51
- return this.node.depth
52
- }
53
-
54
- get extendedKey(): string {
55
- return this.node.extendedKey
56
- }
57
-
58
- get fingerprint(): string {
59
- return this.node.fingerprint
60
- }
61
-
62
- get index(): number {
63
- return this.node.index
64
- }
65
-
66
- get mnemonic(): Mnemonic | null {
67
- return this.node.mnemonic
68
- }
69
-
70
- get parentFingerprint(): string {
71
- return this.node.parentFingerprint
72
- }
73
-
74
- get path(): string | null {
75
- return this.node.path
76
- }
77
-
78
- get privateKey(): Hex {
79
- return this.node.privateKey.toLowerCase() as Hex
80
- }
81
-
82
- get publicKey(): Hex {
83
- return this.node.publicKey.toLowerCase() as Hex
84
- }
85
-
86
- static override async create(opts?: AccountConfig): Promise<WalletInstance> {
87
- if (isPhraseInitializationConfig(opts)) {
88
- return await this.fromPhrase(opts.phrase)
89
- }
90
- if (isMnemonicInitializationConfig(opts)) {
91
- return await this.fromPhrase(opts.mnemonic, opts.path)
92
- }
93
- if (isPrivateKeyInitializationConfig(opts)) {
94
- throw new Error('Invalid initialization config. from privateKey not supported. Use Account.fromPrivateKey instead.')
95
- }
96
- throw new Error('Invalid initialization config')
97
- }
98
-
99
- static async createFromNode(node: HDNodeWallet, previousHash?: string): Promise<WalletInstance> {
100
- return await this.createFromNodeInternal(node, previousHash)
101
- }
102
-
103
- static async fromExtendedKey(key: string): Promise<WalletInstance> {
104
- const node = HDNodeWallet.fromExtendedKey(key)
105
- /* TODO: Handle HDNodeVoidWallet */
106
- return await HDWallet.createFromNode(node as HDNodeWallet)
107
- }
108
-
109
- static async fromMnemonic(mnemonic: Mnemonic, path: string = defaultPath): Promise<WalletInstance> {
110
- const node = HDNodeWallet.fromMnemonic(mnemonic, path)
111
- const createdWallet = await this.createFromNodeInternal(node)
112
- return this.getCachedWalletOrCacheNewWallet(createdWallet)
113
- }
114
-
115
- static async fromPhrase(phrase: string, path: string = defaultPath): Promise<WalletInstance> {
116
- return await this.fromMnemonic(Mnemonic.fromPhrase(phrase), path)
117
- }
118
-
119
- static async fromSeed(seed: string | ArrayBufferLike): Promise<WalletInstance> {
120
- const node = HDNodeWallet.fromSeed(toUint8Array(seed))
121
- const createdWallet = await this.createFromNodeInternal(node)
122
- return this.getCachedWalletOrCacheNewWallet(createdWallet)
123
- }
124
-
125
- static generateMnemonic(wordlist: string[] = englishWordlist, strength: number = 256): string {
126
- return generateMnemonic(wordlist, strength)
127
- }
128
-
129
- static override async random(): Promise<WalletInstance> {
130
- return await this.fromMnemonic(Mnemonic.fromPhrase(HDWallet.generateMnemonic()))
131
- }
132
-
133
- protected static async createFromNodeInternal(node: HDNodeWallet, previousHash?: string): Promise<WalletInstance> {
134
- const privateKey = toUint8Array(node.privateKey.replace('0x', ''))
135
- assertEx(privateKey.length === 32, () => `Private key must be 32 bytes [${privateKey?.length}]`)
136
- const newWallet = await new HDWallet(Account._protectedConstructorKey, node, await PrivateKey.create(privateKey.buffer)).loadPreviousHash(previousHash)
137
- return HDWallet._addressMap[newWallet.address]?.deref() ?? newWallet
138
- }
139
-
140
- protected static getCachedWalletOrCacheNewWallet(createdWallet: WalletInstance): WalletInstance {
141
- const existingWallet = this._addressMap[createdWallet.address]?.deref()
142
- if (existingWallet) {
143
- return existingWallet
144
- }
145
- const ref = new WeakRef(createdWallet)
146
- this._addressMap[createdWallet.address] = ref
147
- return createdWallet
148
- }
149
-
150
- async derivePath(path: string): Promise<WalletInstance> {
151
- // if an absolute path, check if it matches the parent root and work with it
152
- if (path.startsWith('m/')) {
153
- const parentPath = this.path
154
- if (parentPath !== null && path.startsWith(parentPath)) {
155
- const childPath = path.slice(parentPath.length + 1)
156
- return await HDWallet.createFromNode(this.node.derivePath(childPath))
157
- }
158
- throw new Error(`Invalid absolute path ${path} for wallet with path ${parentPath}`)
159
- }
160
- return await HDWallet.createFromNode(this.node.derivePath(path))
161
- }
162
-
163
- neuter: () => HDWallet = () => {
164
- this.node.neuter()
165
- return this
166
- }
167
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './HDWallet.ts'