@xyo-network/xl1-rpc 1.8.2 → 1.8.3
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/dist/neutral/index.mjs +11 -72
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/provider/provider/index.d.ts +0 -2
- package/dist/neutral/provider/provider/index.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/PostMessageRpcTransport.d.ts +1 -0
- package/dist/neutral/transport/post-message/PostMessageRpcTransport.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/SessionEnvelope.d.ts +1 -0
- package/dist/neutral/transport/post-message/SessionEnvelope.d.ts.map +1 -1
- package/dist/neutral/transport/post-message/helpers.d.ts +3 -0
- package/dist/neutral/transport/post-message/helpers.d.ts.map +1 -1
- package/dist/node/index-node.mjs +11 -72
- package/dist/node/index-node.mjs.map +1 -1
- package/dist/node/provider/provider/index.d.ts +0 -2
- package/dist/node/provider/provider/index.d.ts.map +1 -1
- package/dist/node/transport/post-message/PostMessageRpcTransport.d.ts +1 -0
- package/dist/node/transport/post-message/PostMessageRpcTransport.d.ts.map +1 -1
- package/dist/node/transport/post-message/SessionEnvelope.d.ts +1 -0
- package/dist/node/transport/post-message/SessionEnvelope.d.ts.map +1 -1
- package/dist/node/transport/post-message/helpers.d.ts +3 -0
- package/dist/node/transport/post-message/helpers.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/provider/provider/index.ts +0 -2
- package/src/transport/post-message/PostMessageRpcTransport.ts +1 -0
- package/src/transport/post-message/SessionEnvelope.ts +1 -0
- package/src/transport/post-message/helpers.ts +3 -0
- package/dist/neutral/provider/provider/confirmSubmittedTransaction.d.ts +0 -21
- package/dist/neutral/provider/provider/confirmSubmittedTransaction.d.ts.map +0 -1
- package/dist/neutral/provider/provider/confirmTransaction.d.ts +0 -4
- package/dist/neutral/provider/provider/confirmTransaction.d.ts.map +0 -1
- package/dist/node/provider/provider/confirmSubmittedTransaction.d.ts +0 -21
- package/dist/node/provider/provider/confirmSubmittedTransaction.d.ts.map +0 -1
- package/dist/node/provider/provider/confirmTransaction.d.ts +0 -4
- package/dist/node/provider/provider/confirmTransaction.d.ts.map +0 -1
- package/src/provider/provider/confirmSubmittedTransaction.ts +0 -55
- package/src/provider/provider/confirmTransaction.ts +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/transport/post-message/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/transport/post-message/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,oEAAoE;AACpE,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,oEAAoE;AACpE,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,oEAAoE;AAEpE,eAAO,MAAM,UAAU,GAAI,MAAM,GAAG,KAAG,IAAI,IAAI,QAO9C,CAAA"}
|
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-rpc",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.3",
|
|
5
5
|
"description": "XYO Layer One API",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"@metamask/utils": "^11.4.2",
|
|
62
62
|
"@xylabs/assert": "^4.15.0",
|
|
63
63
|
"@xylabs/axios": "^4.15.0",
|
|
64
|
-
"@xylabs/delay": "^4.15.0",
|
|
65
64
|
"@xylabs/hex": "^4.15.0",
|
|
66
65
|
"@xylabs/object": "^4.15.0",
|
|
67
66
|
"@xylabs/promise": "^4.15.0",
|
|
@@ -76,8 +75,8 @@
|
|
|
76
75
|
"@xyo-network/payload-model": "^4.3.0",
|
|
77
76
|
"@xyo-network/payload-wrapper": "^4.3.0",
|
|
78
77
|
"@xyo-network/xl1-protocol": "^1.7.33",
|
|
79
|
-
"@xyo-network/xl1-protocol-sdk": "^1.8.
|
|
80
|
-
"@xyo-network/xl1-wrappers": "^1.8.
|
|
78
|
+
"@xyo-network/xl1-protocol-sdk": "^1.8.3",
|
|
79
|
+
"@xyo-network/xl1-wrappers": "^1.8.3",
|
|
81
80
|
"axios": "^1.11.0",
|
|
82
81
|
"uuid": "^11.1.0",
|
|
83
82
|
"zod": "^3.25.76"
|
|
@@ -10,6 +10,7 @@ import type { JsonRpcRequestWithId } from './helpers.ts'
|
|
|
10
10
|
import { isRpcError } from './helpers.ts'
|
|
11
11
|
import { buildSessionMessageRequest } from './SessionEnvelope.ts'
|
|
12
12
|
|
|
13
|
+
/** @deprecated - now part of a client gateway */
|
|
13
14
|
export class PostMessageRpcTransport<T extends RpcSchemaMap = RpcSchemaMap> implements RpcTransport<T> {
|
|
14
15
|
protected readonly destination?: string
|
|
15
16
|
protected readonly schemas: T
|
|
@@ -8,6 +8,7 @@ export interface SessionMessageEnvelope<T extends JsonValue> {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/** Only intended for web pages where the xyo global object was injected */
|
|
11
|
+
/** @deprecated - rely on the postMessageBus to handle this for you */
|
|
11
12
|
export const buildSessionMessageRequest = <T extends JsonRpcRequest>(data: T, destination?: string) => {
|
|
12
13
|
const request: SessionMessageEnvelope<T> = {
|
|
13
14
|
data,
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { JsonRpcRequest } from '@metamask/utils'
|
|
2
2
|
import type { JsonObject } from '@xylabs/object'
|
|
3
3
|
|
|
4
|
+
/** @deprecated - no longer part of the public rpc implementation */
|
|
4
5
|
export type JsonRpcRequestWithId = JsonRpcRequest & {
|
|
5
6
|
id: string
|
|
6
7
|
}
|
|
7
8
|
|
|
9
|
+
/** @deprecated - no longer part of the public rpc implementation */
|
|
8
10
|
export interface RpcError extends JsonObject {
|
|
9
11
|
error: boolean
|
|
10
12
|
message: string
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
/** @deprecated - no longer part of the public rpc implementation */
|
|
13
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
17
|
export const isRpcError = (data: any): data is RpcError => {
|
|
15
18
|
return (
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@xylabs/logger';
|
|
2
|
-
import type { Signed } from '@xyo-network/boundwitness-model';
|
|
3
|
-
import type { HydratedTransaction, TransactionBoundWitness, XyoConnectionProvider } from '@xyo-network/xl1-protocol';
|
|
4
|
-
export type ConfirmSubmittedTransactionOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* Number of attempts to confirm the transaction.
|
|
7
|
-
* Defaults to 20.
|
|
8
|
-
*/
|
|
9
|
-
attempts?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Delay in milliseconds between confirmation attempts.
|
|
12
|
-
* Defaults to 1000 (1 second).
|
|
13
|
-
*/
|
|
14
|
-
delay?: number;
|
|
15
|
-
/**
|
|
16
|
-
* Optional logger instance for logging progress.
|
|
17
|
-
*/
|
|
18
|
-
logger?: Logger;
|
|
19
|
-
};
|
|
20
|
-
export declare const confirmSubmittedTransaction: (provider: XyoConnectionProvider, txBW: Signed<TransactionBoundWitness>, options?: ConfirmSubmittedTransactionOptions) => Promise<HydratedTransaction>;
|
|
21
|
-
//# sourceMappingURL=confirmSubmittedTransaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmSubmittedTransaction.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/confirmSubmittedTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,KAAK,EACV,mBAAmB,EAAE,uBAAuB,EAAE,qBAAqB,EACpE,MAAM,2BAA2B,CAAA;AAKlC,MAAM,MAAM,kCAAkC,GAAG;IAC/C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,2BAA2B,GACtC,UAAU,qBAAqB,EAC/B,MAAM,MAAM,CAAC,uBAAuB,CAAC,EACrC,UAAU,kCAAkC,KAC3C,OAAO,CAAC,mBAAmB,CAqB7B,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Signed } from '@xyo-network/boundwitness-model';
|
|
2
|
-
import type { TransactionBoundWitness, XyoConnectionProvider } from '@xyo-network/xl1-protocol';
|
|
3
|
-
export declare const confirmTransaction: (provider: XyoConnectionProvider, txBW: Signed<TransactionBoundWitness>, onConfirm?: (txBWHash: string) => void, onTimeout?: () => void) => Promise<void>;
|
|
4
|
-
//# sourceMappingURL=confirmTransaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmTransaction.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/confirmTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAK/F,eAAO,MAAM,kBAAkB,GAC7B,UAAU,qBAAqB,EAC/B,MAAM,MAAM,CAAC,uBAAuB,CAAC,EACrC,YAAY,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACtC,YAAY,MAAM,IAAI,kBAwBvB,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@xylabs/logger';
|
|
2
|
-
import type { Signed } from '@xyo-network/boundwitness-model';
|
|
3
|
-
import type { HydratedTransaction, TransactionBoundWitness, XyoConnectionProvider } from '@xyo-network/xl1-protocol';
|
|
4
|
-
export type ConfirmSubmittedTransactionOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* Number of attempts to confirm the transaction.
|
|
7
|
-
* Defaults to 20.
|
|
8
|
-
*/
|
|
9
|
-
attempts?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Delay in milliseconds between confirmation attempts.
|
|
12
|
-
* Defaults to 1000 (1 second).
|
|
13
|
-
*/
|
|
14
|
-
delay?: number;
|
|
15
|
-
/**
|
|
16
|
-
* Optional logger instance for logging progress.
|
|
17
|
-
*/
|
|
18
|
-
logger?: Logger;
|
|
19
|
-
};
|
|
20
|
-
export declare const confirmSubmittedTransaction: (provider: XyoConnectionProvider, txBW: Signed<TransactionBoundWitness>, options?: ConfirmSubmittedTransactionOptions) => Promise<HydratedTransaction>;
|
|
21
|
-
//# sourceMappingURL=confirmSubmittedTransaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmSubmittedTransaction.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/confirmSubmittedTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,KAAK,EACV,mBAAmB,EAAE,uBAAuB,EAAE,qBAAqB,EACpE,MAAM,2BAA2B,CAAA;AAKlC,MAAM,MAAM,kCAAkC,GAAG;IAC/C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,2BAA2B,GACtC,UAAU,qBAAqB,EAC/B,MAAM,MAAM,CAAC,uBAAuB,CAAC,EACrC,UAAU,kCAAkC,KAC3C,OAAO,CAAC,mBAAmB,CAqB7B,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Signed } from '@xyo-network/boundwitness-model';
|
|
2
|
-
import type { TransactionBoundWitness, XyoConnectionProvider } from '@xyo-network/xl1-protocol';
|
|
3
|
-
export declare const confirmTransaction: (provider: XyoConnectionProvider, txBW: Signed<TransactionBoundWitness>, onConfirm?: (txBWHash: string) => void, onTimeout?: () => void) => Promise<void>;
|
|
4
|
-
//# sourceMappingURL=confirmTransaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmTransaction.d.ts","sourceRoot":"","sources":["../../../../src/provider/provider/confirmTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAK/F,eAAO,MAAM,kBAAkB,GAC7B,UAAU,qBAAqB,EAC/B,MAAM,MAAM,CAAC,uBAAuB,CAAC,EACrC,YAAY,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACtC,YAAY,MAAM,IAAI,kBAwBvB,CAAA"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { delay } from '@xylabs/delay'
|
|
2
|
-
import type { Logger } from '@xylabs/logger'
|
|
3
|
-
import { isDefined } from '@xylabs/typeof'
|
|
4
|
-
import type { Signed } from '@xyo-network/boundwitness-model'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
6
|
-
import type {
|
|
7
|
-
HydratedTransaction, TransactionBoundWitness, XyoConnectionProvider,
|
|
8
|
-
} from '@xyo-network/xl1-protocol'
|
|
9
|
-
|
|
10
|
-
const DEFAULT_CONFIRMATION_ATTEMPTS = 20
|
|
11
|
-
const DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1000 // milliseconds
|
|
12
|
-
|
|
13
|
-
export type ConfirmSubmittedTransactionOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* Number of attempts to confirm the transaction.
|
|
16
|
-
* Defaults to 20.
|
|
17
|
-
*/
|
|
18
|
-
attempts?: number
|
|
19
|
-
/**
|
|
20
|
-
* Delay in milliseconds between confirmation attempts.
|
|
21
|
-
* Defaults to 1000 (1 second).
|
|
22
|
-
*/
|
|
23
|
-
delay?: number
|
|
24
|
-
/**
|
|
25
|
-
* Optional logger instance for logging progress.
|
|
26
|
-
*/
|
|
27
|
-
logger?: Logger
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const confirmSubmittedTransaction = async (
|
|
31
|
-
provider: XyoConnectionProvider,
|
|
32
|
-
txBW: Signed<TransactionBoundWitness>,
|
|
33
|
-
options?: ConfirmSubmittedTransactionOptions,
|
|
34
|
-
): Promise<HydratedTransaction> => {
|
|
35
|
-
const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options || {}
|
|
36
|
-
const txBWHash = await PayloadBuilder.hash(txBW)
|
|
37
|
-
options?.logger?.log('✅ confirming transaction:', txBWHash, '\n')
|
|
38
|
-
let attempts = 0
|
|
39
|
-
while (true) {
|
|
40
|
-
const tx = await provider.viewer?.transactionByHash(txBWHash) ?? undefined
|
|
41
|
-
if (isDefined(tx)) {
|
|
42
|
-
options?.logger?.log('🍻 Transaction confirmed:', txBWHash, '\n')
|
|
43
|
-
return tx
|
|
44
|
-
} else {
|
|
45
|
-
attempts++
|
|
46
|
-
if (attempts > maxAttempts) {
|
|
47
|
-
options?.logger?.error(`⚠️ Transaction not confirmed after ${maxAttempts} attempts`)
|
|
48
|
-
throw new Error(`Transaction ${txBWHash} not confirmed after ${maxAttempts} attempts`)
|
|
49
|
-
} else {
|
|
50
|
-
options?.logger?.log(`🔄 Transaction not confirmed yet, attempt ${attempts}. Retrying...`, '\n')
|
|
51
|
-
await delay(attemptDelay)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { delay } from '@xylabs/delay'
|
|
2
|
-
import type { Signed } from '@xyo-network/boundwitness-model'
|
|
3
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
4
|
-
import type { TransactionBoundWitness, XyoConnectionProvider } from '@xyo-network/xl1-protocol'
|
|
5
|
-
|
|
6
|
-
const CONFIRMATION_ATTEMPTS = 20
|
|
7
|
-
const DELAY_BETWEEN_ATTEMPTS = 1000 // milliseconds
|
|
8
|
-
|
|
9
|
-
export const confirmTransaction = async (
|
|
10
|
-
provider: XyoConnectionProvider,
|
|
11
|
-
txBW: Signed<TransactionBoundWitness>,
|
|
12
|
-
onConfirm?: (txBWHash: string) => void,
|
|
13
|
-
onTimeout?: () => void,
|
|
14
|
-
) => {
|
|
15
|
-
const txBWHash = await PayloadBuilder.hash(txBW)
|
|
16
|
-
console.log('✅ confirming transaction:', txBWHash, '\n')
|
|
17
|
-
let confirmed = false
|
|
18
|
-
let attempts = 0
|
|
19
|
-
while (!confirmed) {
|
|
20
|
-
const tx = await provider.viewer?.transactionByHash(txBWHash)
|
|
21
|
-
if (tx) {
|
|
22
|
-
confirmed = true
|
|
23
|
-
console.log('🍻 Transaction confirmed:', txBWHash, '\n')
|
|
24
|
-
onConfirm?.(txBWHash)
|
|
25
|
-
} else {
|
|
26
|
-
attempts++
|
|
27
|
-
if (attempts > CONFIRMATION_ATTEMPTS) {
|
|
28
|
-
console.error(`⚠️ Transaction not confirmed after ${CONFIRMATION_ATTEMPTS} attempts`)
|
|
29
|
-
onTimeout?.()
|
|
30
|
-
return
|
|
31
|
-
} else {
|
|
32
|
-
console.log(`🔄 Transaction not confirmed yet, attempt ${attempts}. Retrying...`, '\n')
|
|
33
|
-
await delay(DELAY_BETWEEN_ATTEMPTS) // wait 1 second before retrying
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|