@xyo-network/xl1-wrappers 1.26.12 → 1.26.14

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,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/xl1-wrappers",
4
- "version": "1.26.12",
4
+ "version": "1.26.14",
5
5
  "description": "XYO Layer One SDK Wrappers",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -23,7 +23,6 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/neutral/index.d.ts",
26
- "source": "./src/index.ts",
27
26
  "default": "./dist/neutral/index.mjs"
28
27
  },
29
28
  "./package.json": "./package.json"
@@ -33,31 +32,40 @@
33
32
  "types": "./dist/neutral/index.d.ts",
34
33
  "files": [
35
34
  "dist",
36
- "src",
37
35
  "!**/*.bench.*",
38
36
  "!**/*.spec.*",
39
37
  "!**/*.test.*",
40
38
  "README.md"
41
39
  ],
42
40
  "dependencies": {
43
- "@xyo-network/xl1-protocol-lib": "~1.26.12",
44
- "@xyo-network/xl1-protocol-sdk": "~1.26.12",
45
- "@xyo-network/xl1-validation": "~1.26.12"
41
+ "@xyo-network/xl1-protocol-lib": "~1.26.14",
42
+ "@xyo-network/xl1-protocol-sdk": "~1.26.14",
43
+ "@xyo-network/xl1-validation": "~1.26.14"
46
44
  },
47
45
  "devDependencies": {
46
+ "@metamask/providers": "^22.1.1",
48
47
  "@opentelemetry/api": "^1.9.1",
49
48
  "@types/node": "^25.5.0",
50
- "@xylabs/sdk-js": "^5.0.91",
51
- "@xylabs/ts-scripts-common": "~7.6.2",
52
- "@xylabs/ts-scripts-yarn3": "~7.6.2",
53
- "@xylabs/tsconfig": "~7.6.2",
54
- "@xyo-network/sdk-js": "^5.3.20",
49
+ "@xylabs/geo": "^5.0.93",
50
+ "@xylabs/sdk-js": "^5.0.93",
51
+ "@xylabs/ts-scripts-common": "~7.6.18",
52
+ "@xylabs/ts-scripts-pnpm": "~7.6.18",
53
+ "@xylabs/tsconfig": "~7.6.18",
54
+ "@xyo-network/sdk-js": "^5.3.25",
55
+ "acorn": "^8.16.0",
55
56
  "ajv": "^8.18.0",
56
- "axios": "^1.13.6",
57
+ "axios": "^1.14.0",
58
+ "esbuild": "^0.28.0",
57
59
  "ethers": "^6.16.0",
60
+ "firebase": "^12.11.0",
61
+ "lru-cache": "^11.2.7",
62
+ "mapbox-gl": "^3.21.0",
63
+ "mongodb": "^7.1.1",
64
+ "tslib": "^2.8.1",
58
65
  "typescript": "~5.9.3",
59
- "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
66
+ "vite": "^8.0.3",
60
67
  "vitest": "~4.1.2",
68
+ "webextension-polyfill": "^0.12.0",
61
69
  "zod": "~4.3.6"
62
70
  },
63
71
  "peerDependencies": {
@@ -68,14 +76,13 @@
68
76
  "axios": "^1",
69
77
  "ethers": "^6",
70
78
  "mongodb": "^6 || ^7",
71
- "typescript": ">=4.9.5",
72
79
  "zod": "^4"
73
80
  },
74
81
  "engines": {
75
- "node": ">=22.3 <23"
82
+ "node": ">=22.3"
76
83
  },
77
84
  "engineStrict": true,
78
85
  "publishConfig": {
79
86
  "access": "public"
80
87
  }
