@gardenfi/wallet-connectors 0.1.0-beta.1

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 (136) hide show
  1. package/README.md +0 -0
  2. package/dist/index.cjs +1 -0
  3. package/dist/index.js +9 -0
  4. package/dist/index10.cjs +1 -0
  5. package/dist/index10.js +134 -0
  6. package/dist/index11.cjs +1 -0
  7. package/dist/index11.js +46 -0
  8. package/dist/index12.cjs +1 -0
  9. package/dist/index12.js +233 -0
  10. package/dist/index13.cjs +1 -0
  11. package/dist/index13.js +8 -0
  12. package/dist/index14.cjs +2 -0
  13. package/dist/index14.js +133 -0
  14. package/dist/index15.cjs +1 -0
  15. package/dist/index15.js +70 -0
  16. package/dist/index16.cjs +1 -0
  17. package/dist/index16.js +89 -0
  18. package/dist/index17.cjs +1 -0
  19. package/dist/index17.js +31 -0
  20. package/dist/index18.cjs +1 -0
  21. package/dist/index18.js +11 -0
  22. package/dist/index19.cjs +1 -0
  23. package/dist/index19.js +77 -0
  24. package/dist/index2.cjs +1 -0
  25. package/dist/index2.js +106 -0
  26. package/dist/index20.cjs +1 -0
  27. package/dist/index20.js +6 -0
  28. package/dist/index21.cjs +1 -0
  29. package/dist/index21.js +4 -0
  30. package/dist/index22.cjs +1 -0
  31. package/dist/index22.js +83 -0
  32. package/dist/index23.cjs +1 -0
  33. package/dist/index23.js +54 -0
  34. package/dist/index24.cjs +1 -0
  35. package/dist/index24.js +8 -0
  36. package/dist/index25.cjs +1 -0
  37. package/dist/index25.js +7 -0
  38. package/dist/index26.cjs +2 -0
  39. package/dist/index26.js +173 -0
  40. package/dist/index27.cjs +3 -0
  41. package/dist/index27.js +53 -0
  42. package/dist/index28.cjs +1 -0
  43. package/dist/index28.js +71 -0
  44. package/dist/index29.cjs +1 -0
  45. package/dist/index29.js +19 -0
  46. package/dist/index3.cjs +1 -0
  47. package/dist/index3.js +30 -0
  48. package/dist/index30.cjs +1 -0
  49. package/dist/index30.js +58 -0
  50. package/dist/index31.cjs +1 -0
  51. package/dist/index31.js +31 -0
  52. package/dist/index32.cjs +1 -0
  53. package/dist/index32.js +8 -0
  54. package/dist/index33.cjs +1 -0
  55. package/dist/index33.js +51 -0
  56. package/dist/index34.cjs +1 -0
  57. package/dist/index34.js +8 -0
  58. package/dist/index35.cjs +1 -0
  59. package/dist/index35.js +13 -0
  60. package/dist/index36.cjs +1 -0
  61. package/dist/index36.js +9 -0
  62. package/dist/index37.cjs +2 -0
  63. package/dist/index37.js +30 -0
  64. package/dist/index38.cjs +1 -0
  65. package/dist/index38.js +4 -0
  66. package/dist/index39.cjs +1 -0
  67. package/dist/index39.js +71 -0
  68. package/dist/index4.cjs +1 -0
  69. package/dist/index4.js +30 -0
  70. package/dist/index40.cjs +1 -0
  71. package/dist/index40.js +141 -0
  72. package/dist/index41.cjs +1 -0
  73. package/dist/index41.js +15 -0
  74. package/dist/index42.cjs +1 -0
  75. package/dist/index42.js +9 -0
  76. package/dist/index43.cjs +1 -0
  77. package/dist/index43.js +33 -0
  78. package/dist/index44.cjs +1 -0
  79. package/dist/index44.js +13 -0
  80. package/dist/index45.cjs +1 -0
  81. package/dist/index45.js +6 -0
  82. package/dist/index46.cjs +1 -0
  83. package/dist/index46.js +6 -0
  84. package/dist/index47.cjs +1 -0
  85. package/dist/index47.js +14 -0
  86. package/dist/index48.cjs +1 -0
  87. package/dist/index48.js +7 -0
  88. package/dist/index49.cjs +1 -0
  89. package/dist/index49.js +35 -0
  90. package/dist/index5.cjs +1 -0
  91. package/dist/index5.js +5 -0
  92. package/dist/index50.cjs +1 -0
  93. package/dist/index50.js +33 -0
  94. package/dist/index51.cjs +1 -0
  95. package/dist/index51.js +30 -0
  96. package/dist/index52.cjs +1 -0
  97. package/dist/index52.js +63 -0
  98. package/dist/index53.cjs +1 -0
  99. package/dist/index53.js +5 -0
  100. package/dist/index54.cjs +1 -0
  101. package/dist/index54.js +4 -0
  102. package/dist/index55.cjs +1 -0
  103. package/dist/index55.js +4 -0
  104. package/dist/index56.cjs +1 -0
  105. package/dist/index56.js +19 -0
  106. package/dist/index57.cjs +1 -0
  107. package/dist/index57.js +15 -0
  108. package/dist/index58.cjs +1 -0
  109. package/dist/index58.js +37 -0
  110. package/dist/index59.cjs +1 -0
  111. package/dist/index59.js +32 -0
  112. package/dist/index6.cjs +1 -0
  113. package/dist/index6.js +69 -0
  114. package/dist/index7.cjs +1 -0
  115. package/dist/index7.js +69 -0
  116. package/dist/index8.cjs +1 -0
  117. package/dist/index8.js +61 -0
  118. package/dist/index9.cjs +1 -0
  119. package/dist/index9.js +95 -0
  120. package/dist/src/bitcoin/bitcoin.types.d.ts +53 -0
  121. package/dist/src/bitcoin/btcWalletsProvider.d.ts +41 -0
  122. package/dist/src/bitcoin/constants.d.ts +27 -0
  123. package/dist/src/bitcoin/index.d.ts +3 -0
  124. package/dist/src/bitcoin/providers/okx/okx.types.d.ts +33 -0
  125. package/dist/src/bitcoin/providers/okx/provider.d.ts +28 -0
  126. package/dist/src/bitcoin/providers/phantom/phantom.types.d.ts +30 -0
  127. package/dist/src/bitcoin/providers/phantom/provider.d.ts +31 -0
  128. package/dist/src/bitcoin/providers/unisat/provider.d.ts +27 -0
  129. package/dist/src/bitcoin/providers/unisat/unisat.types.d.ts +19 -0
  130. package/dist/src/bitcoin/providers/xdefi/provider.d.ts +24 -0
  131. package/dist/src/bitcoin/providers/xdefi/xdefi.types.d.ts +17 -0
  132. package/dist/src/bitcoin/providers/xverse/provider.d.ts +30 -0
  133. package/dist/src/bitcoin/providers/xverse/xverse.types.d.ts +7 -0
  134. package/dist/src/bitcoin/utils.d.ts +4 -0
  135. package/dist/src/index.d.ts +1 -0
  136. package/package.json +45 -0
