@rango-dev/provider-okx 0.0.0-experimental-936229e8-20251208

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +258 -0
  2. package/dist/builders/utxo.d.ts +12 -0
  3. package/dist/builders/utxo.d.ts.map +1 -0
  4. package/dist/constants.d.ts +6 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/legacy/index.d.ts +21 -0
  7. package/dist/legacy/index.d.ts.map +1 -0
  8. package/dist/mod.d.ts +3 -0
  9. package/dist/mod.d.ts.map +1 -0
  10. package/dist/mod.js +2 -0
  11. package/dist/mod.js.map +7 -0
  12. package/dist/namespaces/evm.d.ts +4 -0
  13. package/dist/namespaces/evm.d.ts.map +1 -0
  14. package/dist/namespaces/solana.d.ts +4 -0
  15. package/dist/namespaces/solana.d.ts.map +1 -0
  16. package/dist/namespaces/utxo.d.ts +4 -0
  17. package/dist/namespaces/utxo.d.ts.map +1 -0
  18. package/dist/provider-okx.build.json +1 -0
  19. package/dist/provider.d.ts +3 -0
  20. package/dist/provider.d.ts.map +1 -0
  21. package/dist/signer.d.ts +4 -0
  22. package/dist/signer.d.ts.map +1 -0
  23. package/dist/signers/solana.d.ts +6 -0
  24. package/dist/signers/solana.d.ts.map +1 -0
  25. package/dist/signers/utxo.d.ts +11 -0
  26. package/dist/signers/utxo.d.ts.map +1 -0
  27. package/dist/types.d.ts +16 -0
  28. package/dist/types.d.ts.map +1 -0
  29. package/dist/utils.d.ts +11 -0
  30. package/dist/utils.d.ts.map +1 -0
  31. package/package.json +33 -0
  32. package/readme.md +78 -0
  33. package/src/builders/utxo.ts +48 -0
  34. package/src/constants.ts +83 -0
  35. package/src/legacy/index.ts +137 -0
  36. package/src/mod.ts +12 -0
  37. package/src/namespaces/evm.ts +73 -0
  38. package/src/namespaces/solana.ts +62 -0
  39. package/src/namespaces/utxo.ts +51 -0
  40. package/src/provider.ts +26 -0
  41. package/src/signer.ts +30 -0
  42. package/src/signers/solana.ts +25 -0
  43. package/src/signers/utxo.ts +57 -0
  44. package/src/types.ts +19 -0
  45. package/src/utils.ts +83 -0
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
2
+ import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
3
+ import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
4
+ import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
5
+
6
+ export type OkxBtcAddress = {
7
+ address: string;
8
+ publicKey: string;
9
+ compressedPublicKey: string;
10
+ };
11
+ export type ProviderObject = {
12
+ [LegacyNetworks.ETHEREUM]: EvmProviderApi;
13
+ [LegacyNetworks.SOLANA]: SolanaProviderApi;
14
+ [LegacyNetworks.BTC]: UtxoProviderApi;
15
+ };
16
+ export type Provider = Map<
17
+ keyof ProviderObject,
18
+ ProviderObject[keyof ProviderObject]
19
+ >;
package/src/utils.ts ADDED
@@ -0,0 +1,83 @@
1
+ import type { OkxBtcAddress, Provider } from './types.js';
2
+ import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
3
+ import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
4
+ import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
5
+
6
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
7
+
8
+ export function okx(): Provider | null {
9
+ const { okxwallet } = window;
10
+ if (!okxwallet) {
11
+ return null;
12
+ }
13
+ const instances: Provider = new Map();
14
+ if (okxwallet) {
15
+ instances.set(LegacyNetworks.ETHEREUM, okxwallet);
16
+ }
17
+ if (okxwallet.solana) {
18
+ instances.set(LegacyNetworks.SOLANA, okxwallet.solana);
19
+ }
20
+ if (okxwallet.bitcoin) {
21
+ instances.set(LegacyNetworks.BTC, okxwallet.bitcoin);
22
+ }
23
+ return instances;
24
+ }
25
+
26
+ export function getInstanceOrThrow(): Provider {
27
+ const instances = okx();
28
+
29
+ if (!instances) {
30
+ throw new Error('OKX Wallet is not injected. Please check your wallet.');
31
+ }
32
+
33
+ return instances;
34
+ }
35
+
36
+ export function evmOKX(): EvmProviderApi {
37
+ const instances = okx();
38
+
39
+ const evmInstance = instances?.get(LegacyNetworks.ETHEREUM);
40
+
41
+ if (!evmInstance) {
42
+ throw new Error(
43
+ 'OKX Wallet not injected or EVM not enabled. Please check your wallet.'
44
+ );
45
+ }
46
+
47
+ return evmInstance as EvmProviderApi;
48
+ }
49
+
50
+ export function solanaOKX(): SolanaProviderApi {
51
+ const instance = okx();
52
+ const solanaInstance = instance?.get(LegacyNetworks.SOLANA);
53
+
54
+ if (!solanaInstance) {
55
+ throw new Error(
56
+ 'OKX Wallet not injected or Solana not enabled. Please check your wallet.'
57
+ );
58
+ }
59
+
60
+ return solanaInstance as SolanaProviderApi;
61
+ }
62
+ export function bitcoinOKX(): UtxoProviderApi {
63
+ const instance = okx();
64
+ const bitcoinInstance = instance?.get(LegacyNetworks.BTC);
65
+
66
+ if (!bitcoinInstance) {
67
+ throw new Error(
68
+ 'OKX Wallet not injected or Utxo not enabled. Please check your wallet.'
69
+ );
70
+ }
71
+
72
+ return bitcoinInstance as UtxoProviderApi;
73
+ }
74
+ export async function getBitcoinAccounts(): Promise<OkxBtcAddress> {
75
+ const instance = bitcoinOKX();
76
+ const requestResult = await instance.connect();
77
+
78
+ if (requestResult.error?.message) {
79
+ throw new Error(requestResult.error.message);
80
+ }
81
+
82
+ return requestResult;
83
+ }