sats-connect
Advanced tools
Comparing version 1.0.0-851f3a4 to 1.0.0-a532718
@@ -21,7 +21,3 @@ "use strict"; | ||
const getAddress = async (options) => { | ||
const { getProvider = provider_1.getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
const provider = await (0, provider_1.getProviderOrThrow)(options.getProvider); | ||
const { purposes } = options.payload; | ||
@@ -28,0 +24,0 @@ if (!purposes) { |
@@ -21,7 +21,3 @@ "use strict"; | ||
const callWalletPopup = async (options) => { | ||
const { getProvider = provider_1.getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
const provider = await (0, provider_1.getProviderOrThrow)(options.getProvider); | ||
const { method } = options.payload; | ||
@@ -28,0 +24,0 @@ if (!method) { |
export * from './addresses'; | ||
export * from './call'; | ||
export * from './inscriptions'; | ||
export * from './messages'; | ||
@@ -4,0 +5,0 @@ export * from './provider'; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__exportStar(require("./call"), exports); | ||
__exportStar(require("./inscriptions"), exports); | ||
__exportStar(require("./messages"), exports); | ||
@@ -21,0 +22,0 @@ __exportStar(require("./provider"), exports); |
@@ -21,7 +21,3 @@ "use strict"; | ||
const signMessage = async (options) => { | ||
const { getProvider = provider_1.getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
const provider = await (0, provider_1.getProviderOrThrow)(options.getProvider); | ||
const { address, message } = options.payload; | ||
@@ -28,0 +24,0 @@ if (!address) { |
import type { BitcoinProvider } from './types'; | ||
export declare function getDefaultProvider(): Promise<BitcoinProvider | undefined>; | ||
export declare function getProviderOrThrow(getProvider?: () => Promise<BitcoinProvider | undefined>): Promise<BitcoinProvider>; | ||
export * from './types'; |
@@ -17,8 +17,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDefaultProvider = void 0; | ||
async function getDefaultProvider() { | ||
return window.BitcoinProvider; | ||
exports.getProviderOrThrow = void 0; | ||
async function getProviderOrThrow(getProvider) { | ||
const provider = (await getProvider?.()) || window.BitcoinProvider; | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
return provider; | ||
} | ||
exports.getDefaultProvider = getDefaultProvider; | ||
exports.getProviderOrThrow = getProviderOrThrow; | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
import type { GetAddressResponse } from '../addresses'; | ||
import type { CallWalletResponse } from '../call'; | ||
import type { GetCapabilitiesResponse } from '../capabilities'; | ||
import type { CreateInscriptionResponse } from '../inscriptions'; | ||
import type { SignMessageResponse } from '../messages'; | ||
import type { SendBtcTransactionResponse, SignTransactionResponse } from '../transactions'; | ||
export interface BitcoinProvider { | ||
interface BaseBitcoinProvider { | ||
call: (request: string) => Promise<CallWalletResponse>; | ||
@@ -11,3 +13,8 @@ connect: (request: string) => Promise<GetAddressResponse>; | ||
sendBtcTransaction: (request: string) => Promise<SendBtcTransactionResponse>; | ||
createInscription: (request: string) => Promise<CreateInscriptionResponse>; | ||
} | ||
export type Capability = keyof BaseBitcoinProvider; | ||
export interface BitcoinProvider extends BaseBitcoinProvider { | ||
getCapabilities?: (request: string) => Promise<GetCapabilitiesResponse>; | ||
} | ||
declare global { | ||
@@ -18,1 +25,2 @@ interface Window { | ||
} | ||
export {}; |
@@ -6,12 +6,20 @@ "use strict"; | ||
const provider_1 = require("../provider"); | ||
const serializer = (recipient) => { | ||
return recipient.map((value) => { | ||
const { address, amountSats } = value; | ||
return { | ||
address, | ||
amountSats: amountSats.toString(), | ||
}; | ||
}); | ||
}; | ||
const sendBtcTransaction = async (options) => { | ||
const { getProvider = provider_1.getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
const { recipients, senderAddress } = options.payload; | ||
const provider = await (0, provider_1.getProviderOrThrow)(options.getProvider); | ||
const { recipients, senderAddress, network, message } = options.payload; | ||
if (!recipients || recipients.length === 0) { | ||
throw new Error('At least one recipient is required'); | ||
} | ||
if (recipients.some((item) => typeof item.address !== 'string' || typeof item.amountSats !== 'bigint')) { | ||
throw new Error('Incorrect recipient format'); | ||
} | ||
if (!senderAddress) { | ||
@@ -21,3 +29,10 @@ throw new Error('The sender address is required'); | ||
try { | ||
const request = (0, jsontokens_1.createUnsecuredToken)(options.payload); | ||
const serializedRecipients = serializer(recipients); | ||
const serializedPayload = { | ||
network, | ||
senderAddress, | ||
message, | ||
recipients: serializedRecipients, | ||
}; | ||
const request = (0, jsontokens_1.createUnsecuredToken)(serializedPayload); | ||
const response = await provider.sendBtcTransaction(request); | ||
@@ -24,0 +39,0 @@ options.onFinish?.(response); |
@@ -7,7 +7,3 @@ "use strict"; | ||
const signTransaction = async (options) => { | ||
const { getProvider = provider_1.getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
const provider = await (0, provider_1.getProviderOrThrow)(options.getProvider); | ||
const { psbtBase64, inputsToSign } = options.payload; | ||
@@ -14,0 +10,0 @@ if (!psbtBase64) { |
@@ -6,2 +6,5 @@ import type { RequestOptions, RequestPayload } from '../types'; | ||
} | ||
export type SerializedRecipient = Omit<Recipient, 'amountSats'> & { | ||
amountSats: string; | ||
}; | ||
export interface SendBtcTransactionPayload extends RequestPayload { | ||
@@ -12,2 +15,5 @@ recipients: Recipient[]; | ||
} | ||
export type SerializedSendBtcTransactionPayload = Omit<SendBtcTransactionPayload, 'recipients'> & { | ||
recipients: SerializedRecipient[]; | ||
}; | ||
export type SendBtcTransactionResponse = string; | ||
@@ -14,0 +20,0 @@ export type SendBtcTransactionOptions = RequestOptions<SendBtcTransactionPayload, SendBtcTransactionResponse>; |
{ | ||
"name": "sats-connect", | ||
"version": "1.0.0-851f3a4", | ||
"version": "1.0.0-a532718", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
61400
60
569
0