-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve APIs and types (BREAKING) (#16)
* Remove unused type * Rename AddressPurposes enum for best practices * Extract call types into separate file * Remove unused CallMethod enum * Extract provider types into separate file * Rename directories for consistency * Rename sendBtcTransaction -> sendTransaction * Extract transactions types to separate file * Extract networks module * Improve types * Use [] instead of Array<> for consistency * Fix copy-paste oversight * Move index.ts inside src * Use import type for types * Revert sendBtcTransaction -> sendTransaction renaming * Simplify types --------- Co-authored-by: Victor Kirov <victor.kirov@gmail.com>
- Loading branch information
1 parent
426c35b
commit 9f0d3f4
Showing
19 changed files
with
167 additions
and
159 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { RequestOptions, RequestPayload } from '../types'; | ||
|
||
export enum AddressPurpose { | ||
Ordinals = 'ordinals', | ||
Payment = 'payment', | ||
} | ||
|
||
export interface GetAddressPayload extends RequestPayload { | ||
purposes: AddressPurpose[]; | ||
message: string; | ||
} | ||
|
||
export interface Address { | ||
address: string; | ||
publicKey: string; | ||
purpose: AddressPurpose; | ||
} | ||
|
||
export interface GetAddressResponse { | ||
addresses: Address[]; | ||
} | ||
|
||
export type GetAddressOptions = RequestOptions<GetAddressPayload, GetAddressResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { RequestOptions, RequestPayload } from '../types'; | ||
|
||
export interface CallWalletPayload extends RequestPayload { | ||
method: string; | ||
params?: any[]; | ||
} | ||
|
||
export type CallWalletResponse = Record<string, any>; | ||
|
||
export type CallWalletOptions = RequestOptions<CallWalletPayload, CallWalletResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './addresses'; | ||
export * from './call'; | ||
export * from './messages'; | ||
export * from './provider'; | ||
export * from './transactions'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { RequestOptions, RequestPayload } from '../types'; | ||
|
||
export interface SignMessagePayload extends RequestPayload { | ||
address: string; | ||
message: string; | ||
} | ||
|
||
export type SignMessageResponse = string; | ||
|
||
export type SignMessageOptions = RequestOptions<SignMessagePayload, SignMessageResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,7 @@ | ||
import { GetAddressResponse } from '../address'; | ||
import { SignTransactionResponse } from '../transactions/signTransaction'; | ||
|
||
export interface BitcoinNetwork { | ||
type: 'Mainnet' | 'Testnet'; | ||
address?: string; | ||
} | ||
|
||
export interface BitcoinProvider { | ||
connect: (request: string) => Promise<GetAddressResponse>; | ||
call: (request: string) => Promise<Record<string, any>>; | ||
signTransaction: (request: string) => Promise<SignTransactionResponse>; | ||
signMessage: (request: string) => Promise<string>; | ||
sendBtcTransaction: (request: string) => Promise<string>; | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
BitcoinProvider?: BitcoinProvider; | ||
} | ||
} | ||
|
||
export type GetBitcoinProviderFunc = () => Promise<BitcoinProvider | undefined>; | ||
import type { BitcoinProvider } from './types'; | ||
|
||
export async function getDefaultProvider(): Promise<BitcoinProvider | undefined> { | ||
return window.BitcoinProvider; | ||
} | ||
|
||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { GetAddressResponse } from '../addresses'; | ||
import type { CallWalletResponse } from '../call'; | ||
import type { SignMessageResponse } from '../messages'; | ||
import type { SendBtcTransactionResponse, SignTransactionResponse } from '../transactions'; | ||
|
||
export interface BitcoinProvider { | ||
call: (request: string) => Promise<CallWalletResponse>; | ||
connect: (request: string) => Promise<GetAddressResponse>; | ||
signMessage: (request: string) => Promise<SignMessageResponse>; | ||
signTransaction: (request: string) => Promise<SignTransactionResponse>; | ||
sendBtcTransaction: (request: string) => Promise<SendBtcTransactionResponse>; | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
BitcoinProvider?: BitcoinProvider; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './sendBtcTransaction'; | ||
export * from './signTransaction'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { RequestOptions, RequestPayload } from '../types'; | ||
|
||
export interface Recipient { | ||
address: string; | ||
amountSats: bigint; | ||
} | ||
|
||
export interface SendBtcTransactionPayload extends RequestPayload { | ||
recipients: Recipient[]; | ||
senderAddress: string; | ||
message?: string; | ||
} | ||
|
||
export type SendBtcTransactionResponse = string; | ||
|
||
export type SendBtcTransactionOptions = RequestOptions< | ||
SendBtcTransactionPayload, | ||
SendBtcTransactionResponse | ||
>; | ||
|
||
export interface InputToSign { | ||
address: string; | ||
signingIndexes: number[]; | ||
sigHash?: number; | ||
} | ||
|
||
export interface SignTransactionPayload extends RequestPayload { | ||
message: string; | ||
psbtBase64: string; | ||
inputsToSign: InputToSign[]; | ||
broadcast?: boolean; | ||
} | ||
|
||
export interface SignTransactionResponse { | ||
psbtBase64: string; | ||
txId?: string; | ||
} | ||
|
||
export type SignTransactionOptions = RequestOptions< | ||
SignTransactionPayload, | ||
SignTransactionResponse | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { BitcoinProvider } from './provider'; | ||
|
||
export enum BitcoinNetworkType { | ||
Mainnet = 'Mainnet', | ||
Testnet = 'Testnet', | ||
} | ||
|
||
export interface BitcoinNetwork { | ||
type: BitcoinNetworkType; | ||
address?: string; | ||
} | ||
|
||
export interface RequestPayload { | ||
network: BitcoinNetwork; | ||
} | ||
|
||
export interface RequestOptions<Payload extends RequestPayload, Response> { | ||
onFinish: (response: Response) => void; | ||
onCancel: () => void; | ||
payload: Payload; | ||
getProvider?: () => Promise<BitcoinProvider | undefined>; | ||
} |
Oops, something went wrong.