@ic-pay/icpay-sdk 1.4.77 → 1.4.84
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.d.ts.map +1 -1
- package/dist/index.js +309 -172
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAoB,cAAc,EAAE,MAAM,UAAU,CAAC;AAO5D,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAoB,cAAc,EAAE,MAAM,UAAU,CAAC;AAO5D,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAyL/D,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAC,CAAwC;IAC9D,OAAO,CAAC,e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AAG,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAsD9G;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAqDtF;;;OAGG;IACG,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAsmC1F;;;;OAIG;IACH,yBAAyB,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE;IAgC3H,6DAA6D;YAC/C,0BAA0B;YAkD1B,mBAAmB;IAkE/B;;KAEC;IACG,uBAAuB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IA0CrD;;OAEG;IACH,OAAO,CAAC,aAAa;CAUtB;AAGD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,cAAc,UAAU,CAAC;AAGzB,eAAe,KAAK,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -118,6 +118,122 @@ function u8FromBase64(b64) {
|
|
|
118
118
|
arr[i] = bin.charCodeAt(i);
|
|
119
119
|
return arr;
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Normalize Solana signTransaction result to base64 signed transaction.
|
|
123
|
+
* Wallets may return: signedTransaction, transaction, signedMessage (string base64/base58),
|
|
124
|
+
* serializedTransaction (Uint8Array), or the raw value. Phantom may return base58.
|
|
125
|
+
*/
|
|
126
|
+
function normalizeSolanaSignedTransaction(r) {
|
|
127
|
+
if (r == null)
|
|
128
|
+
return null;
|
|
129
|
+
const toB64 = (val) => {
|
|
130
|
+
if (val == null)
|
|
131
|
+
return null;
|
|
132
|
+
if (typeof val === 'string') {
|
|
133
|
+
const looksBase64 = /^[A-Za-z0-9+/=]+$/.test(val) && val.length >= 80 && val.length % 4 === 0;
|
|
134
|
+
if (looksBase64)
|
|
135
|
+
return val;
|
|
136
|
+
try {
|
|
137
|
+
const decoded = base58Decode(val);
|
|
138
|
+
if (decoded.length > 64)
|
|
139
|
+
return b64FromBytes(decoded);
|
|
140
|
+
}
|
|
141
|
+
catch { }
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (val.byteLength != null || ArrayBuffer.isView(val)) {
|
|
145
|
+
const b = val instanceof Uint8Array ? val : new Uint8Array(val);
|
|
146
|
+
if (b.length > 64)
|
|
147
|
+
return b64FromBytes(b);
|
|
148
|
+
}
|
|
149
|
+
if (typeof val === 'object' && typeof val.serialize === 'function') {
|
|
150
|
+
try {
|
|
151
|
+
const out = val.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
152
|
+
const b = out instanceof Uint8Array ? out : new Uint8Array(out);
|
|
153
|
+
if (b.length > 64)
|
|
154
|
+
return b64FromBytes(b);
|
|
155
|
+
}
|
|
156
|
+
catch { }
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
};
|
|
160
|
+
const direct = toB64(r);
|
|
161
|
+
if (direct)
|
|
162
|
+
return direct;
|
|
163
|
+
if (typeof r === 'object') {
|
|
164
|
+
for (const key of ['signedTransaction', 'transaction', 'signedMessage', 'serializedTransaction', 'encodedTransaction', 'message']) {
|
|
165
|
+
const v = r[key];
|
|
166
|
+
const b64 = toB64(v);
|
|
167
|
+
if (b64)
|
|
168
|
+
return b64;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
/** Normalize Solana signMessage result to base64 64-byte signature. Phantom returns { signature, rawSignature }; some wallets return { signature: Uint8Array } or string. */
|
|
174
|
+
function normalizeSolanaMessageSignature(r) {
|
|
175
|
+
if (!r)
|
|
176
|
+
return null;
|
|
177
|
+
// Direct string (base58 or base64)
|
|
178
|
+
if (typeof r === 'string') {
|
|
179
|
+
if (r.length === 88 && /^[1-9A-HJ-NP-Za-km-z]+$/.test(r)) {
|
|
180
|
+
try {
|
|
181
|
+
const b = base58Decode(r);
|
|
182
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const b = u8FromBase64(r);
|
|
190
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Byte-like (Uint8Array / ArrayBufferView)
|
|
197
|
+
if (r.byteLength != null || ArrayBuffer.isView(r)) {
|
|
198
|
+
const b = r instanceof Uint8Array ? r : new Uint8Array(r);
|
|
199
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
200
|
+
}
|
|
201
|
+
// Object: signature (string or Uint8Array) or rawSignature (base64 string)
|
|
202
|
+
if (typeof r === 'object') {
|
|
203
|
+
const sig = r.signature;
|
|
204
|
+
if (sig != null) {
|
|
205
|
+
if (typeof sig === 'string') {
|
|
206
|
+
try {
|
|
207
|
+
const b = base58Decode(sig);
|
|
208
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
209
|
+
}
|
|
210
|
+
catch { }
|
|
211
|
+
try {
|
|
212
|
+
const b = u8FromBase64(sig);
|
|
213
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
214
|
+
}
|
|
215
|
+
catch { }
|
|
216
|
+
}
|
|
217
|
+
if (sig.byteLength != null || ArrayBuffer.isView(sig)) {
|
|
218
|
+
const b = sig instanceof Uint8Array ? sig : new Uint8Array(sig);
|
|
219
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const raw = r.rawSignature;
|
|
223
|
+
if (typeof raw === 'string') {
|
|
224
|
+
try {
|
|
225
|
+
const b = u8FromBase64(raw);
|
|
226
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
227
|
+
}
|
|
228
|
+
catch { }
|
|
229
|
+
}
|
|
230
|
+
if (Array.isArray(r.data)) {
|
|
231
|
+
const b = Uint8Array.from(r.data);
|
|
232
|
+
return b.length === 64 ? b64FromBytes(b) : null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
121
237
|
// Normalize metadata so internal icpay-managed fields are nested under metadata.icpay.
|
|
122
238
|
// If icpay exists, merge; otherwise create. Move known internal keys and icpay_* keys under icpay.
|
|
123
239
|
function normalizeSdkMetadata(base) {
|
|
@@ -800,6 +916,7 @@ class Icpay {
|
|
|
800
916
|
const prebuiltBase64 = params.request?.__transactionBase64;
|
|
801
917
|
if (typeof prebuiltBase64 === 'string' && prebuiltBase64.length > 0) {
|
|
802
918
|
let signature = null;
|
|
919
|
+
let relay;
|
|
803
920
|
try {
|
|
804
921
|
if (sol?.request) {
|
|
805
922
|
// Treat as Phantom only if the selected provider itself reports isPhantom,
|
|
@@ -835,80 +952,67 @@ class Icpay {
|
|
|
835
952
|
}
|
|
836
953
|
catch { }
|
|
837
954
|
}
|
|
838
|
-
|
|
839
|
-
if (
|
|
840
|
-
const
|
|
841
|
-
if (
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
if (typeof
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
const
|
|
864
|
-
if (
|
|
865
|
-
|
|
955
|
+
signedTxB64 = normalizeSolanaSignedTransaction(r) ?? signedTxB64;
|
|
956
|
+
if (!signedTxB64 && !signerSigBase58) {
|
|
957
|
+
const candidate = (r?.signedTransaction || r?.transaction || r?.signedMessage || r);
|
|
958
|
+
if (typeof candidate === 'string') {
|
|
959
|
+
const looksBase64 = /^[A-Za-z0-9+/=]+$/.test(candidate) && candidate.length % 4 === 0;
|
|
960
|
+
if (looksBase64)
|
|
961
|
+
signedTxB64 = candidate;
|
|
962
|
+
else
|
|
963
|
+
signerSigBase58 = candidate;
|
|
964
|
+
}
|
|
965
|
+
else if (candidate && (candidate.byteLength != null || ArrayBuffer.isView(candidate))) {
|
|
966
|
+
const b = candidate instanceof Uint8Array ? candidate : new Uint8Array(candidate);
|
|
967
|
+
if (b.length > 64)
|
|
968
|
+
signedTxB64 = b64FromBytes(b);
|
|
969
|
+
else if (b.length === 64)
|
|
970
|
+
signerSigBase58 = base58Encode(b);
|
|
971
|
+
}
|
|
972
|
+
else if (r && typeof r === 'object') {
|
|
973
|
+
const obj = r;
|
|
974
|
+
if (typeof obj.signedTransaction === 'string')
|
|
975
|
+
signedTxB64 = obj.signedTransaction;
|
|
976
|
+
if (!signedTxB64 && typeof obj.signature === 'string')
|
|
977
|
+
signerSigBase58 = obj.signature;
|
|
978
|
+
if (!signedTxB64 && obj && typeof obj.serialize === 'function') {
|
|
979
|
+
try {
|
|
980
|
+
const out = obj.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
981
|
+
if (out && (out.byteLength != null || ArrayBuffer.isView(out))) {
|
|
982
|
+
const b = out instanceof Uint8Array ? out : new Uint8Array(out);
|
|
983
|
+
if (b.length > 64)
|
|
984
|
+
signedTxB64 = b64FromBytes(b);
|
|
985
|
+
}
|
|
866
986
|
}
|
|
987
|
+
catch { }
|
|
867
988
|
}
|
|
868
|
-
catch { }
|
|
869
989
|
}
|
|
870
990
|
}
|
|
871
|
-
// Direct provider API fallback (Phantom: signTransaction(Transaction))
|
|
872
991
|
if (!signedTxB64 && typeof sol.signTransaction === 'function') {
|
|
873
992
|
try {
|
|
874
993
|
const txBytes = u8FromBase64(prebuiltBase64);
|
|
875
994
|
const stx = await sol.signTransaction(txBytes);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
try {
|
|
886
|
-
const out = stx.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
887
|
-
const b = out instanceof Uint8Array ? out : new Uint8Array(out);
|
|
888
|
-
if (b.length > 64)
|
|
889
|
-
signedTxB64 = b64FromBytes(b);
|
|
890
|
-
}
|
|
891
|
-
catch { }
|
|
892
|
-
}
|
|
893
|
-
else if (stx && (stx.byteLength != null || ArrayBuffer.isView(stx))) {
|
|
894
|
-
const b = stx instanceof Uint8Array ? stx : new Uint8Array(stx);
|
|
895
|
-
if (b.length > 64)
|
|
896
|
-
signedTxB64 = b64FromBytes(b);
|
|
897
|
-
else if (b.length === 64)
|
|
898
|
-
signerSigBase58 = base58Encode(b);
|
|
899
|
-
}
|
|
995
|
+
const parsed = normalizeSolanaSignedTransaction(stx);
|
|
996
|
+
if (parsed)
|
|
997
|
+
signedTxB64 = parsed;
|
|
998
|
+
else if (stx && typeof stx === 'string' && stx.length === 88)
|
|
999
|
+
signerSigBase58 = stx;
|
|
1000
|
+
else if (stx && (stx.byteLength != null || ArrayBuffer.isView(stx))) {
|
|
1001
|
+
const b = stx instanceof Uint8Array ? stx : new Uint8Array(stx);
|
|
1002
|
+
if (b.length === 64)
|
|
1003
|
+
signerSigBase58 = base58Encode(b);
|
|
900
1004
|
}
|
|
901
1005
|
}
|
|
902
1006
|
catch { }
|
|
903
1007
|
}
|
|
904
1008
|
if (!signedTxB64 && !signerSigBase58)
|
|
905
1009
|
throw new Error('Wallet did not return a signed transaction');
|
|
906
|
-
// Relay via API
|
|
907
|
-
let relay;
|
|
1010
|
+
// Relay via API (facilitatorPaysFee: true for x402 so facilitator pays network fee)
|
|
908
1011
|
if (signedTxB64) {
|
|
909
1012
|
relay = await this.publicApiClient.post('/sdk/public/payments/solana/relay', {
|
|
910
1013
|
signedTransactionBase64: signedTxB64,
|
|
911
1014
|
paymentIntentId: params.paymentIntentId,
|
|
1015
|
+
facilitatorPaysFee: true,
|
|
912
1016
|
});
|
|
913
1017
|
}
|
|
914
1018
|
else {
|
|
@@ -976,6 +1080,25 @@ class Icpay {
|
|
|
976
1080
|
this.emitMethodSuccess('notifyLedgerTransaction', { paymentIntentId: params.paymentIntentId });
|
|
977
1081
|
}
|
|
978
1082
|
catch { }
|
|
1083
|
+
// If relay already returned completed payload (paymentIntent + payment), skip notify and polling
|
|
1084
|
+
const relayPayload = typeof relay?.paymentIntent !== 'undefined' || typeof relay?.payment !== 'undefined' ? relay : undefined;
|
|
1085
|
+
const relayStatus = relayPayload && (typeof relayPayload.status === 'string' ? relayPayload.status : relayPayload?.paymentIntent?.status || relayPayload?.payment?.status || '');
|
|
1086
|
+
const relayTerminal = typeof relayStatus === 'string' && ['completed', 'succeeded'].includes(String(relayStatus).toLowerCase());
|
|
1087
|
+
if (relayPayload && relayTerminal) {
|
|
1088
|
+
const norm = String(relayStatus).toLowerCase();
|
|
1089
|
+
const out = {
|
|
1090
|
+
transactionId: 0,
|
|
1091
|
+
status: norm === 'succeeded' ? 'completed' : norm,
|
|
1092
|
+
amount: params.amount.toString(),
|
|
1093
|
+
recipientCanister: params.ledgerCanisterId,
|
|
1094
|
+
timestamp: new Date(),
|
|
1095
|
+
description: 'Fund transfer',
|
|
1096
|
+
metadata: { ...(params.metadata || {}), icpay_solana_tx_sig: signature },
|
|
1097
|
+
payment: relayPayload,
|
|
1098
|
+
};
|
|
1099
|
+
this.emit('icpay-sdk-transaction-completed', out);
|
|
1100
|
+
return out;
|
|
1101
|
+
}
|
|
979
1102
|
try {
|
|
980
1103
|
await this.performNotifyPaymentIntent({ paymentIntentId: params.paymentIntentId, transactionId: signature, maxAttempts: 1 });
|
|
981
1104
|
}
|
|
@@ -2137,10 +2260,10 @@ class Icpay {
|
|
|
2137
2260
|
x402: true,
|
|
2138
2261
|
recipientAddress: request?.recipientAddress || '0x0000000000000000000000000000000000000000',
|
|
2139
2262
|
};
|
|
2140
|
-
// Include Solana payerPublicKey
|
|
2263
|
+
// Include Solana payerPublicKey so server can build unsigned tx (standard x402 flow)
|
|
2141
2264
|
try {
|
|
2142
2265
|
const w = globalThis?.window || globalThis;
|
|
2143
|
-
const sol = this.config?.solanaProvider || w?.solana || w?.phantom?.solana;
|
|
2266
|
+
const sol = this.config?.solanaProvider || this.config?.connectedWallet?.solana || this.config?.connectedWallet || w?.solana || w?.phantom?.solana;
|
|
2144
2267
|
const pk = sol?.publicKey?.toBase58?.() || sol?.publicKey || null;
|
|
2145
2268
|
if (pk && typeof pk === 'string') {
|
|
2146
2269
|
body.payerPublicKey = pk;
|
|
@@ -2355,10 +2478,12 @@ class Icpay {
|
|
|
2355
2478
|
});
|
|
2356
2479
|
}
|
|
2357
2480
|
if (isSol) {
|
|
2358
|
-
// Solana x402:
|
|
2481
|
+
// Solana x402: follow standard flow (https://solana.com/developers/guides/getstarted/intro-to-x402)
|
|
2482
|
+
// — client signs transaction with signTransaction, then relay. No signMessage.
|
|
2483
|
+
const solTxBase64 = requirement?.extra?.transactionBase64;
|
|
2484
|
+
const solMsgB58 = requirement?.extra?.messageBase58;
|
|
2359
2485
|
const signableMsgB64 = requirement?.extra?.signableMessageBase64;
|
|
2360
2486
|
const signableFields = requirement?.extra?.signableFields || {};
|
|
2361
|
-
const wSolCtx = globalThis?.window || globalThis;
|
|
2362
2487
|
const sol = providerForHeader;
|
|
2363
2488
|
if (!sol)
|
|
2364
2489
|
throw new errors_1.IcpayError({ code: errors_1.ICPAY_ERROR_CODES.WALLET_PROVIDER_NOT_AVAILABLE, message: 'Solana provider not available (window.solana)' });
|
|
@@ -2377,7 +2502,120 @@ class Icpay {
|
|
|
2377
2502
|
}
|
|
2378
2503
|
if (!fromBase58)
|
|
2379
2504
|
throw new errors_1.IcpayError({ code: errors_1.ICPAY_ERROR_CODES.WALLET_NOT_CONNECTED, message: 'Solana wallet not connected' });
|
|
2380
|
-
//
|
|
2505
|
+
// Standard x402: when server provided unsigned tx, sign it and relay (no signMessage)
|
|
2506
|
+
if (solTxBase64 && solTxBase64.length > 0) {
|
|
2507
|
+
if (typeof sol?.connect === 'function') {
|
|
2508
|
+
try {
|
|
2509
|
+
await sol.connect({ onlyIfTrusted: false });
|
|
2510
|
+
}
|
|
2511
|
+
catch { }
|
|
2512
|
+
}
|
|
2513
|
+
const __txB64 = String(solTxBase64);
|
|
2514
|
+
const inlineMsgB58 = solMsgB58 && solMsgB58.length > 0 ? String(solMsgB58) : base58Encode(u8FromBase64(__txB64));
|
|
2515
|
+
let signedTxB64 = null;
|
|
2516
|
+
let r = null;
|
|
2517
|
+
if (sol?.request) {
|
|
2518
|
+
try {
|
|
2519
|
+
try {
|
|
2520
|
+
r = await sol.request({ method: 'signTransaction', params: { message: inlineMsgB58 } });
|
|
2521
|
+
}
|
|
2522
|
+
catch { }
|
|
2523
|
+
if (!r)
|
|
2524
|
+
try {
|
|
2525
|
+
r = await sol.request({ method: 'signTransaction', params: inlineMsgB58 });
|
|
2526
|
+
}
|
|
2527
|
+
catch { }
|
|
2528
|
+
if (!r)
|
|
2529
|
+
try {
|
|
2530
|
+
r = await sol.request({ method: 'solana:signTransaction', params: { transaction: __txB64 } });
|
|
2531
|
+
}
|
|
2532
|
+
catch { }
|
|
2533
|
+
if (!r)
|
|
2534
|
+
try {
|
|
2535
|
+
r = await sol.request({ method: 'signTransaction', params: { transaction: __txB64 } });
|
|
2536
|
+
}
|
|
2537
|
+
catch { }
|
|
2538
|
+
}
|
|
2539
|
+
catch { }
|
|
2540
|
+
}
|
|
2541
|
+
signedTxB64 = normalizeSolanaSignedTransaction(r) ?? signedTxB64;
|
|
2542
|
+
if (!signedTxB64 && r) {
|
|
2543
|
+
const candidate = (r?.signedTransaction || r?.transaction || r?.signedMessage || r);
|
|
2544
|
+
if (typeof candidate === 'string') {
|
|
2545
|
+
const looksBase64 = /^[A-Za-z0-9+/=]+$/.test(candidate) && candidate.length % 4 === 0;
|
|
2546
|
+
if (looksBase64)
|
|
2547
|
+
signedTxB64 = candidate;
|
|
2548
|
+
}
|
|
2549
|
+
else if (candidate && (candidate.byteLength != null || ArrayBuffer.isView(candidate))) {
|
|
2550
|
+
const b = candidate instanceof Uint8Array ? candidate : new Uint8Array(candidate);
|
|
2551
|
+
if (b.length > 64)
|
|
2552
|
+
signedTxB64 = b64FromBytes(b);
|
|
2553
|
+
}
|
|
2554
|
+
else if (typeof r === 'object') {
|
|
2555
|
+
const obj = r;
|
|
2556
|
+
if (typeof obj.signedTransaction === 'string')
|
|
2557
|
+
signedTxB64 = obj.signedTransaction;
|
|
2558
|
+
else if (typeof obj.transaction === 'string')
|
|
2559
|
+
signedTxB64 = obj.transaction;
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
if (!signedTxB64 && typeof sol.signTransaction === 'function') {
|
|
2563
|
+
try {
|
|
2564
|
+
const txBytes = u8FromBase64(__txB64);
|
|
2565
|
+
const stx = await sol.signTransaction(txBytes);
|
|
2566
|
+
signedTxB64 = normalizeSolanaSignedTransaction(stx) ?? signedTxB64;
|
|
2567
|
+
}
|
|
2568
|
+
catch { }
|
|
2569
|
+
}
|
|
2570
|
+
if (signedTxB64) {
|
|
2571
|
+
const relay = await this.publicApiClient.post('/sdk/public/payments/solana/relay', {
|
|
2572
|
+
signedTransactionBase64: signedTxB64,
|
|
2573
|
+
paymentIntentId,
|
|
2574
|
+
facilitatorPaysFee: true,
|
|
2575
|
+
});
|
|
2576
|
+
const sig = (relay && relay.signature) || null;
|
|
2577
|
+
try {
|
|
2578
|
+
this.emitMethodSuccess('notifyLedgerTransaction', { paymentIntentId });
|
|
2579
|
+
}
|
|
2580
|
+
catch { }
|
|
2581
|
+
if (sig) {
|
|
2582
|
+
try {
|
|
2583
|
+
await this.performNotifyPaymentIntent({ paymentIntentId, transactionId: sig, maxAttempts: 1 });
|
|
2584
|
+
}
|
|
2585
|
+
catch { }
|
|
2586
|
+
}
|
|
2587
|
+
const relayStatus = relay?.status || relay?.paymentIntent?.status || relay?.payment?.status || '';
|
|
2588
|
+
const terminal = typeof relayStatus === 'string' && ['completed', 'succeeded'].includes(String(relayStatus).toLowerCase());
|
|
2589
|
+
if (terminal) {
|
|
2590
|
+
const out = {
|
|
2591
|
+
transactionId: 0,
|
|
2592
|
+
status: String(relayStatus).toLowerCase() === 'succeeded' ? 'completed' : relayStatus,
|
|
2593
|
+
amount: requirement?.maxAmountRequired?.toString?.() || '',
|
|
2594
|
+
recipientCanister: ledgerCanisterId,
|
|
2595
|
+
timestamp: new Date(),
|
|
2596
|
+
metadata: { ...(request.metadata || {}), icpay_x402: true, icpay_solana_tx_sig: sig },
|
|
2597
|
+
payment: relay,
|
|
2598
|
+
};
|
|
2599
|
+
this.emit('icpay-sdk-transaction-completed', out);
|
|
2600
|
+
this.emitMethodSuccess('createPaymentX402Usd', out);
|
|
2601
|
+
return out;
|
|
2602
|
+
}
|
|
2603
|
+
const waited = await this.awaitIntentTerminal({
|
|
2604
|
+
paymentIntentId,
|
|
2605
|
+
transactionId: sig,
|
|
2606
|
+
ledgerCanisterId: ledgerCanisterId,
|
|
2607
|
+
amount: requirement?.maxAmountRequired?.toString?.() || '',
|
|
2608
|
+
metadata: { ...(request.metadata || {}), icpay_x402: true, icpay_solana_tx_sig: sig },
|
|
2609
|
+
});
|
|
2610
|
+
this.emitMethodSuccess('createPaymentX402Usd', waited);
|
|
2611
|
+
return waited;
|
|
2612
|
+
}
|
|
2613
|
+
throw new errors_1.IcpayError({
|
|
2614
|
+
code: errors_1.ICPAY_ERROR_CODES.TRANSACTION_FAILED,
|
|
2615
|
+
message: 'Transaction was not signed. Please approve the transaction in your wallet.',
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
// Fallback: message-sign flow only when no transactionBase64 (e.g. 402 built without payerPublicKey)
|
|
2381
2619
|
if (signableMsgB64) {
|
|
2382
2620
|
// Sign the provided message and settle via header (services will submit)
|
|
2383
2621
|
// Ensure explicit connect prompt before signing
|
|
@@ -2391,7 +2629,7 @@ class Icpay {
|
|
|
2391
2629
|
const msgBytes = u8FromBase64(signableMsgB64);
|
|
2392
2630
|
const msgB58ForReq = base58Encode(msgBytes);
|
|
2393
2631
|
// Attempts in order (strict):
|
|
2394
|
-
// 1) Wallet Standard: request colon form with Uint8Array
|
|
2632
|
+
// 1) Wallet Standard: request colon form with Uint8Array (Phantom returns { signature, rawSignature } or { signature: Uint8Array })
|
|
2395
2633
|
if (!sigB64 && sol?.request) {
|
|
2396
2634
|
try {
|
|
2397
2635
|
try {
|
|
@@ -2399,34 +2637,7 @@ class Icpay {
|
|
|
2399
2637
|
}
|
|
2400
2638
|
catch { }
|
|
2401
2639
|
const r0 = await sol.request({ method: 'solana:signMessage', params: { message: msgBytes } });
|
|
2402
|
-
|
|
2403
|
-
try {
|
|
2404
|
-
const b = base58Decode(r0);
|
|
2405
|
-
sigB64 = b64FromBytes(b);
|
|
2406
|
-
}
|
|
2407
|
-
catch {
|
|
2408
|
-
sigB64 = r0;
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
else if (r0 && typeof r0.signature === 'string') {
|
|
2412
|
-
try {
|
|
2413
|
-
const b = base58Decode(r0.signature);
|
|
2414
|
-
sigB64 = b64FromBytes(b);
|
|
2415
|
-
}
|
|
2416
|
-
catch {
|
|
2417
|
-
sigB64 = r0.signature;
|
|
2418
|
-
}
|
|
2419
|
-
}
|
|
2420
|
-
else if (r0 && (r0.byteLength != null || ArrayBuffer.isView(r0))) {
|
|
2421
|
-
const b = r0 instanceof Uint8Array ? r0 : new Uint8Array(r0);
|
|
2422
|
-
if (b && b.length === 64)
|
|
2423
|
-
sigB64 = b64FromBytes(b);
|
|
2424
|
-
}
|
|
2425
|
-
else if (r0 && typeof r0 === 'object' && Array.isArray(r0.data)) {
|
|
2426
|
-
const b = Uint8Array.from(r0.data);
|
|
2427
|
-
if (b && b.length === 64)
|
|
2428
|
-
sigB64 = b64FromBytes(b);
|
|
2429
|
-
}
|
|
2640
|
+
sigB64 = normalizeSolanaMessageSignature(r0) ?? sigB64;
|
|
2430
2641
|
}
|
|
2431
2642
|
catch (e0) {
|
|
2432
2643
|
try {
|
|
@@ -2443,30 +2654,7 @@ class Icpay {
|
|
|
2443
2654
|
}
|
|
2444
2655
|
catch { }
|
|
2445
2656
|
const r2 = await sol.signMessage(msgBytes);
|
|
2446
|
-
|
|
2447
|
-
const b = r2 instanceof Uint8Array ? r2 : new Uint8Array(r2);
|
|
2448
|
-
if (b && b.length === 64)
|
|
2449
|
-
sigB64 = b64FromBytes(b);
|
|
2450
|
-
}
|
|
2451
|
-
else if (typeof r2 === 'string') {
|
|
2452
|
-
try {
|
|
2453
|
-
const b = base58Decode(r2);
|
|
2454
|
-
sigB64 = b64FromBytes(b);
|
|
2455
|
-
}
|
|
2456
|
-
catch {
|
|
2457
|
-
sigB64 = r2;
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
else if (r2 && typeof r2 === 'object' && typeof r2.signature === 'string') {
|
|
2461
|
-
const s = r2.signature;
|
|
2462
|
-
try {
|
|
2463
|
-
const b = base58Decode(s);
|
|
2464
|
-
sigB64 = b64FromBytes(b);
|
|
2465
|
-
}
|
|
2466
|
-
catch {
|
|
2467
|
-
sigB64 = s;
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2657
|
+
sigB64 = normalizeSolanaMessageSignature(r2) ?? sigB64;
|
|
2470
2658
|
}
|
|
2471
2659
|
catch (e2) {
|
|
2472
2660
|
try {
|
|
@@ -2483,34 +2671,7 @@ class Icpay {
|
|
|
2483
2671
|
}
|
|
2484
2672
|
catch { }
|
|
2485
2673
|
const r3 = await sol.request({ method: 'signMessage', params: { message: msgBytes } });
|
|
2486
|
-
|
|
2487
|
-
try {
|
|
2488
|
-
const b = base58Decode(r3);
|
|
2489
|
-
sigB64 = b64FromBytes(b);
|
|
2490
|
-
}
|
|
2491
|
-
catch {
|
|
2492
|
-
sigB64 = r3;
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
else if (r3 && typeof r3.signature === 'string') {
|
|
2496
|
-
try {
|
|
2497
|
-
const b = base58Decode(r3.signature);
|
|
2498
|
-
sigB64 = b64FromBytes(b);
|
|
2499
|
-
}
|
|
2500
|
-
catch {
|
|
2501
|
-
sigB64 = r3.signature;
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
else if (r3 && (r3.byteLength != null || ArrayBuffer.isView(r3))) {
|
|
2505
|
-
const b = r3 instanceof Uint8Array ? r3 : new Uint8Array(r3);
|
|
2506
|
-
if (b && b.length === 64)
|
|
2507
|
-
sigB64 = b64FromBytes(b);
|
|
2508
|
-
}
|
|
2509
|
-
else if (r3 && typeof r3 === 'object' && Array.isArray(r3.data)) {
|
|
2510
|
-
const b = Uint8Array.from(r3.data);
|
|
2511
|
-
if (b && b.length === 64)
|
|
2512
|
-
sigB64 = b64FromBytes(b);
|
|
2513
|
-
}
|
|
2674
|
+
sigB64 = normalizeSolanaMessageSignature(r3) ?? sigB64;
|
|
2514
2675
|
}
|
|
2515
2676
|
catch (e3) {
|
|
2516
2677
|
try {
|
|
@@ -2527,34 +2688,7 @@ class Icpay {
|
|
|
2527
2688
|
}
|
|
2528
2689
|
catch { }
|
|
2529
2690
|
const r4 = await sol.request({ method: 'signMessage', params: { message: msgB58ForReq } });
|
|
2530
|
-
|
|
2531
|
-
try {
|
|
2532
|
-
const b = base58Decode(r4);
|
|
2533
|
-
sigB64 = b64FromBytes(b);
|
|
2534
|
-
}
|
|
2535
|
-
catch {
|
|
2536
|
-
sigB64 = r4;
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
else if (r4 && typeof r4.signature === 'string') {
|
|
2540
|
-
try {
|
|
2541
|
-
const b = base58Decode(r4.signature);
|
|
2542
|
-
sigB64 = b64FromBytes(b);
|
|
2543
|
-
}
|
|
2544
|
-
catch {
|
|
2545
|
-
sigB64 = r4.signature;
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
else if (r4 && (r4.byteLength != null || ArrayBuffer.isView(r4))) {
|
|
2549
|
-
const b = r4 instanceof Uint8Array ? r4 : new Uint8Array(r4);
|
|
2550
|
-
if (b && b.length === 64)
|
|
2551
|
-
sigB64 = b64FromBytes(b);
|
|
2552
|
-
}
|
|
2553
|
-
else if (r4 && typeof r4 === 'object' && Array.isArray(r4.data)) {
|
|
2554
|
-
const b = Uint8Array.from(r4.data);
|
|
2555
|
-
if (b && b.length === 64)
|
|
2556
|
-
sigB64 = b64FromBytes(b);
|
|
2557
|
-
}
|
|
2691
|
+
sigB64 = normalizeSolanaMessageSignature(r4) ?? sigB64;
|
|
2558
2692
|
}
|
|
2559
2693
|
catch (e4) {
|
|
2560
2694
|
try {
|
|
@@ -2646,10 +2780,13 @@ class Icpay {
|
|
|
2646
2780
|
return waitedSolHdr;
|
|
2647
2781
|
}
|
|
2648
2782
|
else {
|
|
2649
|
-
// Fallback: if API provided an unsigned transaction, try transaction-signing path
|
|
2783
|
+
// Fallback: if API provided an unsigned transaction, try transaction-signing path (signTransaction like normal Solana flow)
|
|
2650
2784
|
const fallbackTx = requirement?.extra?.transactionBase64;
|
|
2651
2785
|
if (!fallbackTx) {
|
|
2652
|
-
throw new errors_1.IcpayError({
|
|
2786
|
+
throw new errors_1.IcpayError({
|
|
2787
|
+
code: errors_1.ICPAY_ERROR_CODES.TRANSACTION_FAILED,
|
|
2788
|
+
message: 'Wallet did not sign message. Connect your Solana wallet before starting the payment and try again.',
|
|
2789
|
+
});
|
|
2653
2790
|
}
|
|
2654
2791
|
// Inject for transaction-signing fallback below
|
|
2655
2792
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|