bsv-x402 0.8.0 → 0.9.0
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 +48 -4
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +48 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -573,7 +573,18 @@ async function constructBrc105Proof(challenge, wallet, origin) {
|
|
|
573
573
|
console.warn("[x402] abortAction failed:", err);
|
|
574
574
|
}
|
|
575
575
|
} : void 0;
|
|
576
|
-
|
|
576
|
+
const broadcast = wallet.createAction ? async () => {
|
|
577
|
+
try {
|
|
578
|
+
await wallet.createAction({
|
|
579
|
+
description: "Broadcast x402 payment",
|
|
580
|
+
outputs: [],
|
|
581
|
+
options: { sendWith: [result.txid] }
|
|
582
|
+
});
|
|
583
|
+
} catch (err) {
|
|
584
|
+
console.warn("[x402] broadcast failed:", err);
|
|
585
|
+
}
|
|
586
|
+
} : void 0;
|
|
587
|
+
return { proof, abort, broadcast };
|
|
577
588
|
}
|
|
578
589
|
|
|
579
590
|
// src/brc121-challenge.ts
|
|
@@ -663,7 +674,18 @@ async function constructBrc121Proof(challenge, wallet, origin) {
|
|
|
663
674
|
console.warn("[x402] abortAction failed:", err);
|
|
664
675
|
}
|
|
665
676
|
} : void 0;
|
|
666
|
-
|
|
677
|
+
const broadcast = wallet.createAction ? async () => {
|
|
678
|
+
try {
|
|
679
|
+
await wallet.createAction({
|
|
680
|
+
description: "Broadcast x402 payment",
|
|
681
|
+
outputs: [],
|
|
682
|
+
options: { sendWith: [result.txid] }
|
|
683
|
+
});
|
|
684
|
+
} catch (err) {
|
|
685
|
+
console.warn("[x402] broadcast failed:", err);
|
|
686
|
+
}
|
|
687
|
+
} : void 0;
|
|
688
|
+
return { proof, abort, broadcast };
|
|
667
689
|
}
|
|
668
690
|
|
|
669
691
|
// src/challenge.ts
|
|
@@ -911,10 +933,12 @@ function createX402Fetch(config = {}) {
|
|
|
911
933
|
};
|
|
912
934
|
let proof;
|
|
913
935
|
let abort;
|
|
936
|
+
let broadcast;
|
|
914
937
|
try {
|
|
915
938
|
const result = await buildProof();
|
|
916
939
|
proof = result.proof;
|
|
917
940
|
abort = result.abort;
|
|
941
|
+
broadcast = result.broadcast;
|
|
918
942
|
} catch (err) {
|
|
919
943
|
console.error("[x402] Proof construction failed (brc105):", err);
|
|
920
944
|
config.onProofError?.(err, "brc105");
|
|
@@ -940,6 +964,9 @@ function createX402Fetch(config = {}) {
|
|
|
940
964
|
);
|
|
941
965
|
}
|
|
942
966
|
if (retryResponse.ok) {
|
|
967
|
+
if (broadcast) {
|
|
968
|
+
broadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
969
|
+
}
|
|
943
970
|
await processPendingBeefs(retryResponse);
|
|
944
971
|
return retryResponse;
|
|
945
972
|
}
|
|
@@ -953,10 +980,12 @@ function createX402Fetch(config = {}) {
|
|
|
953
980
|
}
|
|
954
981
|
let freshProof;
|
|
955
982
|
let freshAbort;
|
|
983
|
+
let freshBroadcast;
|
|
956
984
|
try {
|
|
957
985
|
const result = await buildProof();
|
|
958
986
|
freshProof = result.proof;
|
|
959
987
|
freshAbort = result.abort;
|
|
988
|
+
freshBroadcast = result.broadcast;
|
|
960
989
|
} catch (err) {
|
|
961
990
|
console.error("[x402] Fresh proof construction failed (brc105):", err);
|
|
962
991
|
config.onProofError?.(err, "brc105");
|
|
@@ -970,7 +999,11 @@ function createX402Fetch(config = {}) {
|
|
|
970
999
|
"[x402] Payment state unknown: network error on fresh retry. The transaction may have been broadcast \u2014 do not retry with a new transaction without checking on-chain state."
|
|
971
1000
|
);
|
|
972
1001
|
}
|
|
973
|
-
if (
|
|
1002
|
+
if (freshResponse.ok) {
|
|
1003
|
+
if (freshBroadcast) {
|
|
1004
|
+
freshBroadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
1005
|
+
}
|
|
1006
|
+
} else if (freshAbort) {
|
|
974
1007
|
try {
|
|
975
1008
|
await freshAbort();
|
|
976
1009
|
console.warn("[x402] Server rejected fresh BRC-105 payment, UTXOs released via abortAction");
|
|
@@ -1010,10 +1043,12 @@ function createX402Fetch(config = {}) {
|
|
|
1010
1043
|
};
|
|
1011
1044
|
let proof;
|
|
1012
1045
|
let abort;
|
|
1046
|
+
let broadcast;
|
|
1013
1047
|
try {
|
|
1014
1048
|
const result = await buildProof();
|
|
1015
1049
|
proof = result.proof;
|
|
1016
1050
|
abort = result.abort;
|
|
1051
|
+
broadcast = result.broadcast;
|
|
1017
1052
|
} catch (err) {
|
|
1018
1053
|
console.error("[x402] Proof construction failed (brc121):", err);
|
|
1019
1054
|
config.onProofError?.(err, "brc121");
|
|
@@ -1039,6 +1074,9 @@ function createX402Fetch(config = {}) {
|
|
|
1039
1074
|
);
|
|
1040
1075
|
}
|
|
1041
1076
|
if (retryResponse.ok) {
|
|
1077
|
+
if (broadcast) {
|
|
1078
|
+
broadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
1079
|
+
}
|
|
1042
1080
|
await processPendingBeefs(retryResponse);
|
|
1043
1081
|
return retryResponse;
|
|
1044
1082
|
}
|
|
@@ -1052,10 +1090,12 @@ function createX402Fetch(config = {}) {
|
|
|
1052
1090
|
}
|
|
1053
1091
|
let freshProof;
|
|
1054
1092
|
let freshAbort;
|
|
1093
|
+
let freshBroadcast;
|
|
1055
1094
|
try {
|
|
1056
1095
|
const result = await buildProof();
|
|
1057
1096
|
freshProof = result.proof;
|
|
1058
1097
|
freshAbort = result.abort;
|
|
1098
|
+
freshBroadcast = result.broadcast;
|
|
1059
1099
|
} catch (err) {
|
|
1060
1100
|
console.error("[x402] Fresh proof construction failed (brc121):", err);
|
|
1061
1101
|
config.onProofError?.(err, "brc121");
|
|
@@ -1069,7 +1109,11 @@ function createX402Fetch(config = {}) {
|
|
|
1069
1109
|
"[x402] Payment state unknown: network error on fresh retry. The transaction may have been broadcast \u2014 do not retry with a new transaction without checking on-chain state."
|
|
1070
1110
|
);
|
|
1071
1111
|
}
|
|
1072
|
-
if (
|
|
1112
|
+
if (freshResponse.ok) {
|
|
1113
|
+
if (freshBroadcast) {
|
|
1114
|
+
freshBroadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
1115
|
+
}
|
|
1116
|
+
} else if (freshAbort) {
|
|
1073
1117
|
try {
|
|
1074
1118
|
await freshAbort();
|
|
1075
1119
|
console.warn("[x402] Server rejected fresh BRC-121 payment, UTXOs released via abortAction");
|
package/dist/index.d.cts
CHANGED
|
@@ -53,6 +53,7 @@ interface Brc105Proof {
|
|
|
53
53
|
interface Brc105ProofResult {
|
|
54
54
|
proof: Brc105Proof;
|
|
55
55
|
abort?: () => Promise<void>;
|
|
56
|
+
broadcast?: () => Promise<void>;
|
|
56
57
|
}
|
|
57
58
|
type Brc105ProofConstructor = (challenge: Brc105Challenge) => Promise<Brc105ProofResult>;
|
|
58
59
|
/** BRC-121 challenge parsed from 402 response headers. */
|
|
@@ -73,6 +74,7 @@ interface Brc121Proof {
|
|
|
73
74
|
interface Brc121ProofResult {
|
|
74
75
|
proof: Brc121Proof;
|
|
75
76
|
abort?: () => Promise<void>;
|
|
77
|
+
broadcast?: () => Promise<void>;
|
|
76
78
|
}
|
|
77
79
|
/** Custom BRC-121 proof constructor. */
|
|
78
80
|
type Brc121ProofConstructor = (challenge: Brc121Challenge) => Promise<Brc121ProofResult>;
|
|
@@ -151,6 +153,7 @@ interface CWICreateActionParams {
|
|
|
151
153
|
returnTXIDOnly?: boolean;
|
|
152
154
|
noSend?: boolean;
|
|
153
155
|
randomizeOutputs?: boolean;
|
|
156
|
+
sendWith?: string[];
|
|
154
157
|
};
|
|
155
158
|
}
|
|
156
159
|
interface CWICreateActionResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ interface Brc105Proof {
|
|
|
53
53
|
interface Brc105ProofResult {
|
|
54
54
|
proof: Brc105Proof;
|
|
55
55
|
abort?: () => Promise<void>;
|
|
56
|
+
broadcast?: () => Promise<void>;
|
|
56
57
|
}
|
|
57
58
|
type Brc105ProofConstructor = (challenge: Brc105Challenge) => Promise<Brc105ProofResult>;
|
|
58
59
|
/** BRC-121 challenge parsed from 402 response headers. */
|
|
@@ -73,6 +74,7 @@ interface Brc121Proof {
|
|
|
73
74
|
interface Brc121ProofResult {
|
|
74
75
|
proof: Brc121Proof;
|
|
75
76
|
abort?: () => Promise<void>;
|
|
77
|
+
broadcast?: () => Promise<void>;
|
|
76
78
|
}
|
|
77
79
|
/** Custom BRC-121 proof constructor. */
|
|
78
80
|
type Brc121ProofConstructor = (challenge: Brc121Challenge) => Promise<Brc121ProofResult>;
|
|
@@ -151,6 +153,7 @@ interface CWICreateActionParams {
|
|
|
151
153
|
returnTXIDOnly?: boolean;
|
|
152
154
|
noSend?: boolean;
|
|
153
155
|
randomizeOutputs?: boolean;
|
|
156
|
+
sendWith?: string[];
|
|
154
157
|
};
|
|
155
158
|
}
|
|
156
159
|
interface CWICreateActionResult {
|
package/dist/index.js
CHANGED
|
@@ -533,7 +533,18 @@ async function constructBrc105Proof(challenge, wallet, origin) {
|
|
|
533
533
|
console.warn("[x402] abortAction failed:", err);
|
|
534
534
|
}
|
|
535
535
|
} : void 0;
|
|
536
|
-
|
|
536
|
+
const broadcast = wallet.createAction ? async () => {
|
|
537
|
+
try {
|
|
538
|
+
await wallet.createAction({
|
|
539
|
+
description: "Broadcast x402 payment",
|
|
540
|
+
outputs: [],
|
|
541
|
+
options: { sendWith: [result.txid] }
|
|
542
|
+
});
|
|
543
|
+
} catch (err) {
|
|
544
|
+
console.warn("[x402] broadcast failed:", err);
|
|
545
|
+
}
|
|
546
|
+
} : void 0;
|
|
547
|
+
return { proof, abort, broadcast };
|
|
537
548
|
}
|
|
538
549
|
|
|
539
550
|
// src/brc121-challenge.ts
|
|
@@ -623,7 +634,18 @@ async function constructBrc121Proof(challenge, wallet, origin) {
|
|
|
623
634
|
console.warn("[x402] abortAction failed:", err);
|
|
624
635
|
}
|
|
625
636
|
} : void 0;
|
|
626
|
-
|
|
637
|
+
const broadcast = wallet.createAction ? async () => {
|
|
638
|
+
try {
|
|
639
|
+
await wallet.createAction({
|
|
640
|
+
description: "Broadcast x402 payment",
|
|
641
|
+
outputs: [],
|
|
642
|
+
options: { sendWith: [result.txid] }
|
|
643
|
+
});
|
|
644
|
+
} catch (err) {
|
|
645
|
+
console.warn("[x402] broadcast failed:", err);
|
|
646
|
+
}
|
|
647
|
+
} : void 0;
|
|
648
|
+
return { proof, abort, broadcast };
|
|
627
649
|
}
|
|
628
650
|
|
|
629
651
|
// src/challenge.ts
|
|
@@ -871,10 +893,12 @@ function createX402Fetch(config = {}) {
|
|
|
871
893
|
};
|
|
872
894
|
let proof;
|
|
873
895
|
let abort;
|
|
896
|
+
let broadcast;
|
|
874
897
|
try {
|
|
875
898
|
const result = await buildProof();
|
|
876
899
|
proof = result.proof;
|
|
877
900
|
abort = result.abort;
|
|
901
|
+
broadcast = result.broadcast;
|
|
878
902
|
} catch (err) {
|
|
879
903
|
console.error("[x402] Proof construction failed (brc105):", err);
|
|
880
904
|
config.onProofError?.(err, "brc105");
|
|
@@ -900,6 +924,9 @@ function createX402Fetch(config = {}) {
|
|
|
900
924
|
);
|
|
901
925
|
}
|
|
902
926
|
if (retryResponse.ok) {
|
|
927
|
+
if (broadcast) {
|
|
928
|
+
broadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
929
|
+
}
|
|
903
930
|
await processPendingBeefs(retryResponse);
|
|
904
931
|
return retryResponse;
|
|
905
932
|
}
|
|
@@ -913,10 +940,12 @@ function createX402Fetch(config = {}) {
|
|
|
913
940
|
}
|
|
914
941
|
let freshProof;
|
|
915
942
|
let freshAbort;
|
|
943
|
+
let freshBroadcast;
|
|
916
944
|
try {
|
|
917
945
|
const result = await buildProof();
|
|
918
946
|
freshProof = result.proof;
|
|
919
947
|
freshAbort = result.abort;
|
|
948
|
+
freshBroadcast = result.broadcast;
|
|
920
949
|
} catch (err) {
|
|
921
950
|
console.error("[x402] Fresh proof construction failed (brc105):", err);
|
|
922
951
|
config.onProofError?.(err, "brc105");
|
|
@@ -930,7 +959,11 @@ function createX402Fetch(config = {}) {
|
|
|
930
959
|
"[x402] Payment state unknown: network error on fresh retry. The transaction may have been broadcast \u2014 do not retry with a new transaction without checking on-chain state."
|
|
931
960
|
);
|
|
932
961
|
}
|
|
933
|
-
if (
|
|
962
|
+
if (freshResponse.ok) {
|
|
963
|
+
if (freshBroadcast) {
|
|
964
|
+
freshBroadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
965
|
+
}
|
|
966
|
+
} else if (freshAbort) {
|
|
934
967
|
try {
|
|
935
968
|
await freshAbort();
|
|
936
969
|
console.warn("[x402] Server rejected fresh BRC-105 payment, UTXOs released via abortAction");
|
|
@@ -970,10 +1003,12 @@ function createX402Fetch(config = {}) {
|
|
|
970
1003
|
};
|
|
971
1004
|
let proof;
|
|
972
1005
|
let abort;
|
|
1006
|
+
let broadcast;
|
|
973
1007
|
try {
|
|
974
1008
|
const result = await buildProof();
|
|
975
1009
|
proof = result.proof;
|
|
976
1010
|
abort = result.abort;
|
|
1011
|
+
broadcast = result.broadcast;
|
|
977
1012
|
} catch (err) {
|
|
978
1013
|
console.error("[x402] Proof construction failed (brc121):", err);
|
|
979
1014
|
config.onProofError?.(err, "brc121");
|
|
@@ -999,6 +1034,9 @@ function createX402Fetch(config = {}) {
|
|
|
999
1034
|
);
|
|
1000
1035
|
}
|
|
1001
1036
|
if (retryResponse.ok) {
|
|
1037
|
+
if (broadcast) {
|
|
1038
|
+
broadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
1039
|
+
}
|
|
1002
1040
|
await processPendingBeefs(retryResponse);
|
|
1003
1041
|
return retryResponse;
|
|
1004
1042
|
}
|
|
@@ -1012,10 +1050,12 @@ function createX402Fetch(config = {}) {
|
|
|
1012
1050
|
}
|
|
1013
1051
|
let freshProof;
|
|
1014
1052
|
let freshAbort;
|
|
1053
|
+
let freshBroadcast;
|
|
1015
1054
|
try {
|
|
1016
1055
|
const result = await buildProof();
|
|
1017
1056
|
freshProof = result.proof;
|
|
1018
1057
|
freshAbort = result.abort;
|
|
1058
|
+
freshBroadcast = result.broadcast;
|
|
1019
1059
|
} catch (err) {
|
|
1020
1060
|
console.error("[x402] Fresh proof construction failed (brc121):", err);
|
|
1021
1061
|
config.onProofError?.(err, "brc121");
|
|
@@ -1029,7 +1069,11 @@ function createX402Fetch(config = {}) {
|
|
|
1029
1069
|
"[x402] Payment state unknown: network error on fresh retry. The transaction may have been broadcast \u2014 do not retry with a new transaction without checking on-chain state."
|
|
1030
1070
|
);
|
|
1031
1071
|
}
|
|
1032
|
-
if (
|
|
1072
|
+
if (freshResponse.ok) {
|
|
1073
|
+
if (freshBroadcast) {
|
|
1074
|
+
freshBroadcast().catch((err) => console.warn("[x402] broadcast failed:", err));
|
|
1075
|
+
}
|
|
1076
|
+
} else if (freshAbort) {
|
|
1033
1077
|
try {
|
|
1034
1078
|
await freshAbort();
|
|
1035
1079
|
console.warn("[x402] Server rejected fresh BRC-121 payment, UTXOs released via abortAction");
|