@rhea-finance/confidential-swap 0.3.4 → 0.3.6
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/index.cjs +24 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -600,6 +600,17 @@ function validateSigned(unsigned, signed, identity) {
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
// src/api.ts
|
|
603
|
+
function toMultiPayload(data) {
|
|
604
|
+
if (data.standard !== "tip191") return data;
|
|
605
|
+
if (data.signature.startsWith("secp256k1:")) {
|
|
606
|
+
const bytes2 = import_base4.base58.decode(data.signature.slice("secp256k1:".length));
|
|
607
|
+
responseAssert(bytes2.length === 65 && bytes2[64] <= 1, "Invalid TIP-191 signature.");
|
|
608
|
+
return data;
|
|
609
|
+
}
|
|
610
|
+
const bytes = import_base4.base16.decode(normalizeSecpSignature(data.signature).slice(2).toUpperCase());
|
|
611
|
+
bytes[64] = bytes[64] - 27;
|
|
612
|
+
return { ...data, signature: `secp256k1:${import_base4.base58.encode(bytes)}` };
|
|
613
|
+
}
|
|
603
614
|
function record(value) {
|
|
604
615
|
responseAssert(value && typeof value === "object" && !Array.isArray(value), "Expected an object response.");
|
|
605
616
|
return value;
|
|
@@ -646,7 +657,7 @@ var HttpConfidentialApi = class {
|
|
|
646
657
|
proxy;
|
|
647
658
|
indexer;
|
|
648
659
|
appFees;
|
|
649
|
-
async request(url, method = "GET", body, token, signal) {
|
|
660
|
+
async request(url, method = "GET", body, token, signal, accessHeader = "authentication") {
|
|
650
661
|
throwIfAborted(signal);
|
|
651
662
|
const timeout = AbortSignal.timeout(this.config.requestTimeoutMs ?? 3e4);
|
|
652
663
|
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
@@ -657,8 +668,7 @@ var HttpConfidentialApi = class {
|
|
|
657
668
|
headers: {
|
|
658
669
|
Accept: "application/json",
|
|
659
670
|
...body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
660
|
-
|
|
661
|
-
...token ? { authentication: `Bearer ${token}` } : {}
|
|
671
|
+
...token ? { [accessHeader]: `Bearer ${token}` } : {}
|
|
662
672
|
},
|
|
663
673
|
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
664
674
|
});
|
|
@@ -725,7 +735,7 @@ var HttpConfidentialApi = class {
|
|
|
725
735
|
return { accessToken: r.accessToken, refreshToken, expiresAt: this.now() + r.expiresIn * 1e3, refreshExpiresAt };
|
|
726
736
|
}
|
|
727
737
|
async authenticate(data, signal) {
|
|
728
|
-
return this.session(await this.request(`${this.proxy}/auth/authenticate`, "POST", { signedData: data }, void 0, signal));
|
|
738
|
+
return this.session(await this.request(`${this.proxy}/auth/authenticate`, "POST", { signedData: toMultiPayload(data) }, void 0, signal));
|
|
729
739
|
}
|
|
730
740
|
async refresh(session, signal) {
|
|
731
741
|
return this.session(await this.request(`${this.proxy}/auth/refresh`, "POST", { refreshToken: session.refreshToken }, void 0, signal), session);
|
|
@@ -741,7 +751,14 @@ var HttpConfidentialApi = class {
|
|
|
741
751
|
});
|
|
742
752
|
}
|
|
743
753
|
async getBalances(token, signal) {
|
|
744
|
-
const data = record(await this.request(
|
|
754
|
+
const data = record(await this.request(
|
|
755
|
+
`${this.direct}/account/balances`,
|
|
756
|
+
"GET",
|
|
757
|
+
void 0,
|
|
758
|
+
text(token, "Access token"),
|
|
759
|
+
signal,
|
|
760
|
+
"authorization"
|
|
761
|
+
));
|
|
745
762
|
responseAssert(Array.isArray(data.balances), "Invalid balances.");
|
|
746
763
|
return data.balances.map((b) => {
|
|
747
764
|
const r = record(b);
|
|
@@ -784,7 +801,7 @@ var HttpConfidentialApi = class {
|
|
|
784
801
|
return data.intent;
|
|
785
802
|
}
|
|
786
803
|
async submitIntent(signedData, signal) {
|
|
787
|
-
const data = record(await this.request(`${this.proxy}/submit-intent`, "POST", { type: "swap_transfer", signedData }, void 0, signal));
|
|
804
|
+
const data = record(await this.request(`${this.proxy}/submit-intent`, "POST", { type: "swap_transfer", signedData: toMultiPayload(signedData) }, void 0, signal));
|
|
788
805
|
return text(data.intentHash, "Intent hash");
|
|
789
806
|
}
|
|
790
807
|
async privateRequest(path, method, body, token, signal) {
|
|
@@ -800,7 +817,7 @@ var HttpConfidentialApi = class {
|
|
|
800
817
|
const data = record(await this.privateRequest(
|
|
801
818
|
"withdraws",
|
|
802
819
|
"POST",
|
|
803
|
-
request,
|
|
820
|
+
{ ...request, withdraws: request.withdraws.map((row) => ({ ...row, signed_payload: toMultiPayload(row.signed_payload) })) },
|
|
804
821
|
this.config.withdrawAuthorization === "bearer" ? token : void 0,
|
|
805
822
|
signal
|
|
806
823
|
));
|