Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bitcoin extension for web and react native #233

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/@magic-ext/bitcoin/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/coverage
/dist
/.eslintrc.js
/jest.config.ts
7 changes: 7 additions & 0 deletions packages/@magic-ext/bitcoin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../../.eslintrc.js'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
}
2 changes: 2 additions & 0 deletions packages/@magic-ext/bitcoin/.lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'*.{ts,tsx}':
- eslint --fix
1 change: 1 addition & 0 deletions packages/@magic-ext/bitcoin/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../../.prettierrc.js');
Empty file.
21 changes: 21 additions & 0 deletions packages/@magic-ext/bitcoin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018-present Magic Labs, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions packages/@magic-ext/bitcoin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@magic-ext/bitcoin",
"version": "0.1.0",
"description": "magic bitcoin extension",
"author": "Magic <[email protected]> (https://magic.link/)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/magiclabs/magic-js"
},
"files": [
"dist"
],
"target": "web",
"cdnGlobalName": "MagicBitcoinExtension",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"types": "./dist/types/index.d.ts",
"jsdelivr": "./dist/extension.js",
"react-native": "./dist/react-native/index.native.js",
"exports": {
"import": "./dist/modern/index.mjs",
"require": "./dist/cjs/index.js"
},
"externals": {
"include": [
"@magic-sdk/commons"
]
},
"devDependencies": {
"@magic-sdk/commons": "^2.2.0"
}
}
3 changes: 3 additions & 0 deletions packages/@magic-ext/bitcoin/src/index.cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BitcoinExtension } from './index';

export { BitcoinExtension as default };
1 change: 1 addition & 0 deletions packages/@magic-ext/bitcoin/src/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index';
25 changes: 25 additions & 0 deletions packages/@magic-ext/bitcoin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Extension } from '@magic-sdk/commons';
import { BitcoinConfig, BitcoinPayloadMethod } from './types';

export class BitcoinExtension extends Extension.Internal<'bitcoin', any> {
name = 'bitcoin' as const;
config: any = {};

constructor(public bitcoinConfig: BitcoinConfig) {
super();

this.config = {
rpcUrl: bitcoinConfig.rpcUrl,
chainType: 'BITCOIN',
options: {
network: bitcoinConfig.network,
},
};
}

public async signTransaction(txn: string, inputIndex: number) {
return this.request(
this.utils.createJsonRpcRequestPayload(BitcoinPayloadMethod.BitcoinSignTransaction, [txn, inputIndex]),
);
}
}
8 changes: 8 additions & 0 deletions packages/@magic-ext/bitcoin/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface BitcoinConfig {
rpcUrl: string;
network: string;
}

export enum BitcoinPayloadMethod {
BitcoinSignTransaction = 'btc_signTransaction',
}
4 changes: 4 additions & 0 deletions packages/@magic-ext/bitcoin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../tsconfig.settings.json",
}

52 changes: 30 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4118,23 +4118,31 @@ __metadata:
languageName: node
linkType: hard

"@magic-ext/oauth@^0.10.4, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
"@magic-ext/bitcoin@workspace:packages/@magic-ext/bitcoin":
version: 0.0.0-use.local
resolution: "@magic-ext/bitcoin@workspace:packages/@magic-ext/bitcoin"
dependencies:
"@magic-sdk/commons": ^2.2.0
languageName: unknown
linkType: soft

"@magic-ext/oauth@^0.11.0, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
version: 0.0.0-use.local
resolution: "@magic-ext/oauth@workspace:packages/@magic-ext/oauth"
dependencies:
"@magic-sdk/types": ^5.1.4
"@magic-sdk/types": ^5.2.0
"@types/crypto-js": ~3.1.47
crypto-js: ^3.3.0
magic-sdk: ^6.1.4
magic-sdk: ^6.2.0
languageName: unknown
linkType: soft

