@rango-dev/provider-okx 0.63.1-next.1 → 0.63.1-next.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/actions/ton.d.ts +12 -0
- package/dist/actions/ton.d.ts.map +1 -0
- package/dist/actions/tron.d.ts +5 -0
- package/dist/actions/tron.d.ts.map +1 -0
- package/dist/builders/ton.d.ts +10 -0
- package/dist/builders/ton.d.ts.map +1 -0
- package/dist/builders/tron.d.ts +7 -0
- package/dist/builders/tron.d.ts.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +4 -4
- package/dist/namespaces/ton/ton.d.ts +4 -0
- package/dist/namespaces/ton/ton.d.ts.map +1 -0
- package/dist/namespaces/ton/types.d.ts +65 -0
- package/dist/namespaces/ton/types.d.ts.map +1 -0
- package/dist/namespaces/ton/utils.d.ts +9 -0
- package/dist/namespaces/ton/utils.d.ts.map +1 -0
- package/dist/namespaces/tron.d.ts +4 -0
- package/dist/namespaces/tron.d.ts.map +1 -0
- package/dist/provider.d.ts +1 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/signer.d.ts.map +1 -1
- package/dist/signers/ton.d.ts +11 -0
- package/dist/signers/ton.d.ts.map +1 -0
- package/dist/types.d.ts +13 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +6 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -2
- package/readme.md +10 -4
- package/src/actions/ton.ts +99 -0
- package/src/actions/tron.ts +37 -0
- package/src/builders/ton.ts +48 -0
- package/src/builders/tron.ts +63 -0
- package/src/constants.ts +22 -0
- package/src/namespaces/ton/ton.ts +50 -0
- package/src/namespaces/ton/types.ts +89 -0
- package/src/namespaces/ton/utils.ts +79 -0
- package/src/namespaces/tron.ts +40 -0
- package/src/provider.ts +9 -1
- package/src/signer.ts +10 -0
- package/src/signers/ton.ts +70 -0
- package/src/types.ts +20 -0
- package/src/utils.ts +53 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TonConnectWalletResponseError,
|
|
3
|
+
TonProviderApi,
|
|
4
|
+
} from '../namespaces/ton/types.js';
|
|
5
|
+
import type { GenericSigner, TonTransaction } from 'rango-types';
|
|
6
|
+
|
|
7
|
+
import { dynamicImportWithRefinedError } from '@rango-dev/wallets-shared';
|
|
8
|
+
import { SignerError, SignerErrorCode, TonChainID } from 'rango-types';
|
|
9
|
+
|
|
10
|
+
import { TON_CONNECT_USER_REJECTED_CODE } from '../constants.js';
|
|
11
|
+
import { nextTonRequestId } from '../namespaces/ton/utils.js';
|
|
12
|
+
|
|
13
|
+
function toSignerError(response: TonConnectWalletResponseError): SignerError {
|
|
14
|
+
const code =
|
|
15
|
+
response.error.code === TON_CONNECT_USER_REJECTED_CODE
|
|
16
|
+
? SignerErrorCode.REJECTED_BY_USER
|
|
17
|
+
: SignerErrorCode.SEND_TX_ERROR;
|
|
18
|
+
return new SignerError(code, response.error.message, response.error);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class OKXTonSigner implements GenericSigner<TonTransaction> {
|
|
22
|
+
private provider: TonProviderApi;
|
|
23
|
+
|
|
24
|
+
constructor(provider: TonProviderApi) {
|
|
25
|
+
this.provider = provider;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async signMessage(): Promise<string> {
|
|
29
|
+
throw SignerError.UnimplementedError('signMessage');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async signAndSendTx(tx: TonTransaction): Promise<{ hash: string }> {
|
|
33
|
+
const { validUntil, network, from, messages } = tx;
|
|
34
|
+
|
|
35
|
+
const { Address, Cell } = await dynamicImportWithRefinedError(
|
|
36
|
+
async () => await import('@ton/core')
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const transactionPayload = {
|
|
40
|
+
valid_until: validUntil,
|
|
41
|
+
network: network ?? TonChainID.MAINNET,
|
|
42
|
+
...(from && { from: Address.parse(from).toRawString() }),
|
|
43
|
+
messages: messages.map(({ stateInit, payload, ...message }) => ({
|
|
44
|
+
...message,
|
|
45
|
+
...(stateInit != null && { stateInit }),
|
|
46
|
+
...(payload != null && { payload }),
|
|
47
|
+
})),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const response = await this.provider.send({
|
|
52
|
+
method: 'sendTransaction',
|
|
53
|
+
params: [JSON.stringify(transactionPayload)],
|
|
54
|
+
id: nextTonRequestId(),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if ('error' in response) {
|
|
58
|
+
throw toSignerError(response);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const hash = Cell.fromBase64(response.result).hash().toString('hex');
|
|
62
|
+
return { hash };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof SignerError) {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import type { TonProviderApi } from './namespaces/ton/types.js';
|
|
1
2
|
import type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';
|
|
2
3
|
import type {
|
|
3
4
|
EVM_NAMESPACE,
|
|
4
5
|
SOLANA_NAMESPACE,
|
|
5
6
|
UTXO_NAMESPACE,
|
|
7
|
+
TON_NAMESPACE,
|
|
8
|
+
TRON_NAMESPACE,
|
|
6
9
|
} from '@hub3js/namespaces';
|
|
7
10
|
import type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';
|
|
11
|
+
import type { ProviderAPI as TronProviderApi } from '@rango-dev/wallets-core/namespaces/tron';
|
|
8
12
|
import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
|
|
9
13
|
|
|
10
14
|
export type OkxBtcAddress = {
|
|
@@ -12,12 +16,28 @@ export type OkxBtcAddress = {
|
|
|
12
16
|
publicKey: string;
|
|
13
17
|
compressedPublicKey: string;
|
|
14
18
|
};
|
|
19
|
+
|
|
15
20
|
export type ProviderObject = {
|
|
16
21
|
[EVM_NAMESPACE]: EvmProviderApi;
|
|
17
22
|
[SOLANA_NAMESPACE]: SolanaProviderApi;
|
|
18
23
|
[UTXO_NAMESPACE]: UtxoProviderApi;
|
|
24
|
+
[TON_NAMESPACE]: TonProviderApi;
|
|
25
|
+
[TRON_NAMESPACE]: TronProviderApi;
|
|
19
26
|
};
|
|
20
27
|
export type Provider = Map<
|
|
21
28
|
keyof ProviderObject,
|
|
22
29
|
ProviderObject[keyof ProviderObject]
|
|
23
30
|
>;
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* On `accountsChanged`, `data.address` is the new base58 address, or `false`
|
|
34
|
+
* when disconnected; on `disconnect`, `data` is absent.
|
|
35
|
+
*/
|
|
36
|
+
export type OkxTronMessageEvent = {
|
|
37
|
+
message: {
|
|
38
|
+
action: string;
|
|
39
|
+
data?: {
|
|
40
|
+
address: string | false;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TonProviderApi } from './namespaces/ton/types.js';
|
|
2
|
+
import type { OkxBtcAddress, OkxTronMessageEvent, Provider } from './types.js';
|
|
2
3
|
import type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';
|
|
3
4
|
import type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';
|
|
5
|
+
import type { ProviderAPI as TronProviderApi } from '@rango-dev/wallets-core/namespaces/tron';
|
|
4
6
|
import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
|
|
5
7
|
|
|
6
8
|
import {
|
|
7
9
|
EVM_NAMESPACE,
|
|
8
10
|
SOLANA_NAMESPACE,
|
|
9
11
|
UTXO_NAMESPACE,
|
|
12
|
+
TON_NAMESPACE,
|
|
13
|
+
TRON_NAMESPACE,
|
|
10
14
|
} from '@hub3js/namespaces';
|
|
11
15
|
|
|
12
16
|
export function okx(): Provider | null {
|
|
13
|
-
const { okxwallet } = window;
|
|
14
|
-
if (!okxwallet) {
|
|
17
|
+
const { okxwallet, okxTonWallet } = window;
|
|
18
|
+
if (!okxwallet && !okxTonWallet) {
|
|
15
19
|
return null;
|
|
16
20
|
}
|
|
17
21
|
const instances: Provider = new Map();
|
|
@@ -24,6 +28,12 @@ export function okx(): Provider | null {
|
|
|
24
28
|
if (okxwallet.bitcoin) {
|
|
25
29
|
instances.set(UTXO_NAMESPACE, okxwallet.bitcoin);
|
|
26
30
|
}
|
|
31
|
+
if (okxTonWallet?.tonconnect) {
|
|
32
|
+
instances.set(TON_NAMESPACE, okxTonWallet.tonconnect);
|
|
33
|
+
}
|
|
34
|
+
if (okxwallet.tronLink) {
|
|
35
|
+
instances.set(TRON_NAMESPACE, okxwallet.tronLink);
|
|
36
|
+
}
|
|
27
37
|
return instances;
|
|
28
38
|
}
|
|
29
39
|
|
|
@@ -75,6 +85,32 @@ export function bitcoinOKX(): UtxoProviderApi {
|
|
|
75
85
|
|
|
76
86
|
return bitcoinInstance;
|
|
77
87
|
}
|
|
88
|
+
|
|
89
|
+
export function tonOKX(): TonProviderApi {
|
|
90
|
+
const instance = okx();
|
|
91
|
+
const tonInstance = instance?.get(TON_NAMESPACE);
|
|
92
|
+
|
|
93
|
+
if (!tonInstance) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
'OKX Wallet not injected or TON not enabled. Please check your wallet.'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return tonInstance as TonProviderApi;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function tronOKX(): TronProviderApi {
|
|
103
|
+
const instance = okx();
|
|
104
|
+
const tronInstance = instance?.get(TRON_NAMESPACE);
|
|
105
|
+
|
|
106
|
+
if (!tronInstance) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
'OKX Wallet not injected or Tron not enabled. Please check your wallet.'
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return tronInstance;
|
|
113
|
+
}
|
|
78
114
|
export async function getBitcoinAccounts(): Promise<OkxBtcAddress> {
|
|
79
115
|
const instance = bitcoinOKX();
|
|
80
116
|
const requestResult = await instance.connect();
|
|
@@ -85,3 +121,17 @@ export async function getBitcoinAccounts(): Promise<OkxBtcAddress> {
|
|
|
85
121
|
|
|
86
122
|
return requestResult;
|
|
87
123
|
}
|
|
124
|
+
|
|
125
|
+
export function isOkxTronMessageEvent(
|
|
126
|
+
value: unknown
|
|
127
|
+
): value is OkxTronMessageEvent {
|
|
128
|
+
if (typeof value !== 'object' || value === null) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const event = value as { message?: { action?: unknown } };
|
|
132
|
+
return (
|
|
133
|
+
typeof event.message === 'object' &&
|
|
134
|
+
event.message !== null &&
|
|
135
|
+
typeof event.message.action === 'string'
|
|
136
|
+
);
|
|
137
|
+
}
|