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

Support dApp Providers (Bitcoin Provider) #162

Merged
merged 60 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9a16db3
Update EVM provider folder structure
saltict Jun 6, 2024
148107d
Init provider core
saltict Jun 10, 2024
c5019c5
[Issue-85] Update getAddresses method for dApp provider
Jun 11, 2024
668e8f5
[Issue-85] Update getAddresses type
Jun 11, 2024
d682f4b
Add method signMessage for bitcoin provider
Thiendekaco Jun 12, 2024
50fe756
[Issue-85] Add type bitcoinSignPsbtRequest
Jun 12, 2024
c36ae34
[Issue-85] Init BitcoinSignPsbtConfirmation
Jun 12, 2024
23a85ad
Add method signPsbt for bitcoin provider
Thiendekaco Jun 13, 2024
0e1245d
Merge remote-tracking branch 'origin/openbit-provider-dev' into openb…
Jun 13, 2024
d23be2a
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provider
Jun 13, 2024
73b2069
Add message to get psbt from transaction
Jun 13, 2024
f507590
Add method signPsbt for bitcoin provider #2
Thiendekaco Jun 13, 2024
d778225
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provider
Jun 14, 2024
55fcdd7
[UI] Update manage website access logic
Jun 14, 2024
d8fdcb6
Update NotSupportConfirmation
Jun 14, 2024
ccea3ab
Update broadcast logic for signPsbt
Jun 14, 2024
d466411
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provider
Jun 18, 2024
69ca415
[UI] Update response type for getAddresses
Jun 18, 2024
3117a86
Merge remote-tracking branch 'origin/master' into openbit-provider
Jun 21, 2024
30770a2
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provider
Jun 21, 2024
5b378aa
Merge remote-tracking branch 'refs/remotes/origin/openbit-provider' i…
Thiendekaco Jun 22, 2024
40ad089
Update logic for showing auth accounts
Jun 22, 2024
7cce940
Update keyring lib
Jun 22, 2024
ff5937c
Merge remote-tracking branch 'refs/remotes/origin/openbit-provider' i…
Thiendekaco Jun 22, 2024
0a1b897
update: Bip-322 standard sign message for bitcoin provider
Thiendekaco Jun 22, 2024
cef32cc
Highlight current account proxy on connect dApp modal
Jun 22, 2024
df8ce1c
update: sign Psbt for bitcoin provider
Thiendekaco Jun 22, 2024
d12ed94
Merge remote-tracking branch 'origin/openbit-provider-dev' into openb…
Jun 22, 2024
7dd3969
update: send Transfer for bitcoin provider
Thiendekaco Jun 22, 2024
af7e081
update: send Transfer for bitcoin provider #1
Thiendekaco Jun 22, 2024
1808bd8
update: send Transfer for bitcoin provider #2
Thiendekaco Jun 22, 2024
125617c
update: send Transfer for bitcoin provider #3
Thiendekaco Jun 22, 2024
b4c68b3
update: send Transfer for bitcoin provider #4
Thiendekaco Jun 22, 2024
5f184be
update: send Transfer for bitcoin provider #5
Thiendekaco Jun 22, 2024
58704e7
Merge branch 'openbit-provider-dev' into openbit-provider
Jun 22, 2024
4be5763
update: send Transfer for bitcoin provider #6
Thiendekaco Jun 22, 2024
5433b7a
Merge remote-tracking branch 'origin/openbit-provider-dev' into openb…
Jun 24, 2024
5ba0ecb
update: send Transfer for bitcoin provider #7
Thiendekaco Jun 24, 2024
b9fedb9
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provid…
Jun 25, 2024
4817d1c
Update sendTransfer confirmation
Jun 26, 2024
322ba31
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provid…
Jun 26, 2024
4db4590
Merge branch 'openbit-provider-dev' into openbit-provider
Jun 26, 2024
62aaf97
Update yarn.lock
dungnguyen-art Jun 26, 2024
d16cce0
Fix eslint issues
Jun 26, 2024
5ba6605
update: send Transfer for bitcoin provider #8
Thiendekaco Jun 26, 2024
2972e76
Fix eslint issues
Jun 26, 2024
80f425f
Update yarn.lock
dungnguyen-art Jun 26, 2024
2859659
update: completed send Transfer for bitcoin provider
Thiendekaco Jun 26, 2024
36d5501
Merge remote-tracking branch 'refs/remotes/origin/openbit-provider' i…
Thiendekaco Jun 26, 2024
358d874
Fix sign issue
Jun 27, 2024
1884455
Merge remote-tracking branch 'refs/remotes/origin/openbit-provider' i…
Thiendekaco Jun 27, 2024
f92c3a4
fix: optional signAtIndex of signPsbt method
Thiendekaco Jun 27, 2024
48a6d6f
fix: type address follow bittest-84 standard
Thiendekaco Jun 27, 2024
cbeecc9
Update yarn lock
Jun 27, 2024
95a1f0d
Merge remote-tracking branch 'origin/openbit-dev' into openbit-provider
Jun 27, 2024
62e3301
Fix eslint issue
Jun 27, 2024
02fa41d
fix: loading page after transfer
Thiendekaco Jun 27, 2024
719fa35
fix: transaction response for dapp
Thiendekaco Jun 27, 2024
93d510f
Update signPSBT logic
Jun 28, 2024
8b0dee1
Fix issue related to send fund
Jun 28, 2024
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
25 changes: 14 additions & 11 deletions local-libs/keyring/cjs/pair/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createPair = createPair;
var _bip322Js = require("bip322-js");
var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
var _bitcoinjsMessage = require("bitcoinjs-message");
var _ecpair = require("ecpair");
var _ethSimpleKeyring = _interopRequireDefault(require("eth-simple-keyring"));
var ecc = _interopRequireWildcard(require("tiny-secp256k1"));
Expand Down Expand Up @@ -108,13 +108,13 @@ function createPair(_ref, _ref2) {
const encodeAddress = () => {
const raw = _utils.TYPE_ADDRESS[type](publicKey);
const bitNetwork = ['bitcoin-44', 'bitcoin-84', 'bitcoin-86'].includes(type) ? bitcoin.networks.bitcoin : ['bittest-44', 'bittest-84', 'bittest-86'].includes(type) ? bitcoin.networks.testnet : bitcoin.networks.regtest;
let dataKey;

/**
* With bitcoin accounts, some attached account have no public key (only address).
* In this case, public key is the hash of result after decoded address.
* Add `noPublicKey` in metadata for this case.
*/
let dataKey;
if (meta.noPublicKey) {
dataKey = 'hash';
} else {
Expand Down Expand Up @@ -316,34 +316,37 @@ function createPair(_ref, _ref2) {
type
}, derived, meta, null);
},
signMessage: (message, compressed, options) => {
signMessage: message => {
if (isLocked(secretKey)) {
throw new Error('Cannot encrypt with a locked key pair');
}
const _message = typeof message === 'string' ? message : Buffer.from(message);
const _message = typeof message === 'string' ? message : (0, _util.u8aToString)(message);
const address = encodeAddress();
const _pair = ECPair.fromPrivateKey(Buffer.from(secretKey));
const wif = _pair.toWIF();

// Sign the message
const signature = (0, _bitcoinjsMessage.sign)(_message, Buffer.from(secretKey), compressed, options);
return signature.toString('base64');
const signature = _bip322Js.Signer.sign(wif, address, _message);
return typeof signature === 'string' ? signature : signature.toString('base64');
},
signTransaction: (transaction, indexes) => {
signTransaction: (psbt, indexes, sighashTypes, tapLeafHashToSign) => {
if (isLocked(secretKey)) {
throw new Error('Cannot encrypt with a locked key pair');
}
if (!transaction) {
if (!psbt) {
throw new Error('Not found sign method');
}
const pair = ECPair.fromPrivateKey(Buffer.from(secretKey));
const isTaproot = ['bitcoin-86', 'bittest-86'].includes(type);
for (const index of indexes) {
if (isTaproot) {
const tweakedSigner = pair.tweak(bitcoin.crypto.taggedHash('TapTweak', toXOnly(pair.publicKey)));
transaction.signTaprootInput(index, tweakedSigner);
psbt.signTaprootInput(index, tweakedSigner, tapLeafHashToSign, sighashTypes);
} else {
transaction.signInput(index, pair);
psbt.signInput(index, pair, sighashTypes);
}
}
return transaction;
return psbt;
},
get output() {
return output || Buffer.from([]);
Expand Down
10 changes: 9 additions & 1 deletion local-libs/keyring/cjs/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BitcoinAddressType = void 0;
exports.SubstrateKeypairTypes = exports.EthereumKeypairTypes = exports.BitcoinKeypairTypes = exports.BitcoinAddressType = void 0;
// Copyright 2017-2022 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0

/**
*
*
* */

const SubstrateKeypairTypes = ['sr25519', 'ed25519', 'ecdsa'];
exports.SubstrateKeypairTypes = SubstrateKeypairTypes;
const EthereumKeypairTypes = ['ethereum'];
exports.EthereumKeypairTypes = EthereumKeypairTypes;
const BitcoinKeypairTypes = ['bitcoin-44', 'bitcoin-84', 'bitcoin-86', 'bittest-44', 'bittest-84', 'bittest-86'];
exports.BitcoinKeypairTypes = BitcoinKeypairTypes;
let BitcoinAddressType;
exports.BitcoinAddressType = BitcoinAddressType;
(function (BitcoinAddressType) {
Expand Down
14 changes: 7 additions & 7 deletions local-libs/keyring/cjs/utils/derive-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getEvmDerivePath = index => {
return emvPath.replace('{index}', index.toString());
};
exports.getEvmDerivePath = getEvmDerivePath;
const getBitDerivePathFunction = (proposal, slip44) => {
const getBitDerivePathFunction = (slip44, proposal) => {
const path = bitPath.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
return index => {
return path.replace('{index}', index.toString());
Expand All @@ -27,17 +27,17 @@ const getDerivePath = type => {
case 'ethereum':
return getEvmDerivePath;
case 'bitcoin-44':
return getBitDerivePathFunction(44, 0);
return getBitDerivePathFunction(0, 44);
case 'bitcoin-84':
return getBitDerivePathFunction(84, 0);
return getBitDerivePathFunction(0, 84);
case 'bitcoin-86':
return getBitDerivePathFunction(86, 0);
return getBitDerivePathFunction(0, 86);
case 'bittest-44':
return getBitDerivePathFunction(44, 1);
return getBitDerivePathFunction(1, 44);
case 'bittest-84':
return getBitDerivePathFunction(84, 1);
return getBitDerivePathFunction(1, 84);
case 'bittest-86':
return getBitDerivePathFunction(86, 1);
return getBitDerivePathFunction(1, 86);
default:
return () => '';
}
Expand Down
1 change: 1 addition & 0 deletions local-libs/keyring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"@polkadot/util-crypto": "^12.2.1",
"bcryptjs": "^2.4.3",
"bignumber.js": "^9.1.2",
"bip322-js": "^2.0.0",
"bitcoinjs-lib": "^6.1.5",
"bitcoinjs-message": "^2.2.0",
"ecpair": "^2.1.0",
Expand Down
27 changes: 15 additions & 12 deletions local-libs/keyring/pair/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2017-2022 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { Signer } from 'bip322-js';
import * as bitcoin from 'bitcoinjs-lib';
import { sign as bitcoinSignMessage } from 'bitcoinjs-message';
import { ECPairFactory } from 'ecpair';
import SimpleKeyring from 'eth-simple-keyring';
import * as ecc from 'tiny-secp256k1';
import { hexAddPrefix, hexStripPrefix, objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
import { hexAddPrefix, hexStripPrefix, objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a, ethereumEncode, hdEthereum, keyExtractPath, mnemonicToLegacySeed, secp256k1Compress, signatureVerify, sr25519VrfSign, sr25519VrfVerify } from '@polkadot/util-crypto';
import { entropyToMnemonic } from '@polkadot/util-crypto/mnemonic/bip39';
import { getDerivePath, keyFromPath, TYPE_ADDRESS, TYPE_FROM_SEED, TYPE_PREFIX, TYPE_SIGNATURE } from "../utils/index.js";
Expand Down Expand Up @@ -94,13 +94,13 @@ export function createPair({
const encodeAddress = () => {
const raw = TYPE_ADDRESS[type](publicKey);
const bitNetwork = ['bitcoin-44', 'bitcoin-84', 'bitcoin-86'].includes(type) ? bitcoin.networks.bitcoin : ['bittest-44', 'bittest-84', 'bittest-86'].includes(type) ? bitcoin.networks.testnet : bitcoin.networks.regtest;
let dataKey;

/**
* With bitcoin accounts, some attached account have no public key (only address).
* In this case, public key is the hash of result after decoded address.
* Add `noPublicKey` in metadata for this case.
*/
let dataKey;
if (meta.noPublicKey) {
dataKey = 'hash';
} else {
Expand Down Expand Up @@ -301,34 +301,37 @@ export function createPair({
type
}, derived, meta, null);
},
signMessage: (message, compressed, options) => {
signMessage: message => {
if (isLocked(secretKey)) {
throw new Error('Cannot encrypt with a locked key pair');
}
const _message = typeof message === 'string' ? message : Buffer.from(message);
const _message = typeof message === 'string' ? message : u8aToString(message);
const address = encodeAddress();
const _pair = ECPair.fromPrivateKey(Buffer.from(secretKey));
const wif = _pair.toWIF();

// Sign the message
const signature = bitcoinSignMessage(_message, Buffer.from(secretKey), compressed, options);
return signature.toString('base64');
const signature = Signer.sign(wif, address, _message);
return typeof signature === 'string' ? signature : signature.toString('base64');
},
signTransaction: (transaction, indexes) => {
signTransaction: (psbt, indexes, sighashTypes, tapLeafHashToSign) => {
if (isLocked(secretKey)) {
throw new Error('Cannot encrypt with a locked key pair');
}
if (!transaction) {
if (!psbt) {
throw new Error('Not found sign method');
}
const pair = ECPair.fromPrivateKey(Buffer.from(secretKey));
const isTaproot = ['bitcoin-86', 'bittest-86'].includes(type);
for (const index of indexes) {
if (isTaproot) {
const tweakedSigner = pair.tweak(bitcoin.crypto.taggedHash('TapTweak', toXOnly(pair.publicKey)));
transaction.signTaprootInput(index, tweakedSigner);
psbt.signTaprootInput(index, tweakedSigner, tapLeafHashToSign, sighashTypes);
} else {
transaction.signInput(index, pair);
psbt.signInput(index, pair, sighashTypes);
}
}
return transaction;
return psbt;
},
get output() {
return output || Buffer.from([]);
Expand Down
5 changes: 2 additions & 3 deletions local-libs/keyring/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { HexString } from '@polkadot/util/types';
import type { EncryptedJson, Keypair, Prefix } from '@polkadot/util-crypto/types';
import { TypedTransaction } from '@ethereumjs/tx';
import { Psbt as BitcoinTransaction } from 'bitcoinjs-lib';
import { SignatureOptions } from 'bitcoinjs-message';
/**
*
*
Expand Down Expand Up @@ -58,8 +57,8 @@ export interface SubstrateSigner {
}
export interface BitcoinSigner {
derive: (index: number, meta?: KeyringPair$Meta) => KeyringPair;
signMessage: (message: HexString | string | Uint8Array, compressed?: boolean, options?: SignatureOptions) => string;
signTransaction: (transaction: BitcoinTransaction, indexes: number[]) => BitcoinTransaction;
signMessage: (message: HexString | string | Uint8Array) => string;
signTransaction: (transaction: BitcoinTransaction, indexes: number[], sighashTypes?: number[], tapLeafHashToSign?: Buffer | undefined) => BitcoinTransaction;
output: Buffer;
internalPubkey: Buffer;
}
Expand Down
2 changes: 1 addition & 1 deletion local-libs/keyring/utils/derive-path.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { KeypairType } from '../types';
export declare const emvPath = "m/44'/60'/0'/0/{index}";
export declare const bitPath = "m/{proposal}'/{slip44}'/{index}'/0/0";
export declare const getEvmDerivePath: (index: number) => string;
export declare const getBitDerivePathFunction: (proposal: number, slip44: number) => (index: number) => string;
export declare const getBitDerivePathFunction: (slip44: number, proposal: number) => (index: number) => string;
export declare const getDerivePath: (type: KeypairType) => (index: number) => string;
14 changes: 7 additions & 7 deletions local-libs/keyring/utils/derive-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const bitPath = "m/{proposal}'/{slip44}'/{index}'/0/0";
export const getEvmDerivePath = index => {
return emvPath.replace('{index}', index.toString());
};
export const getBitDerivePathFunction = (proposal, slip44) => {
export const getBitDerivePathFunction = (slip44, proposal) => {
const path = bitPath.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
return index => {
return path.replace('{index}', index.toString());
Expand All @@ -17,17 +17,17 @@ export const getDerivePath = type => {
case 'ethereum':
return getEvmDerivePath;
case 'bitcoin-44':
return getBitDerivePathFunction(44, 0);
return getBitDerivePathFunction(0, 44);
case 'bitcoin-84':
return getBitDerivePathFunction(84, 0);
return getBitDerivePathFunction(0, 84);
case 'bitcoin-86':
return getBitDerivePathFunction(86, 0);
return getBitDerivePathFunction(0, 86);
case 'bittest-44':
return getBitDerivePathFunction(44, 1);
return getBitDerivePathFunction(1, 44);
case 'bittest-84':
return getBitDerivePathFunction(84, 1);
return getBitDerivePathFunction(1, 84);
case 'bittest-86':
return getBitDerivePathFunction(86, 1);
return getBitDerivePathFunction(1, 86);
default:
return () => '';
}
Expand Down
4 changes: 3 additions & 1 deletion packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@
"web3-core-subscriptions": "1.10.0",
"web3-eth": "1.10.0",
"web3-eth-contract": "^1.10.0",
"web3-utils": "^1.10.0"
"web3-utils": "^1.10.0",
"yup": "^1.4.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No use for this library found

},
"devDependencies": {
"@btckit/types": "^0.0.19",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No use for this library found

"@types/uuid": "^9.0.1"
}
}
Loading
Loading