"@magic-ext/react-native-oauth@workspace:packages/@magic-ext/react-native-oauth":
version: 0.0.0-use.local
resolution: "@magic-ext/react-native-oauth@workspace:packages/@magic-ext/react-native-oauth"
dependencies:
"@magic-sdk/react-native": ^6.1.4
"@magic-sdk/types": ^5.1.4
"@magic-sdk/react-native": ^6.2.0
"@magic-sdk/types": ^5.2.0
"@types/crypto-js": ~3.1.47
crypto-js: ^3.3.0
expo-web-browser: ^8.3.1
Expand All @@ -4145,16 +4153,16 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/webauthn@workspace:packages/@magic-ext/webauthn"
dependencies:
"@magic-sdk/commons": ^2.1.4
"@magic-sdk/commons": ^2.2.0
languageName: unknown
linkType: soft

"@magic-sdk/commons@^2.1.4, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
"@magic-sdk/commons@^2.2.0, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
version: 0.0.0-use.local
resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons"
dependencies:
"@magic-sdk/provider": ^6.1.4
"@magic-sdk/types": ^5.1.4
"@magic-sdk/provider": ^6.2.0
"@magic-sdk/types": ^5.2.0
peerDependencies:
"@magic-sdk/provider": ">=4.3.0"
"@magic-sdk/types": ">=3.1.1"
Expand All @@ -4168,17 +4176,17 @@ __metadata:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-ext/oauth": ^0.10.4
magic-sdk: ^6.1.4
"@magic-ext/oauth": ^0.11.0
magic-sdk: ^6.2.0
languageName: unknown
linkType: soft

"@magic-sdk/provider@^6.1.4, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
"@magic-sdk/provider@^6.2.0, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
version: 0.0.0-use.local
resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider"
dependencies:
"@babel/plugin-transform-modules-commonjs": ^7.9.6
"@magic-sdk/types": ^5.1.4
"@magic-sdk/types": ^5.2.0
"@peculiar/webcrypto": ^1.1.7
eventemitter3: ^4.0.4
localforage: ^1.7.4
Expand All @@ -4190,17 +4198,17 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-sdk/react-native@^6.1.4, @magic-sdk/react-native@workspace:packages/@magic-sdk/react-native":
"@magic-sdk/react-native@^6.2.0, @magic-sdk/react-native@workspace:packages/@magic-sdk/react-native":
version: 0.0.0-use.local
resolution: "@magic-sdk/react-native@workspace:packages/@magic-sdk/react-native"
dependencies:
"@aveq-research/localforage-asyncstorage-driver": ^3.0.1
"@babel/core": ^7.15.0
"@babel/plugin-transform-flow-strip-types": ^7.14.5
"@babel/runtime": ~7.10.4
"@magic-sdk/commons": ^2.1.4
"@magic-sdk/provider": ^6.1.4
"@magic-sdk/types": ^5.1.4
"@magic-sdk/commons": ^2.2.0
"@magic-sdk/provider": ^6.2.0
"@magic-sdk/types": ^5.2.0
"@react-native-async-storage/async-storage": ^1.15.5
"@types/lodash": ^4.14.158
buffer: ~5.6.0
Expand All @@ -4221,7 +4229,7 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-sdk/types@^5.1.4, @magic-sdk/types@workspace:packages/@magic-sdk/types":
"@magic-sdk/types@^5.2.0, @magic-sdk/types@workspace:packages/@magic-sdk/types":
version: 0.0.0-use.local
resolution: "@magic-sdk/types@workspace:packages/@magic-sdk/types"
languageName: unknown
Expand Down Expand Up @@ -13895,16 +13903,16 @@ fsevents@^1.2.7:
languageName: unknown
linkType: soft

"magic-sdk@^6.1.4, magic-sdk@workspace:packages/magic-sdk":
"magic-sdk@^6.2.0, magic-sdk@workspace:packages/magic-sdk":
version: 0.0.0-use.local
resolution: "magic-sdk@workspace:packages/magic-sdk"
dependencies:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-sdk/commons": ^2.1.4
"@magic-sdk/provider": ^6.1.4
"@magic-sdk/types": ^5.1.4
"@magic-sdk/commons": ^2.2.0
"@magic-sdk/provider": ^6.2.0
"@magic-sdk/types": ^5.2.0
localforage: ^1.7.4
localforage-driver-memory: ^1.0.5
languageName: unknown
Expand Down