@@ -0,0 +1,15 @@
1
+ function h(r, a) {
2
+ let s = 0, u = 1e3 / a, e, t;
3
+ const n = (l, o = Date.now()) => {
4
+ s = o, e = null, t && (clearTimeout(t), t = null), r.apply(null, l);
5
+ };
6
+ return [(...l) => {
7
+ const o = Date.now(), i = o - s;
8
+ i >= u ? n(l, o) : (e = l, t || (t = setTimeout(() => {
9
+ t = null, n(e);
10
+ }, u - i)));
11
+ }, () => e && n(e)];
12
+ }
13
+ export {
14
+ h as default
15
+ };
@@ -0,0 +1 @@
1
+ "use strict";const c=require("./index12.cjs"),n=require("./index36.cjs"),u=n.hasStandardBrowserEnv?function(){const o=n.navigator&&/(msie|trident)/i.test(n.navigator.userAgent),t=document.createElement("a");let e;function a(s){let r=s;return o&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:t.pathname.charAt(0)==="/"?t.pathname:"/"+t.pathname}}return e=a(window.location.href),function(r){const i=c.isString(r)?a(r):r;return i.protocol===e.protocol&&i.host===e.host}}():function(){return function(){return!0}}();module.exports=u;
@@ -0,0 +1,37 @@
1
+ import c from "./index12.js";
2
+ import o from "./index36.js";
3
+ const f = o.hasStandardBrowserEnv ? (
4
+ // Standard browser envs have full support of the APIs needed to test
5
+ // whether the request URL is of the same origin as current location.
6
+ function() {
7
+ const n = o.navigator && /(msie|trident)/i.test(o.navigator.userAgent), t = document.createElement("a");
8
+ let e;
9
+ function a(s) {
10
+ let r = s;
11
+ return n && (t.setAttribute("href", r), r = t.href), t.setAttribute("href", r), {
12
+ href: t.href,
13
+ protocol: t.protocol ? t.protocol.replace(/:$/, "") : "",
14
+ host: t.host,
15
+ search: t.search ? t.search.replace(/^\?/, "") : "",
16
+ hash: t.hash ? t.hash.replace(/^#/, "") : "",
17
+ hostname: t.hostname,
18
+ port: t.port,
19
+ pathname: t.pathname.charAt(0) === "/" ? t.pathname : "/" + t.pathname
20
+ };
21
+ }
22
+ return e = a(window.location.href), function(r) {
23
+ const i = c.isString(r) ? a(r) : r;
24
+ return i.protocol === e.protocol && i.host === e.host;
25
+ };
26
+ }()
27
+ ) : (
28
+ // Non standard browser envs (web workers, react-native) lack needed support.
29
+ /* @__PURE__ */ function() {
30
+ return function() {
31
+ return !0;
32
+ };
33
+ }()
34
+ );
35
+ export {
36
+ f as default
37
+ };
@@ -0,0 +1 @@
1
+ "use strict";const n=require("./index12.cjs"),u=require("./index36.cjs"),d=u.hasStandardBrowserEnv?{write(e,o,r,s,i,c){const t=[e+"="+encodeURIComponent(o)];n.isNumber(r)&&t.push("expires="+new Date(r).toGMTString()),n.isString(s)&&t.push("path="+s),n.isString(i)&&t.push("domain="+i),c===!0&&t.push("secure"),document.cookie=t.join("; ")},read(e){const o=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return o?decodeURIComponent(o[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};module.exports=d;
@@ -0,0 +1,32 @@
1
+ import r from "./index12.js";
2
+ import c from "./index36.js";
3
+ const p = c.hasStandardBrowserEnv ? (
4
+ // Standard browser envs support document.cookie
5
+ {
6
+ write(e, t, n, i, s, u) {
7
+ const o = [e + "=" + encodeURIComponent(t)];
8
+ r.isNumber(n) && o.push("expires=" + new Date(n).toGMTString()), r.isString(i) && o.push("path=" + i), r.isString(s) && o.push("domain=" + s), u === !0 && o.push("secure"), document.cookie = o.join("; ");
9
+ },
10
+ read(e) {
11
+ const t = document.cookie.match(new RegExp("(^|;\\s*)(" + e + ")=([^;]*)"));
12
+ return t ? decodeURIComponent(t[3]) : null;
13
+ },
14
+ remove(e) {
15
+ this.write(e, "", Date.now() - 864e5);
16
+ }
17
+ }
18
+ ) : (
19
+ // Non-standard browser env (web workers, react-native) lack needed support.
20
+ {
21
+ write() {
22
+ },
23
+ read() {
24
+ return null;
25
+ },
26
+ remove() {
27
+ }
28
+ }
29
+ );
30
+ export {
31
+ p as default
32
+ };
@@ -0,0 +1 @@
1
+ "use strict";var y=i=>{throw TypeError(i)};var N=(i,t,r)=>t.has(i)||y("Cannot "+r);var e=(i,t,r)=>(N(i,t,"read from private field"),r?r.call(i):t.get(i)),w=(i,t,r)=>t.has(i)?y("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,r),u=(i,t,r,d)=>(N(i,t,"write to private field"),d?d.call(i,r):t.set(i,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),o=require("./index5.cjs");var c,a,s,h,l;class g{constructor(t,r){w(this,h);w(this,c);w(this,a);w(this,s);this.address="",this.disconnect=()=>(this.address="",Promise.resolve(n.Ok("Disconnected OKX wallet"))),u(this,c,t),u(this,a,r),u(this,s,o.Network.MAINNET)}async connect(t){t||(t=o.Network.MAINNET);try{u(this,s,t);const r=await e(this,h,l).connect();return!r||!r.address?n.Err("Failed to connect to OKX wallet"):(this.address=r.address,n.Ok({address:this.address,provider:this,network:e(this,s)}))}catch(r){return n.Err("Error while connecting to the OKX wallet",r)}}async getPublicKey(){return await n.executeWithTryCatch(async()=>await e(this,h,l).getPublicKey(),"Error while getting public key from OKX wallet")}async requestAccounts(){const t=await this.connect(e(this,s));return t.error?n.Err(t.error):n.Ok([t.val.address])}async getAccounts(){return e(this,s)===o.Network.TESTNET?await this.requestAccounts():await n.executeWithTryCatch(async()=>await e(this,c).getAccounts(),"Error while getting accounts from OKX wallet")}async getNetwork(){return n.Ok(e(this,s))}async switchNetwork(){u(this,s,e(this,s)===o.Network.MAINNET?o.Network.TESTNET:o.Network.MAINNET);const t=await this.connect(e(this,s));return t.error?n.Err(`Failed to connect to ${e(this,s)}: ${t.error}`):n.Ok(e(this,s))}async getBalance(){return await n.executeWithTryCatch(async()=>await e(this,h,l).getBalance(),"Error while getting balance from OKX wallet")}async sendBitcoin(t,r){return await n.executeWithTryCatch(async()=>await e(this,h,l).sendBitcoin(t,r),"Error while sending bitcoin from OKX wallet")}on(t,r){e(this,c).on(t,r),e(this,a).on(t,r)}off(t,r){e(this,c).off(t,r),e(this,a).off(t,r)}}c=new WeakMap,a=new WeakMap,s=new WeakMap,h=new WeakSet,l=function(){return e(this,s)===o.Network.MAINNET?e(this,c):e(this,a)};exports.OKXProvider=g;
package/dist/index6.js ADDED
@@ -0,0 +1,69 @@
1
+ var g = (s) => {
2
+ throw TypeError(s);
3
+ };
4
+ var N = (s, t, r) => t.has(s) || g("Cannot " + r);
5
+ var e = (s, t, r) => (N(s, t, "read from private field"), r ? r.call(s) : t.get(s)), u = (s, t, r) => t.has(s) ? g("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, r), h = (s, t, r, y) => (N(s, t, "write to private field"), y ? y.call(s, r) : t.set(s, r), r);
6
+ import { Ok as l, Err as w, executeWithTryCatch as f } from "@catalogfi/utils";
7
+ import { Network as o } from "./index5.js";
8
+ var n, c, i, a, d;
9
+ class K {
10
+ constructor(t, r) {
11
+ u(this, a);
12
+ u(this, n);
13
+ u(this, c);
14
+ u(this, i);
15
+ this.address = "", this.disconnect = () => (this.address = "", Promise.resolve(l("Disconnected OKX wallet"))), h(this, n, t), h(this, c, r), h(this, i, o.MAINNET);
16
+ }
17
+ async connect(t) {
18
+ t || (t = o.MAINNET);
19
+ try {
20
+ h(this, i, t);
21
+ const r = await e(this, a, d).connect();
22
+ return !r || !r.address ? w("Failed to connect to OKX wallet") : (this.address = r.address, l({
23
+ address: this.address,
24
+ provider: this,
25
+ network: e(this, i)
26
+ }));
27
+ } catch (r) {
28
+ return w("Error while connecting to the OKX wallet", r);
29
+ }
30
+ }
31
+ async getPublicKey() {
32
+ return await f(async () => await e(this, a, d).getPublicKey(), "Error while getting public key from OKX wallet");
33
+ }
34
+ async requestAccounts() {
35
+ const t = await this.connect(e(this, i));
36
+ return t.error ? w(t.error) : l([t.val.address]);
37
+ }
38
+ async getAccounts() {
39
+ return e(this, i) === o.TESTNET ? await this.requestAccounts() : await f(async () => await e(this, n).getAccounts(), "Error while getting accounts from OKX wallet");
40
+ }
41
+ async getNetwork() {
42
+ return l(e(this, i));
43
+ }
44
+ async switchNetwork() {
45
+ h(this, i, e(this, i) === o.MAINNET ? o.TESTNET : o.MAINNET);
46
+ const t = await this.connect(e(this, i));
47
+ return t.error ? w(
48
+ `Failed to connect to ${e(this, i)}: ${t.error}`
49
+ ) : l(e(this, i));
50
+ }
51
+ async getBalance() {
52
+ return await f(async () => await e(this, a, d).getBalance(), "Error while getting balance from OKX wallet");
53
+ }
54
+ async sendBitcoin(t, r) {
55
+ return await f(async () => await e(this, a, d).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
56
+ }
57
+ on(t, r) {
58
+ e(this, n).on(t, r), e(this, c).on(t, r);
59
+ }
60
+ off(t, r) {
61
+ e(this, n).off(t, r), e(this, c).off(t, r);
62
+ }
63
+ }
64
+ n = new WeakMap(), c = new WeakMap(), i = new WeakMap(), a = new WeakSet(), d = function() {
65
+ return e(this, i) === o.MAINNET ? e(this, n) : e(this, c);
66
+ };
67
+ export {
68
+ K as OKXProvider
69
+ };
@@ -0,0 +1 @@
1
+ "use strict";var c=e=>{throw TypeError(e)};var w=(e,t,r)=>t.has(e)||c("Cannot "+r);var s=(e,t,r)=>(w(e,t,"read from private field"),r?r.call(e):t.get(e)),h=(e,t,r)=>t.has(e)?c("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),u=(e,t,r,a)=>(w(e,t,"write to private field"),a?a.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@catalogfi/utils"),o=require("./index5.cjs");var n;class l{constructor(t){h(this,n);this.address="",this.disconnect=()=>(this.address="",Promise.resolve(i.Ok("Disconnected unisat wallet"))),u(this,n,t)}async connect(t){try{t||(t=o.Network.MAINNET);const r=await s(this,n).getAccounts();r.length>0&&(this.address=r[0]);const a=await this.getNetwork();return a.error?i.Err("Could not get network",a.error):(a.val!==t&&await this.switchNetwork(),i.Ok({address:this.address,provider:this,network:t}))}catch(r){return i.Err("Error while connecting to the Unisat wallet",r)}}async requestAccounts(){return await i.executeWithTryCatch(async()=>await s(this,n).requestAccounts(),"Error while requesting accounts from the Unisat wallet")}async getAccounts(){return await i.executeWithTryCatch(async()=>await s(this,n).getAccounts(),"Error while getting accounts from the Unisat wallet")}async getNetwork(){return await i.executeWithTryCatch(async()=>await s(this,n).getNetwork()==="livenet"?o.Network.MAINNET:o.Network.TESTNET,"Error while getting network from Unisat wallet")}async switchNetwork(){try{const t=await this.getNetwork();if(t.error)return i.Err("Failed to get current network");const r=t.val===o.Network.MAINNET?o.Network.TESTNET:o.Network.MAINNET;await s(this,n).switchNetwork(r);const a=await this.getNetwork();return a.error?i.Err("Failed to verify network switch"):a.val!==r?i.Err("Network switch failed"):i.Ok(r)}catch(t){return i.Err("Error while switching network in Unisat:",t)}}async getBalance(){return await i.executeWithTryCatch(async()=>await s(this,n).getBalance(),"Error while getting balance from Unisat wallet")}async sendBitcoin(t,r){return await i.executeWithTryCatch(async()=>await s(this,n).sendBitcoin(t,r),"Error while sending bitcoin from Unisat wallet")}on(t,r){s(this,n).on(t,r)}off(t,r){s(this,n).removeListener(t,r)}}n=new WeakMap;exports.UnisatProvider=l;
package/dist/index7.js ADDED
@@ -0,0 +1,69 @@
1
+ var h = (e) => {
2
+ throw TypeError(e);
3
+ };
4
+ var u = (e, t, r) => t.has(e) || h("Cannot " + r);
5
+ var i = (e, t, r) => (u(e, t, "read from private field"), r ? r.call(e) : t.get(e)), l = (e, t, r) => t.has(e) ? h("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), N = (e, t, r, s) => (u(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
+ import { Ok as w, Err as a, executeWithTryCatch as c } from "@catalogfi/utils";
7
+ import { Network as o } from "./index5.js";
8
+ var n;
9
+ class k {
10
+ constructor(t) {
11
+ l(this, n);
12
+ this.address = "", this.disconnect = () => (this.address = "", Promise.resolve(w("Disconnected unisat wallet"))), N(this, n, t);
13
+ }
14
+ async connect(t) {
15
+ try {
16
+ t || (t = o.MAINNET);
17
+ const r = await i(this, n).getAccounts();
18
+ r.length > 0 && (this.address = r[0]);
19
+ const s = await this.getNetwork();
20
+ return s.error ? a("Could not get network", s.error) : (s.val !== t && await this.switchNetwork(), w({
21
+ address: this.address,
22
+ provider: this,
23
+ network: t
24
+ }));
25
+ } catch (r) {
26
+ return a("Error while connecting to the Unisat wallet", r);
27
+ }
28
+ }
29
+ // requests accounts from the wallet, if not connected, it will connect first
30
+ async requestAccounts() {
31
+ return await c(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
32
+ }
33
+ //silently gets accounts if already connected
34
+ async getAccounts() {
35
+ return await c(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
36
+ }
37
+ async getNetwork() {
38
+ return await c(async () => await i(this, n).getNetwork() === "livenet" ? o.MAINNET : o.TESTNET, "Error while getting network from Unisat wallet");
39
+ }
40
+ async switchNetwork() {
41
+ try {
42
+ const t = await this.getNetwork();
43
+ if (t.error)
44
+ return a("Failed to get current network");
45
+ const r = t.val === o.MAINNET ? o.TESTNET : o.MAINNET;
46
+ await i(this, n).switchNetwork(r);
47
+ const s = await this.getNetwork();
48
+ return s.error ? a("Failed to verify network switch") : s.val !== r ? a("Network switch failed") : w(r);
49
+ } catch (t) {
50
+ return a("Error while switching network in Unisat:", t);
51
+ }
52
+ }
53
+ async getBalance() {
54
+ return await c(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
55
+ }
56
+ async sendBitcoin(t, r) {
57
+ return await c(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
58
+ }
59
+ on(t, r) {
60
+ i(this, n).on(t, r);
61
+ }
62
+ off(t, r) {
63
+ i(this, n).removeListener(t, r);
64
+ }
65
+ }
66
+ n = new WeakMap();
67
+ export {
68
+ k as UnisatProvider
69
+ };
@@ -0,0 +1 @@
1
+ "use strict";var l=t=>{throw TypeError(t)};var y=(t,s,e)=>s.has(t)||l("Cannot "+e);var a=(t,s,e)=>(y(t,s,"read from private field"),e?e.call(t):s.get(t)),g=(t,s,e)=>s.has(t)?l("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,e),d=(t,s,e,o)=>(y(t,s,"write to private field"),o?o.call(t,e):s.set(t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./index5.cjs"),r=require("@catalogfi/utils");var i;const w=class w{constructor(s){g(this,i);this.provider=s,this.address="",this.connect=async()=>{try{const o=(await a(this,i).request("getAccounts",{purposes:["payment"],message:"I want to connect",network:"testnet"})).result[0].address;if(this.address=o,!window.XverseProviders||!window.XverseProviders.BitcoinProvider)return r.Err("XVerse wallet not found");const n=new w(window.XverseProviders.BitcoinProvider);d(this,i,n.provider);const c=await this.getNetwork();return c.error?r.Err("Could not get network",c.error):r.Ok({address:this.address,provider:n,network:c.val})}catch(e){return r.Err("Error while connecting to the XVerse wallet",e)}},this.getBalance=async()=>await r.executeWithTryCatch(async()=>(await a(this,i).request("getBalance",{})).result,"Error while getting balance from XVerse wallet"),this.requestAccounts=async()=>r.Ok([]),this.getAccounts=async()=>await r.executeWithTryCatch(async()=>(await a(this,i).request("getAccounts",{purposes:["payment"],message:"I want to connect"})).result.map(o=>o.address)),this.sendBitcoin=async(e,o)=>{try{const n=await a(this,i).request("sendTransfer",{recipients:[{address:e,amount:o}]});return n.status==="success"?r.Ok(n.result.txid):n.error.code===-32e3?r.Err("User rejected the transaction"):r.Err("Error while sending bitcoin from XVerse wallet",n.error)}catch(n){return r.Err("Error while sending bitcoin from XVerse wallet",n)}},this.getNetwork=async()=>this.address.startsWith("1")||this.address.startsWith("3")||this.address.startsWith("bc1")?r.Ok(h.Network.MAINNET):(this.address.startsWith("m")||this.address.startsWith("n")||this.address.startsWith("2")||this.address.startsWith("tb1"),r.Ok(h.Network.TESTNET)),this.on=()=>{},this.off=()=>{},this.disconnect=()=>(this.address="",Promise.resolve(r.Ok("Disconnected"))),d(this,i,s)}async switchNetwork(){return r.Err("Not available in xverse wallet")}};i=new WeakMap;let u=w;exports.XverseProvider=u;
package/dist/index8.js ADDED
@@ -0,0 +1,61 @@
1
+ var l = (t) => {
2
+ throw TypeError(t);
3
+ };
4
+ var f = (t, r, e) => r.has(t) || l("Cannot " + e);
5
+ var c = (t, r, e) => (f(t, r, "read from private field"), e ? e.call(t) : r.get(t)), g = (t, r, e) => r.has(t) ? l("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(t) : r.set(t, e), h = (t, r, e, i) => (f(t, r, "write to private field"), i ? i.call(t, e) : r.set(t, e), e);
6
+ import { Network as u } from "./index5.js";
7
+ import { Err as o, Ok as a, executeWithTryCatch as m } from "@catalogfi/utils";
8
+ var n;
9
+ const w = class w {
10
+ constructor(r) {
11
+ g(this, n);
12
+ this.provider = r, this.address = "", this.connect = async () => {
13
+ try {
14
+ const i = (await c(this, n).request("getAccounts", {
15
+ purposes: ["payment"],
16
+ message: "I want to connect",
17
+ network: "testnet"
18
+ })).result[0].address;
19
+ if (this.address = i, !window.XverseProviders || !window.XverseProviders.BitcoinProvider)
20
+ return o("XVerse wallet not found");
21
+ const s = new w(
22
+ window.XverseProviders.BitcoinProvider
23
+ );
24
+ h(this, n, s.provider);
25
+ const d = await this.getNetwork();
26
+ return d.error ? o("Could not get network", d.error) : a({
27
+ address: this.address,
28
+ provider: s,
29
+ network: d.val
30
+ });
31
+ } catch (e) {
32
+ return o("Error while connecting to the XVerse wallet", e);
33
+ }
34
+ }, this.getBalance = async () => await m(async () => (await c(this, n).request("getBalance", {})).result, "Error while getting balance from XVerse wallet"), this.requestAccounts = async () => a([]), this.getAccounts = async () => await m(async () => (await c(this, n).request("getAccounts", {
35
+ purposes: ["payment"],
36
+ message: "I want to connect"
37
+ })).result.map((i) => i.address)), this.sendBitcoin = async (e, i) => {
38
+ try {
39
+ const s = await c(this, n).request("sendTransfer", {
40
+ recipients: [{ address: e, amount: i }]
41
+ });
42
+ return s.status === "success" ? a(s.result.txid) : s.error.code === -32e3 ? o("User rejected the transaction") : o(
43
+ "Error while sending bitcoin from XVerse wallet",
44
+ s.error
45
+ );
46
+ } catch (s) {
47
+ return o("Error while sending bitcoin from XVerse wallet", s);
48
+ }
49
+ }, this.getNetwork = async () => this.address.startsWith("1") || this.address.startsWith("3") || this.address.startsWith("bc1") ? a(u.MAINNET) : this.address.startsWith("m") || this.address.startsWith("n") || this.address.startsWith("2") || this.address.startsWith("tb1") ? a(u.TESTNET) : a(u.TESTNET), this.on = () => {
50
+ }, this.off = () => {
51
+ }, this.disconnect = () => (this.address = "", Promise.resolve(a("Disconnected"))), h(this, n, r);
52
+ }
53
+ async switchNetwork() {
54
+ return o("Not available in xverse wallet");
55
+ }
56
+ };
57
+ n = new WeakMap();
58
+ let p = w;
59
+ export {
60
+ p as XverseProvider
61
+ };
@@ -0,0 +1 @@
1
+ "use strict";var d=i=>{throw TypeError(i)};var l=(i,e,t)=>e.has(i)||d("Cannot "+t);var o=(i,e,t)=>(l(i,e,"read from private field"),t?t.call(i):e.get(i)),f=(i,e,t)=>e.has(i)?d("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),w=(i,e,t,s)=>(l(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),a=require("./index5.cjs"),y=require("./index4.cjs");var r;const h=class h{constructor(e){f(this,r);this.address="",this.sendBitcoin=async(t,s)=>{const c=await new Promise(k=>{o(this,r).request({method:"transfer",params:[{feeRate:10,from:this.address,recipient:t,amount:{amount:s,decimals:8},memo:"Send Bitcoin"}]},(N,g)=>{k({error:N,txHash:g})})});return c.error?n.Err(c.error):n.Ok(c.txHash)},this.on=(t,s)=>o(this,r).on(t,s),this.off=(t,s)=>o(this,r).off(t,s),this.disconnect=()=>(this.address="",Promise.resolve(n.Ok("Disconnected xdefi wallet"))),w(this,r,e)}async connect(e){try{if(!window.xfi||!window.xfi.bitcoin)return n.Err("Xdefi wallet not found");e||(e=a.Network.MAINNET);const t=await o(this,r).getAccounts();if(t.length===0)return n.Err("No accounts found in Xdefi wallet");const s=new h(window.xfi.bitcoin);return w(this,r,o(s,r)),this.address=t[0],o(s,r).network!==e&&await this.switchNetwork(),n.Ok({address:t[0],provider:s,network:o(s,r).network})}catch(t){return n.Err("Error while connecting to the Xdefi wallet",t)}}async requestAccounts(){return await n.executeWithTryCatch(async()=>await o(this,r).requestAccounts(),"Error while requesting accounts from the Xdefi wallet")}async getAccounts(){return await n.executeWithTryCatch(async()=>await o(this,r).getAccounts(),"Error while getting accounts from the Xdefi wallet")}async getNetwork(){return n.Ok(o(this,r).network)}async switchNetwork(){try{const t=(await this.getNetwork()).val===a.Network.MAINNET?a.Network.TESTNET:a.Network.MAINNET;await o(this,r).changeNetwork(t);const s=await this.getAccounts();return this.address=s.val[0],n.Ok(t)}catch(e){return n.Err("Error while switching networks in the Xdefi wallet:",e)}}async getPublicKey(){return n.Err("not available in Xdefi wallet")}async getBalance(){const e=await this.getNetwork(),t=await y.getBalance(this.address,e.val);return t.error?n.Err(t.error):n.Ok(t.val)}};r=new WeakMap;let u=h;exports.XdefiProvider=u;
package/dist/index9.js ADDED
@@ -0,0 +1,95 @@
1
+ var d = (i) => {
2
+ throw TypeError(i);
3
+ };
4
+ var l = (i, e, t) => e.has(i) || d("Cannot " + t);
5
+ var s = (i, e, t) => (l(i, e, "read from private field"), t ? t.call(i) : e.get(i)), f = (i, e, t) => e.has(i) ? d("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), h = (i, e, t, n) => (l(i, e, "write to private field"), n ? n.call(i, t) : e.set(i, t), t);
6
+ import { Err as o, Ok as a, executeWithTryCatch as m } from "@catalogfi/utils";
7
+ import { Network as c } from "./index5.js";
8
+ import { getBalance as E } from "./index4.js";
9
+ var r;
10
+ const u = class u {
11
+ constructor(e) {
12
+ f(this, r);
13
+ this.address = "", this.sendBitcoin = async (t, n) => {
14
+ const w = await new Promise((g) => {
15
+ s(this, r).request(
16
+ {
17
+ method: "transfer",
18
+ params: [
19
+ {
20
+ feeRate: 10,
21
+ from: this.address,
22
+ recipient: t,
23
+ amount: {
24
+ amount: n,
25
+ decimals: 8
26
+ },
27
+ memo: "Send Bitcoin"
28
+ }
29
+ ]
30
+ },
31
+ (k, y) => {
32
+ g({ error: k, txHash: y });
33
+ }
34
+ );
35
+ });
36
+ return w.error ? o(w.error) : a(w.txHash);
37
+ }, this.on = (t, n) => s(this, r).on(t, n), this.off = (t, n) => s(this, r).off(t, n), this.disconnect = () => (this.address = "", Promise.resolve(a("Disconnected xdefi wallet"))), h(this, r, e);
38
+ }
39
+ async connect(e) {
40
+ try {
41
+ if (!window.xfi || !window.xfi.bitcoin)
42
+ return o("Xdefi wallet not found");
43
+ e || (e = c.MAINNET);
44
+ const t = await s(this, r).getAccounts();
45
+ if (t.length === 0) return o("No accounts found in Xdefi wallet");
46
+ const n = new u(window.xfi.bitcoin);
47
+ return h(this, r, s(n, r)), this.address = t[0], s(n, r).network !== e && await this.switchNetwork(), a({
48
+ address: t[0],
49
+ provider: n,
50
+ network: s(n, r).network
51
+ });
52
+ } catch (t) {
53
+ return o("Error while connecting to the Xdefi wallet", t);
54
+ }
55
+ }
56
+ // requests accounts from the wallet, if not connected, it will connect first
57
+ async requestAccounts() {
58
+ return await m(
59
+ async () => await s(this, r).requestAccounts(),
60
+ "Error while requesting accounts from the Xdefi wallet"
61
+ );
62
+ }
63
+ //silently gets accounts if already connected
64
+ async getAccounts() {
65
+ return await m(
66
+ async () => await s(this, r).getAccounts(),
67
+ "Error while getting accounts from the Xdefi wallet"
68
+ );
69
+ }
70
+ async getNetwork() {
71
+ return a(s(this, r).network);
72
+ }
73
+ async switchNetwork() {
74
+ try {
75
+ const t = (await this.getNetwork()).val === c.MAINNET ? c.TESTNET : c.MAINNET;
76
+ await s(this, r).changeNetwork(t);
77
+ const n = await this.getAccounts();
78
+ return this.address = n.val[0], a(t);
79
+ } catch (e) {
80
+ return o("Error while switching networks in the Xdefi wallet:", e);
81
+ }
82
+ }
83
+ async getPublicKey() {
84
+ return o("not available in Xdefi wallet");
85
+ }
86
+ async getBalance() {
87
+ const e = await this.getNetwork(), t = await E(this.address, e.val);
88
+ return t.error ? o(t.error) : a(t.val);
89
+ }
90
+ };
91
+ r = new WeakMap();
92
+ let N = u;
93
+ export {
94
+ N as XdefiProvider
95
+ };
@@ -0,0 +1,53 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+
3
+ export type Balance = {
4
+ confirmed: number;
5
+ unconfirmed: number;
6
+ total: number;
7
+ };
8
+ export type Connect = {
9
+ address: string;
10
+ provider: IInjectedBitcoinProvider;
11
+ network: Network;
12
+ };
13
+ export interface IInjectedBitcoinProvider {
14
+ address: string;
15
+ getBalance: () => AsyncResult<Balance, string>;
16
+ /**
17
+ * requests accounts from the wallet, if not connected, it will connect first
18
+ * @returns {AsyncResult<string[], string>}
19
+ */
20
+ requestAccounts: () => AsyncResult<string[], string>;
21
+ /**
22
+ * silently gets accounts if already connected
23
+ * @returns {AsyncResult<string[], string>}
24
+ */
25
+ getAccounts: () => AsyncResult<string[], string>;
26
+ sendBitcoin: (toAddress: string, satoshis: number) => AsyncResult<string, string>;
27
+ getNetwork: () => AsyncResult<Network, string>;
28
+ switchNetwork: () => AsyncResult<Network, string>;
29
+ connect: (network?: Network) => AsyncResult<Connect, string>;
30
+ disconnect: () => AsyncResult<string, string>;
31
+ on: (event: string, callback: (data: any) => void) => void;
32
+ off: (event: string, callback: (data: any) => void) => void;
33
+ }
34
+ export declare enum Network {
35
+ MAINNET = "mainnet",
36
+ TESTNET = "testnet"
37
+ }
38
+ export type SelectedAccount = {
39
+ address: string;
40
+ publicKey: string;
41
+ };
42
+ export interface BitcoinWallet {
43
+ name: string;
44
+ symbol: string;
45
+ connect: () => AsyncResult<IInjectedBitcoinProvider, string>;
46
+ }
47
+ export declare enum BitcoinWallets {
48
+ OKX_WALLET = "OKX_WALLET",
49
+ UNISAT = "UNISAT",
50
+ XVERSE = "XVERSE",
51
+ XDEFI = "XDEFI",
52
+ PHANTOM = "PHANTOM"
53
+ }
@@ -0,0 +1,41 @@
1
+ import { default as React, ReactNode } from 'react';
2
+ import { IInjectedBitcoinProvider, Network } from './bitcoin.types';
3
+ import { OKXBitcoinProvider } from './providers/okx/okx.types';
4
+ import { AsyncResult, Result } from '@catalogfi/utils';
5
+ import { UnisatBitcoinProvider } from './providers/unisat/unisat.types';
6
+ import { XVerseBitcoinProvider } from './providers/xverse/xverse.types';
7
+ import { XdefiBitcoinProvider } from './providers/xdefi/xdefi.types';
8
+ import { PhantomBitcoinProvider } from './providers/phantom/phantom.types';
9
+
10
+ declare global {
11
+ interface Window {
12
+ okxwallet?: {
13
+ bitcoin?: OKXBitcoinProvider;
14
+ bitcoinTestnet?: OKXBitcoinProvider;
15
+ };
16
+ XverseProviders?: {
17
+ BitcoinProvider: XVerseBitcoinProvider;
18
+ };
19
+ unisat?: UnisatBitcoinProvider;
20
+ xfi?: {
21
+ bitcoin: XdefiBitcoinProvider;
22
+ };
23
+ phantom?: {
24
+ bitcoin: PhantomBitcoinProvider;
25
+ };
26
+ }
27
+ }
28
+ export declare const BTCWalletProvider: ({ children }: {
29
+ children: ReactNode;
30
+ }) => React.JSX.Element;
31
+ export declare const useBitcoinWallet: () => {
32
+ walletList: {
33
+ [key: string]: IInjectedBitcoinProvider;
34
+ };
35
+ connect: (BitcoinWallet: IInjectedBitcoinProvider, network?: Network) => AsyncResult<void, string>;
36
+ updateAccount: () => Promise<void>;
37
+ provider: IInjectedBitcoinProvider | undefined;
38
+ account: string | undefined;
39
+ network: Network | undefined;
40
+ disconnect: () => Result<void, string>;
41
+ };
@@ -0,0 +1,27 @@
1
+ export declare const SupportedWallets: {
2
+ OKX: {
3
+ name: string;
4
+ icon: string;
5
+ description: string;
6
+ };
7
+ Unisat: {
8
+ name: string;
9
+ icon: string;
10
+ description: string;
11
+ };
12
+ Xverse: {
13
+ name: string;
14
+ icon: string;
15
+ description: string;
16
+ };
17
+ Xdefi: {
18
+ name: string;
19
+ icon: string;
20
+ description: string;
21
+ };
22
+ Phantom: {
23
+ name: string;
24
+ icon: string;
25
+ description: string;
26
+ };
27
+ };
@@ -0,0 +1,3 @@
1
+ export { BTCWalletProvider, useBitcoinWallet } from './btcWalletsProvider';
2
+ export { SupportedWallets } from './constants';
3
+ export { getBalance } from './utils';
@@ -0,0 +1,33 @@
1
+ import { Network, SelectedAccount } from 'src/bitcoin/bitcoin.types';
2
+
3
+ export interface OKXBitcoinProvider {
4
+ selectedAccount: SelectedAccount;
5
+ connect: () => Promise<{
6
+ address: string;
7
+ publicKey: string;
8
+ }>;
9
+ requestAccounts: () => Promise<string[]>;
10
+ getAccounts: () => Promise<string[]>;
11
+ getNetwork: () => Promise<string>;
12
+ switchNetwork: (network: Network) => Promise<string>;
13
+ getPublicKey: () => Promise<string>;
14
+ getBalance: () => Promise<{
15
+ confirmed: number;
16
+ unconfirmed: number;
17
+ total: number;
18
+ }>;
19
+ sendBitcoin: (toAddress: string, satoshis: number) => Promise<string>;
20
+ send: (params: {
21
+ from: string;
22
+ to: string;
23
+ value: string;
24
+ satBytes?: string;
25
+ memo?: string;
26
+ memoPos?: number;
27
+ }) => Promise<{
28
+ txhash: string;
29
+ }>;
30
+ on: (event: string, callback: (data: any) => void) => void;
31
+ off: (event: string, callback: (data: any) => void) => void;
32
+ disconnect: () => void;
33
+ }
@@ -0,0 +1,28 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+ import { IInjectedBitcoinProvider, Network } from '../../bitcoin.types';
3
+ import { OKXBitcoinProvider } from './okx.types';
4
+
5
+ export declare class OKXProvider implements IInjectedBitcoinProvider {
6
+ #private;
7
+ address: string;
8
+ constructor(mainnetProvider: OKXBitcoinProvider, testnetProvider: OKXBitcoinProvider);
9
+ connect(network?: Network): AsyncResult<{
10
+ address: string;
11
+ provider: IInjectedBitcoinProvider;
12
+ network: Network;
13
+ }, string>;
14
+ getPublicKey(): AsyncResult<string, string>;
15
+ requestAccounts(): AsyncResult<string[], string>;
16
+ getAccounts(): AsyncResult<string[], string>;
17
+ getNetwork(): AsyncResult<Network, string>;
18
+ switchNetwork(): AsyncResult<Network, string>;
19
+ getBalance(): AsyncResult<{
20
+ confirmed: number;
21
+ unconfirmed: number;
22
+ total: number;
23
+ }, string>;
24
+ sendBitcoin(toAddress: string, satoshis: number): AsyncResult<string, string>;
25
+ on(event: string, callback: (data: any) => void): void;
26
+ off(event: string, callback: (data: any) => void): void;
27
+ disconnect: () => AsyncResult<string, string>;
28
+ }
@@ -0,0 +1,30 @@
1
+ import { Network } from 'src/bitcoin/bitcoin.types';
2
+
3
+ export interface PhantomBitcoinProvider {
4
+ connect: (network: Network) => Promise<{
5
+ address: string;
6
+ publicKey: string;
7
+ }>;
8
+ requestAccounts: () => Promise<{
9
+ address: string;
10
+ addressType: string;
11
+ publicKey: string;
12
+ purpose: string;
13
+ }[]>;
14
+ getBalance: () => Promise<{
15
+ confirmed: number;
16
+ unconfirmed: number;
17
+ total: number;
18
+ }>;
19
+ sendBitcoin: (toAddress: string, satoshis: number) => Promise<string>;
20
+ signPSBT: (psbt: Uint8Array, options: {
21
+ inputsToSign: {
22
+ sigHash?: number | undefined;
23
+ address: string;
24
+ signingIndexes: number[];
25
+ }[];
26
+ }) => Promise<Uint8Array>;
27
+ on: (event: string, callback: (data: any) => void) => void;
28
+ off: (event: string, callback: (data: any) => void) => void;
29
+ disconnect: () => void;
30
+ }