81
- }
88
+ }
package/src/Address.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { Address, Promisable } from '@xylabs/sdk-js'
2
- import { isAddress } from '@xylabs/sdk-js'
3
- import type { AddressInstance } from '@xyo-network/xl1-protocol-sdk'
4
-
5
- import { BaseWrapper } from './Base.ts'
6
-
7
- /** Wrapper around an Ethereum-style address with validation. */
8
- export class AddressWrapper extends BaseWrapper<Address> implements AddressInstance {
9
- get address(): Address {
10
- return this.value
11
- }
12
-
13
- static override validateValue(address: unknown): Promisable<Error[]> {
14
- return isAddress(address) ? [] : [new Error('Invalid address')]
15
- }
16
-
17
- override async validate(): Promise<Error[]> {
18
- return await AddressWrapper.validateValue(this.address)
19
- }
20
- }
@@ -1,19 +0,0 @@
1
- import type { Promisable } from '@xylabs/sdk-js'
2
- import type { XL1AmountInstance } from '@xyo-network/xl1-protocol-lib'
3
- import type {
4
- AddressStateInstance,
5
- BlockWindowInstance,
6
- } from '@xyo-network/xl1-protocol-sdk'
7
-
8
- import { AddressWrapper } from './Address.ts'
9
-
10
- /** Wrapper for an address with associated block window and balance state. */
11
- export class AddressStateWrapper extends AddressWrapper implements AddressStateInstance {
12
- get blockWindow(): BlockWindowInstance {
13
- throw new Error('Method [blockWindow] not implemented.')
14
- }
15
-
16
- balance(): Promisable<[XL1AmountInstance, BlockWindowInstance]> {
17
- throw new Error('Method [balance] not implemented.')
18
- }
19
- }
package/src/Base.ts DELETED
@@ -1,44 +0,0 @@
1
- import type { PromisableArray } from '@xylabs/sdk-js'
2
- import type { XyoConnection } from '@xyo-network/xl1-protocol-lib'
3
-
4
- /** Configuration for a base wrapper, providing a connection and a value to wrap. */
5
- export interface BaseWrapperConfig<T> {
6
- provider: XyoConnection
7
- value: T
8
- }
9
-
10
- /** Abstract base class for protocol value wrappers with validation support. */
11
- export class BaseWrapper<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>> {
12
- protected readonly config: Partial<C>
13
- protected readonly value: T
14
- protected constructor(value: T, config: Partial<C> = {}) {
15
- this.config = config
16
- this.value = value
17
- }
18
-
19
- get provider(): XyoConnection | undefined {
20
- return this.config.provider
21
- }
22
-
23
- static async create<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>>(value: T, config: Partial<C> = {}) {
24
- if ((await this.validateValue(value)).length > 0) {
25
- throw new Error(`Invalid value for ${this.constructor.name}: ${value}`)
26
- }
27
- if ((await this.validateConfig(config)).length > 0) {
28
- throw new Error(`Invalid config for ${this.constructor.name}: ${config}`)
29
- }
30
- return new this<T>(value, config)
31
- }
32
-
33
- static validateConfig(_config: unknown): PromisableArray<Error> {
34
- return []
35
- }
36
-
37
- static validateValue(_value: unknown): PromisableArray<Error> {
38
- return []
39
- }
40
-
41
- validate(): PromisableArray<Error> {
42
- return []
43
- }
44
- }
@@ -1,44 +0,0 @@
1
- import type { Hash, Promisable } from '@xylabs/sdk-js'
2
- import type { HydratedBlock } from '@xyo-network/xl1-protocol-lib'
3
- import type { BlockWindowInstance } from '@xyo-network/xl1-protocol-sdk'
4
-
5
- /** Navigable store of hydrated blocks within a block window range. */
6
- export interface HydratedBlockRangeStore extends BlockWindowInstance {
7
- first(): Promisable<HydratedBlock>
8
- fromHash(hash: Hash): Promisable<HydratedBlock>
9
- fromNumber(number: number): Promisable<HydratedBlock>
10
- last(): Promisable<HydratedBlock>
11
- next(): Promisable<HydratedBlock>
12
- next(count: number): Promisable<HydratedBlock[]>
13
- prev(): Promisable<HydratedBlock>
14
- prev(count: number): Promisable<HydratedBlock[]>
15
- }
16
-
17
- /** Wrapper that exposes block window properties from a HydratedBlockRangeStore. */
18
- export class BlockWindowWrapper implements BlockWindowInstance {
19
- private _store: HydratedBlockRangeStore
20
-
21
- constructor(store: HydratedBlockRangeStore) {
22
- this._store = store
23
- }
24
-
25
- get count() {
26
- return this._store.count
27
- }
28
-
29
- get numberRange() {
30
- return this._store.numberRange
31
- }
32
-
33
- get range() {
34
- return this._store.range
35
- }
36
-
37
- static validate(_store: HydratedBlockRangeStore): Promisable<Error[]> {
38
- return [] // TODO: Implement validation logic
39
- }
40
-
41
- async validate(): Promise<Error[]> {
42
- return await BlockWindowWrapper.validate(this._store)
43
- }
44
- }
@@ -1,21 +0,0 @@
1
- import type { Address, Promisable } from '@xylabs/sdk-js'
2
-
3
- import type { HydratedBlockRangeStore } from './BlockWindow.ts'
4
-
5
- /** Interface for querying address balances within a block window. */
6
- export interface BlockWindowBalanceCacheInstance {
7
- balance(address: Address): Promisable<bigint>
8
- }
9
-
10
- /** Cache for looking up account balances within a hydrated block range. */
11
- export class BlockWindowBalanceCache implements BlockWindowBalanceCacheInstance {
12
- private _store: HydratedBlockRangeStore
13
-
14
- constructor(store: HydratedBlockRangeStore) {
15
- this._store = store
16
- }
17
-
18
- balance(_address: Address): Promisable<bigint> {
19
- throw new Error('Method [balance] not implemented.')
20
- }
21
- }
package/src/Fees.ts DELETED
@@ -1,55 +0,0 @@
1
- import type { Hex, Promisable } from '@xylabs/sdk-js'
2
- import { hexToBigInt } from '@xylabs/sdk-js'
3
- import type { TransactionFeesBigInt, TransactionFeesHex } from '@xyo-network/xl1-protocol-lib'
4
- import { AttoXL1 } from '@xyo-network/xl1-protocol-lib'
5
- import type { TransactionFeesInstance } from '@xyo-network/xl1-protocol-sdk'
6
-
7
- function parseHexOrBigInt(value: Hex | bigint) {
8
- return AttoXL1((typeof value === 'bigint' ? value : hexToBigInt(value)))
9
- }
10
-
11
- /** Wrapper for transaction fee fields (base, gasLimit, gasPrice, priority) with validation. */
12
- export class FeesWrapper implements TransactionFeesInstance {
13
- base: AttoXL1
14
- gasLimit: AttoXL1
15
- gasPrice: AttoXL1
16
- priority: AttoXL1
17
-
18
- constructor({
19
- base, gasLimit, gasPrice, priority,
20
- }: TransactionFeesHex | TransactionFeesBigInt) {
21
- this.base = parseHexOrBigInt(base)
22
- this.gasLimit = parseHexOrBigInt(gasLimit)
23
- this.gasPrice = parseHexOrBigInt(gasPrice)
24
- this.priority = parseHexOrBigInt(priority)
25
- }
26
-
27
- static validate({
28
- base, gasLimit, gasPrice, priority,
29
- }: TransactionFeesHex | TransactionFeesBigInt): Promisable<Error[]> {
30
- const errors: Error[] = []
31
- const baseValue = parseHexOrBigInt(base)
32
- const gasLimitValue = parseHexOrBigInt(gasLimit)
33
- const gasPriceValue = parseHexOrBigInt(gasPrice)
34
- const priorityValue = parseHexOrBigInt(priority)
35
- if (baseValue <= 0n) {
36
- errors.push(new Error('Base fee cannot be negative or zero'))
37
- }
38
- if (gasLimitValue < 0n) {
39
- errors.push(new Error('Gas limit cannot be negative'))
40
- }
41
- if (gasPriceValue < 0n) {
42
- errors.push(new Error('Gas price cannot be negative'))
43
- }
44
- if (priorityValue < 0n) {
45
- errors.push(new Error('Priority cannot be negative'))
46
- }
47
- return errors
48
- }
49
-
50
- async validate(): Promise<Error[]> {
51
- return await FeesWrapper.validate({
52
- base: this.base, gasLimit: this.gasLimit, gasPrice: this.gasPrice, priority: this.priority,
53
- })
54
- }
55
- }
package/src/Signature.ts DELETED
@@ -1,27 +0,0 @@
1
- import type {
2
- Address, Hash, Hex,
3
- } from '@xylabs/sdk-js'
4
- import { toArrayBuffer } from '@xylabs/sdk-js'
5
- import { BoundWitnessValidator } from '@xyo-network/sdk-js'
6
- import type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'
7
-
8
- /** Wrapper for cryptographic signatures with validation against BoundWitness hashes. */
9
- export class SignatureWrapper implements SignatureInstance {
10
- address: Address
11
- hash: Hash
12
- signature: Hex
13
-
14
- constructor(signature: Hex, address: Address, hash: Hash) {
15
- this.signature = signature
16
- this.address = address
17
- this.hash = hash
18
- }
19
-
20
- static async validate(hash: Hash, address: Address, signature: Hex): Promise<Error[]> {
21
- return await BoundWitnessValidator.validateSignature(toArrayBuffer(hash), toArrayBuffer(address), toArrayBuffer(signature))
22
- }
23
-
24
- async validate(): Promise<Error[]> {
25
- return await SignatureWrapper.validate(this.hash, this.address, this.signature)
26
- }
27
- }
@@ -1,11 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { BaseWrapperConfig } from '../Base.ts'
4
- import { BaseWrapper } from '../Base.ts'
5
-
6
- /** Wrapper for a chain identifier address. */
7
- export class ChainWrapper extends BaseWrapper<Address, BaseWrapperConfig<Address>> {
8
- get id(): Address {
9
- return this.value
10
- }
11
- }
@@ -1 +0,0 @@
1
- export * from './chain.ts'
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './Base.ts'
2
- export * from './chain/index.ts'
3
- export * from './Fees.ts'
4
- export * from './lib/index.ts'
5
- export * from './Signature.ts'
6
- export * from './transaction/index.ts'
@@ -1,18 +0,0 @@
1
- import { asHex } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/sdk-js'
3
- import { PayloadBuilder } from '@xyo-network/sdk-js'
4
- import type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'
5
-
6
- import { SignatureWrapper } from '../Signature.ts'
7
-
8
- /** Creates SignatureWrapper instances for each signature in a BoundWitness. */
9
- export const createSignatureWrappers = async (bw: BoundWitness): Promise<SignatureInstance[]> => {
10
- const signatures: SignatureInstance[] = []
11
- const hash = await PayloadBuilder.dataHash(bw)
12
- for (let i = 0; i < bw.$signatures.length; i++) {
13
- signatures.push(
14
- new SignatureWrapper(asHex(bw.$signatures[i], true), bw.addresses[i], hash),
15
- )
16
- }
17
- return signatures
18
- }
package/src/lib/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './createSignatureWrappers.ts'
@@ -1,177 +0,0 @@
1
- import type { Hash, Hex } from '@xylabs/sdk-js'
2
- import { hexToBigInt, isDefined } from '@xylabs/sdk-js'
3
- import type {
4
- Payload, Schema,
5
- WithHashMeta,
6
- } from '@xyo-network/sdk-js'
7
- import { PayloadBuilder } from '@xyo-network/sdk-js'
8
- import type {
9
- AllowedBlockPayload, BaseContext, HydratedTransactionWithHashMeta, Transfer,
10
- } from '@xyo-network/xl1-protocol-lib'
11
- import {
12
- isAllowedBlockPayload, isTransfer, XYO_ZERO_ADDRESS,
13
- } from '@xyo-network/xl1-protocol-lib'
14
- import type {
15
- HydratedTransactionInstance, SignatureInstance,
16
- TransactionFeesInstance,
17
- } from '@xyo-network/xl1-protocol-sdk'
18
- import {
19
- transactionRequiredGas, tryExtractElevatedHashes, tryExtractElevatedHashesFromScript,
20
- } from '@xyo-network/xl1-protocol-sdk'
21
- import { validateTransaction } from '@xyo-network/xl1-validation'
22
-
23
- import { FeesWrapper } from '../Fees.ts'
24
- import { createSignatureWrappers } from '../lib/index.ts'
25
-
26
- const sumTransfers = (payload: Transfer) => {
27
- let total = 0n
28
- for (let i of Object.values(payload.transfers)) {
29
- total += hexToBigInt(i ?? '00' as Hex)
30
- }
31
- return total
32
- }
33
-
34
- /** Context for hydrated transaction wrapper operations. */
35
- export interface HydratedTransactionWrapperContext extends BaseContext {
36
-
37
- }
38
-
39
- /** Wrapper for a hydrated transaction providing access to payloads, signatures, fees, and validation. */
40
- export class HydratedTransactionWrapper<T extends HydratedTransactionWithHashMeta> implements HydratedTransactionInstance<T> {
41
- data: T
42
- fees: TransactionFeesInstance
43
-
44
- protected context: HydratedTransactionWrapperContext
45
- protected payloadsCache: WithHashMeta<AllowedBlockPayload & T[1][number]>[] = []
46
-
47
- private _signatureCache: SignatureInstance[] = []
48
-
49
- protected constructor(data: T, context?: HydratedTransactionWrapperContext) {
50
- this.context = context ?? { singletons: {} }
51
- this.data = data
52
- this.fees = new FeesWrapper(
53
- this.boundWitness.fees,
54
- )
55
- }
56
-
57
- get boundWitness(): T[0] {
58
- return this.data[0]
59
- }
60
-
61
- get elevatedPayloadCount(): number {
62
- const { script } = this.data[0]
63
- return script ? tryExtractElevatedHashesFromScript(script).length : 0
64
- }
65
-
66
- get elevatedPayloads() {
67
- return tryExtractElevatedHashes(this.data) as WithHashMeta<AllowedBlockPayload & T[1][number]>[]
68
- }
69
-
70
- get externalPayloads(): Record<Hash, Schema | Payload> {
71
- const allPayloads = this.payloads
72
- const external: Record<Hash, Schema | Payload> = {}
73
- for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {
74
- const payloadHash = this.boundWitness.payload_hashes[i]
75
- const payload = allPayloads.find(p => p._hash === payloadHash)
76
- external[payloadHash] = isDefined(payload) ? payload : this.boundWitness.payload_schemas[i]
77
- }
78
- return external
79
- }
80
-
81
- get from() {
82
- return this.data[0].from
83
- }
84
-
85
- get payloadCount(): number {
86
- return this.payloadsCache.length
87
- }
88
-
89
- get payloads(): WithHashMeta<WithHashMeta<T[1][number]>>[] {
90
- return [...this.payloadsCache]
91
- }
92
-
93
- get privateExternalPayloads(): Record<Hash, Schema> {
94
- const allPayloads = this.payloads
95
- const missing: Record<Hash, Schema> = {}
96
- for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {
97
- const payloadHash = this.boundWitness.payload_hashes[i]
98
- if (!allPayloads.some(p => p._hash === payloadHash)) {
99
- missing[payloadHash] = this.boundWitness.payload_schemas[i]
100
- }
101
- }
102
- return missing
103
- }
104
-
105
- // list all the payloads that are included in the transaction and are not elevated and found in the hydration
106
- get publicExternalPayloads(): Payload[] {
107
- const allPayloads = this.payloads
108
- const elevatedPayloads = this.elevatedPayloads
109
- return allPayloads.filter(p => !elevatedPayloads.some(ep => ep._hash === p._hash))
110
- }
111
-
112
- get signatureCount(): number {
113
- return this._signatureCache.length
114
- }
115
-
116
- get signatures(): SignatureInstance[] {
117
- return [...this._signatureCache]
118
- }
119
-
120
- static async parse<T extends HydratedTransactionWithHashMeta>(transaction: T, validate = false): Promise<HydratedTransactionInstance<[T[0],
121
- T[1][number][]]>> {
122
- const wrapper = new HydratedTransactionWrapper<T>(
123
- transaction,
124
- )
125
- const parsed = await wrapper.parse()
126
- if (validate) {
127
- const errors = await wrapper.validate()
128
- if (errors.length > 0) {
129
- throw new Error(`Block validation failed: ${errors.join(', ')}`)
130
- }
131
- }
132
- return parsed
133
- }
134
-
135
- elevatedPayload(index: number): WithHashMeta<AllowedBlockPayload & T[1][number]> | undefined {
136
- return this.elevatedPayloads.at(index)
137
- }
138
-
139
- gasRequired(): bigint {
140
- return transactionRequiredGas(this.data)
141
- }
142
-
143
- payload(index: number) {
144
- return this.payloads.at(index) as WithHashMeta<AllowedBlockPayload & T[1][number]>
145
- }
146
-
147
- reward(): bigint {
148
- return this.payloadsCache.reduce((acc: bigint, payload) => acc + (
149
- isTransfer(payload)
150
- ? payload.from === XYO_ZERO_ADDRESS
151
- ? sumTransfers(payload)
152
- : 0n
153
- : 0n), 0n)
154
- }
155
-
156
- signature(index: number): SignatureInstance | undefined {
157
- return this._signatureCache[index]
158
- }
159
-
160
- async validate(): Promise<Error[]> {
161
- const errors: Error[] = [...(await Promise.all(this._signatureCache.map(signature => signature.validate()))).flat(),
162
- ...(await validateTransaction({ ...this.context, chainId: this.data[0].chain }, this.data))]
163
- return errors
164
- }
165
-
166
- protected async parse(validate = false): Promise<HydratedTransactionInstance<[WithHashMeta<T[0]>, WithHashMeta<T[1][number]>[]]>> {
167
- const transactionPayloads = (await PayloadBuilder.addHashMeta(this.data[1])).filter(isAllowedBlockPayload)
168
- this._signatureCache = await createSignatureWrappers(this.data[0])
169
- for (const payload of transactionPayloads) {
170
- this.payloadsCache.push(payload)
171
- }
172
- if (validate) {
173
- await this.validate()
174
- }
175
- return this
176
- }
177
- }
@@ -1 +0,0 @@
1
- export * from './HydratedTransaction.ts'