-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added signMessage method to provider * throw error on missing options * Include send btc transaction function * Remove console.log * convert to amountSats * make message optional * Allow to pass a custom Bitcoin provider (#14) * Allow to pass a custom Bitcoin provider * Extract GetBitcoinProviderFunc type * Add senderAddress and allow multiple recipients (#10) * Add senderAddress and allow multiple recipients * Use Recipient in payload * Use bigint type for amountSats * Improve readability and error messages (#15) * Improve readability * Clean up error messages * Remove duplicate line * Improve error message --------- Co-authored-by: Victor Kirov <victor.kirov@gmail.com> * Add NPM pull request preview publish github workflow (#22) * Add NPM pull request preview publish github workflow * Add NPM pull request preview publish github workflow * fix build script * add npmrc file * add npm token * add npmrc file * change package repository to npm * update release workflow * release v0.5.0 (#23) * 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> * Fix bigInt serialisation Issue (#25) * serialize recipient array * Fix AddressPurposes type * Revert AddressPurpose name change * Rename const * Check recipient type * chore: npm publish with prerelease tag if prerelease option selected (#27) * chore: update release-package.yml syntax (#28) * Release v1.0.0 (#24) release v1.0.0 Co-authored-by: Tim Man <tim@secretkeylabs.com> --------- Co-authored-by: Ken Liao <yukanliao@gmail.com> Co-authored-by: Imamah-Zafar <imamah.zafar@tintash.com> Co-authored-by: Duska.T <55587184+DuskaT021@users.noreply.github.com> Co-authored-by: Matías Olivera <moliverafreire@gmail.com> Co-authored-by: Imamah-Zafar <88320460+Imamah-Zafar@users.noreply.github.com> Co-authored-by: Victor Kirov <victor.kirov@gmail.com> Co-authored-by: Tim Man <tim@secretkeylabs.com>
- Loading branch information
1 parent
a8b7f41
commit 2f98952
Showing
23 changed files
with
424 additions
and
153 deletions.
There are no files selected for viewing
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,104 @@ | ||
name: Release & Publish Package | ||
|
||
on: | ||
pull_request: | ||
branches: [develop] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
fork-check: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
is-not-fork: ${{ steps.check.outputs.is_not_fork }} | ||
steps: | ||
- id: check | ||
run: echo "::set-output name=is_not_fork::${{ github.repository == 'secretkeylabs/sats-connect' }}" | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: npm | ||
- run: npm ci | ||
# TODO: enable linting once ready | ||
# - run: npm run lint | ||
# - run: npm test | ||
|
||
publish-beta: | ||
needs: | ||
- test | ||
- fork-check | ||
if: needs.fork-check.outputs.is-not-fork == 'true' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: npm | ||
registry-url: https://registry.npmjs.org | ||
|
||
- id: git-commit | ||
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
- run: npm ci | ||
- run: npm run build | ||
|
||
- id: current-version | ||
run: echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT | ||
- id: tag-version | ||
run: npm version --no-git-tag-version $CURRENT_VERSION-$SHA | ||
env: | ||
SHA: ${{ steps.git-commit.outputs.sha }} | ||
CURRENT_VERSION: ${{ steps.current-version.outputs.version }} | ||
|
||
- id: publish | ||
run: npm publish --tag pr | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
|
||
- id: published-version | ||
run: echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT | ||
- run: echo published version $VERSION | ||
env: | ||
VERSION: ${{ steps.published-version.outputs.version }} | ||
|
||
- name: Delete old bot comments | ||
if: ${{ github.event_name == 'pull_request' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_ID: ${{ github.event.pull_request.number }} | ||
REPO: ${{ github.repository }} | ||
run: | | ||
curl \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/$REPO/issues/$PR_ID/comments \ | ||
| jq ".[] | select(.user.login==\"github-actions[bot]\") | .id" \ | ||
| xargs -I %q curl \ | ||
-L \ | ||
-X DELETE \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token $GITHUB_TOKEN"\ | ||
https://api.github.com/repos/$REPO/issues/comments/%q | ||
- name: Post test package PR comment | ||
if: ${{ github.event_name == 'pull_request' }} | ||
env: | ||
VERSION: ${{ steps.published-version.outputs.version }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_URL: ${{ github.event.pull_request.comments_url }} | ||
run: | | ||
curl \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
$GITHUB_URL \ | ||
-d "{\"body\":\"> Test this PR with \`npm i @secretkeylabs/sats-connect@$VERSION\`\"}" |
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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
import type { Json } from 'jsontokens'; | ||
import { createUnsecuredToken } from 'jsontokens'; | ||
|
||
import { getDefaultProvider } from '../provider'; | ||
import type { GetAddressOptions } from './types'; | ||
|
||
export const getAddress = async (options: GetAddressOptions) => { | ||
const { getProvider = getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
|
||
const { purposes } = options.payload; | ||
if (!purposes) { | ||
throw new Error('Address purposes are required'); | ||
} | ||
|
||
try { | ||
const request = createUnsecuredToken(options.payload as unknown as Json); | ||
const response = await provider.connect(request); | ||
options.onFinish?.(response); | ||
} catch (error) { | ||
console.error('[Connect] Error during address request', error); | ||
options.onCancel?.(); | ||
} | ||
}; | ||
|
||
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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,29 @@ | ||
import { createUnsecuredToken, Json } from 'jsontokens'; | ||
import { BitcoinNetwork } from '../provider'; | ||
import type { Json } from 'jsontokens'; | ||
import { createUnsecuredToken } from 'jsontokens'; | ||
|
||
export interface CallWalletPayload { | ||
method: string; | ||
network: BitcoinNetwork; | ||
params?: Array<any>; | ||
} | ||
|
||
export interface CallWalletOptions { | ||
onFinish: (response: Record<string, any>) => void; | ||
onCancel: () => void; | ||
payload: CallWalletPayload; | ||
} | ||
|
||
export enum CallMethod { | ||
SIGN_TRANSACTION = 'signTransaction', | ||
GET_ADDRESS = 'getAddress', | ||
} | ||
import { getDefaultProvider } from '../provider'; | ||
import type { CallWalletOptions } from './types'; | ||
|
||
export const callWalletPopup = async (options: CallWalletOptions) => { | ||
const provider = window.BitcoinProvider; | ||
const { method } = options.payload; | ||
const { getProvider = getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin Wallet installed'); | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
if(!method) { | ||
|
||
const { method } = options.payload; | ||
if (!method) { | ||
throw new Error('A wallet method is required'); | ||
} | ||
|
||
const request = createUnsecuredToken(options.payload as unknown as Json); | ||
try { | ||
const callResponse = await provider.call(request); | ||
options.onFinish?.(callResponse); | ||
const response = await provider.call(request); | ||
options.onFinish?.(response); | ||
} catch (error) { | ||
console.error('[Connect] Error during call request', error); | ||
options.onCancel?.(); | ||
} | ||
}; | ||
|
||
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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Json } from 'jsontokens'; | ||
import { createUnsecuredToken } from 'jsontokens'; | ||
|
||
import { getDefaultProvider } from '../provider'; | ||
import type { SignMessageOptions } from './types'; | ||
|
||
export const signMessage = async (options: SignMessageOptions) => { | ||
const { getProvider = getDefaultProvider } = options; | ||
const provider = await getProvider(); | ||
if (!provider) { | ||
throw new Error('No Bitcoin wallet installed'); | ||
} | ||
|
||
const { address, message } = options.payload; | ||
if (!address) { | ||
throw new Error('An address is required to sign a message'); | ||
} | ||
if (!message) { | ||
throw new Error('A message to be signed is required'); | ||
} | ||
|
||
try { | ||
const request = createUnsecuredToken(options.payload as unknown as Json); | ||
const response = await provider.signMessage(request); | ||
options.onFinish?.(response); | ||
} catch (error) { | ||
console.error('[Connect] Error during sign message request', error); | ||
options.onCancel?.(); | ||
} | ||
}; | ||
|
||
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,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>; |
Oops, something went wrong.