Skip to content

Commit 5c02bfb

Browse files
committed
Merge branch 'solanaKitBWC' of github.com:leolambo/bitcore
2 parents 84c3b8c + f4bc4c2 commit 5c02bfb

File tree

27 files changed

+916
-154
lines changed

27 files changed

+916
-154
lines changed

packages/bitcore-wallet-client/src/lib/api.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const Bitcore_ = {
3232
op: CWC.BitcoreLib,
3333
xrp: CWC.BitcoreLib,
3434
doge: CWC.BitcoreLibDoge,
35-
ltc: CWC.BitcoreLibLtc
35+
ltc: CWC.BitcoreLibLtc,
36+
sol: CWC.BitcoreLib,
3637
};
3738

3839
const NetworkChar = {
@@ -707,6 +708,7 @@ export class API extends EventEmitter {
707708
case 'arb':
708709
case 'base':
709710
case 'op':
711+
case 'sol':
710712
const unsignedTxs = t.uncheckedSerialize();
711713
const signedTxs = [];
712714
for (let index = 0; index < signatures.length; index++) {
@@ -756,6 +758,7 @@ export class API extends EventEmitter {
756758
* @param {string} [opts.customData]
757759
* @param {string} [opts.coin]
758760
* @param {string} [opts.hardwareSourcePublicKey]
761+
* @param {string} [opts.clientDerivedPublicKey]
759762
* @param {function} cb Callback function in the standard form (err, wallet)
760763
* @returns {API} Returns instance of API wallet
761764
*/
@@ -786,7 +789,8 @@ export class API extends EventEmitter {
786789
xPubKey,
787790
requestPubKey,
788791
customData: encCustomData,
789-
hardwareSourcePublicKey: opts.hardwareSourcePublicKey
792+
hardwareSourcePublicKey: opts.hardwareSourcePublicKey,
793+
clientDerivedPublicKey: opts.clientDerivedPublicKey
790794
};
791795
if (opts.dryRun) args.dryRun = true;
792796

@@ -941,7 +945,8 @@ export class API extends EventEmitter {
941945
usePurpose48: n > 1,
942946
useNativeSegwit: !!opts.useNativeSegwit,
943947
segwitVersion: opts.segwitVersion,
944-
hardwareSourcePublicKey: c.hardwareSourcePublicKey
948+
hardwareSourcePublicKey: c.hardwareSourcePublicKey,
949+
clientDerivedPublicKey: c.clientDerivedPublicKey
945950
};
946951
this.request.post('/v2/wallets/', args, (err, res) => {
947952
if (err) return cb(err);
@@ -967,7 +972,8 @@ export class API extends EventEmitter {
967972
{
968973
coin,
969974
chain,
970-
hardwareSourcePublicKey: c.hardwareSourcePublicKey
975+
hardwareSourcePublicKey: c.hardwareSourcePublicKey,
976+
clientDerivedPublicKey: c.clientDerivedPublicKey
971977
},
972978
(err, wallet) => {
973979
if (err) return cb(err);
@@ -2806,7 +2812,8 @@ export class API extends EventEmitter {
28062812
network: opts.network,
28072813
account: opts.account,
28082814
n: opts.n,
2809-
use0forBCH: opts.use0forBCH // only used for server assisted import
2815+
use0forBCH: opts.use0forBCH, // only used for server assisted import
2816+
algo: opts.algo
28102817
});
28112818

28122819
if (copayerIdAlreadyTested[c.copayerId + ':' + opts.n]) {
@@ -2831,6 +2838,7 @@ export class API extends EventEmitter {
28312838
['eth', 'base', 'livenet'],
28322839
['eth', 'op', 'livenet'],
28332840
['xrp', 'xrp', 'livenet'],
2841+
['sol', 'sol', 'livenet'],
28342842
['doge', 'doge', 'livenet'],
28352843
['ltc', 'ltc', 'livenet'],
28362844
['btc', 'btc', 'livenet', true],
@@ -2868,7 +2876,8 @@ export class API extends EventEmitter {
28682876
network: opt[2],
28692877
account: 0,
28702878
n: opt[3] ? 2 : 1,
2871-
use0forBCH: opt[4]
2879+
use0forBCH: opt[4],
2880+
algo: opt[5],
28722881
};
28732882
generateCredentials(key, optsObj);
28742883
}
@@ -3122,6 +3131,7 @@ export class API extends EventEmitter {
31223131
{ chain: 'arb', tokenAddresses: wallet.status.preferences.arbTokenAddresses, multisigInfo: wallet.status.preferences.multisigArbInfo, tokenOpts: Constants.ARB_TOKEN_OPTS, tokenUrlPath: 'arb' },
31233132
{ chain: 'op', tokenAddresses: wallet.status.preferences.opTokenAddresses, multisigInfo: wallet.status.preferences.multisigOpInfo, tokenOpts: Constants.OP_TOKEN_OPTS, tokenUrlPath: 'op' },
31243133
{ chain: 'base', tokenAddresses: wallet.status.preferences.baseTokenAddresses, multisigInfo: wallet.status.preferences.multisigBaseInfo, tokenOpts: Constants.BASE_TOKEN_OPTS, tokenUrlPath: 'base' },
3134+
{ chain: 'sol', tokenAddresses: wallet.status.preferences.solTokenAddresses, multisigInfo: wallet.status.preferences.multisigSolInfo, tokenOpts: Constants.SOL_TOKEN_OPTS, tokenUrlPath: 'sol' },
31253135
];
31263136

31273137
for (let config of chainConfigurations) {

packages/bitcore-wallet-client/src/lib/common/constants.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ export const Constants = {
2424
REQUEST_KEY_AUTH: 'm/2' // relative to BASE
2525
},
2626
BIP45_SHARED_INDEX: 0x80000000 - 1,
27+
CURVES: {
28+
ED25519: 'ed25519',
29+
SECP256K1: 'secp256k1',
30+
},
31+
ALGOS: {
32+
EDDSA: 'EDDSA',
33+
ECDSA: 'ECDSA'
34+
},
35+
CURVE_KEY: {
36+
ED25519: 'ed25519',
37+
BITCOIN: 'bitcoin',
38+
},
2739

2840
// there is no need to add new entries here ( only for backwards compatiblity )
2941
BITPAY_SUPPORTED_ETH_ERC20: [
@@ -41,14 +53,16 @@ export const Constants = {
4153
'usdt'
4254
],
4355

44-
CHAINS: ['btc', 'bch', 'eth', 'matic', 'xrp', 'doge', 'ltc', 'arb', 'base', 'op'],
56+
CHAINS: ['btc', 'bch', 'eth', 'matic', 'xrp', 'doge', 'ltc', 'arb', 'base', 'op', 'sol'],
4557
UTXO_CHAINS: ['btc', 'bch', 'doge', 'ltc'],
4658
EVM_CHAINS: ['eth', 'matic', 'arb', 'base', 'op'],
59+
SVM_CHAINS: ['sol'],
4760
ETH_TOKEN_OPTS: CWC.Constants.ETH_TOKEN_OPTS,
4861
MATIC_TOKEN_OPTS: CWC.Constants.MATIC_TOKEN_OPTS,
4962
ARB_TOKEN_OPTS: CWC.Constants.ARB_TOKEN_OPTS,
5063
BASE_TOKEN_OPTS: CWC.Constants.BASE_TOKEN_OPTS,
5164
OP_TOKEN_OPTS: CWC.Constants.OP_TOKEN_OPTS,
65+
SOL_TOKEN_OPTS: CWC.Constants.SOL_TOKEN_OPTS,
5266
UNITS: CWC.Constants.UNITS,
5367
EVM_CHAINSUFFIXMAP: {
5468
eth: 'e',

packages/bitcore-wallet-client/src/lib/common/utils.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const Bitcore_ = {
2626
op: Bitcore,
2727
xrp: Bitcore,
2828
doge: BitcoreLibDoge,
29-
ltc: BitcoreLibLtc
29+
ltc: BitcoreLibLtc,
30+
sol: Bitcore
3031
};
3132
const PrivateKey = Bitcore.PrivateKey;
3233
const PublicKey = Bitcore.PublicKey;
@@ -181,16 +182,17 @@ export class Utils {
181182
network,
182183
chain,
183184
escrowInputs?,
184-
hardwareSourcePublicKey?
185+
hardwareSourcePublicKey?,
186+
clientDerivedPublicKey?
185187
) {
186188
$.checkArgument(Object.values(Constants.SCRIPT_TYPES).includes(scriptType));
187-
188-
if (hardwareSourcePublicKey) {
189-
const bitcoreAddress = Deriver.getAddress(chain.toUpperCase(), network, hardwareSourcePublicKey, scriptType);
189+
const externSourcePublicKey = hardwareSourcePublicKey || clientDerivedPublicKey;
190+
if (externSourcePublicKey) {
191+
const bitcoreAddress = Deriver.getAddress(chain.toUpperCase(), network, externSourcePublicKey, scriptType);
190192
return {
191193
address: bitcoreAddress.toString(),
192194
path,
193-
publicKeys: [hardwareSourcePublicKey]
195+
publicKeys: [externSourcePublicKey]
194196
}
195197
}
196198

@@ -467,13 +469,14 @@ export class Utils {
467469
}
468470
const unsignedTxs = [];
469471
// If it is a token swap its an already created ERC20 transaction so we skip it and go directly to ETH transaction create
470-
const isERC20 = tokenAddress && !payProUrl && !isTokenSwap;
472+
const isToken = tokenAddress && !payProUrl && !isTokenSwap;
471473
const isMULTISIG = multisigContractAddress;
472474
const chainName = chain.toUpperCase();
475+
const tokenType = chainName === 'SOL' ? 'SPL' : 'ERC20'
473476
const _chain = isMULTISIG
474477
? chainName + 'MULTISIG'
475-
: isERC20
476-
? chainName + 'ERC20'
478+
: isToken
479+
? chainName + tokenType
477480
: chainName;
478481

479482
if (multiSendContractAddress) {
@@ -503,7 +506,7 @@ export class Utils {
503506
...recepient,
504507
tag: _tag ? Number(_tag) : undefined,
505508
chain: _chain,
506-
nonce: Number(txp.nonce) + Number(index),
509+
nonce: this.formatNonce(chainName, txp.nonce, index),
507510
recipients: [recepient]
508511
});
509512
unsignedTxs.push(rawTx);
@@ -515,8 +518,8 @@ export class Utils {
515518
...recipients[index],
516519
tag: destinationTag ? Number(destinationTag) : undefined,
517520
chain: _chain,
518-
nonce: Number(txp.nonce) + Number(index),
519-
recipients: [recipients[index]]
521+
nonce: this.formatNonce(chainName, txp.nonce, index),
522+
recipients: [recipients[index]],
520523
});
521524
unsignedTxs.push(rawTx);
522525
}
@@ -525,6 +528,14 @@ export class Utils {
525528
}
526529
}
527530

531+
static formatNonce(chain, nonce, index) {
532+
if (Constants.SVM_CHAINS.includes(chain.toLowerCase())) {
533+
return nonce
534+
} else {
535+
return Number(nonce) + Number(index)
536+
}
537+
}
538+
528539
static getCurrencyCodeFromCoinAndChain(coin: string, chain: string): string {
529540
if (coin.toLowerCase() === chain.toLowerCase()) {
530541
return coin.toUpperCase();

packages/bitcore-wallet-client/src/lib/credentials.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export class Credentials {
4343
'keyId', // this is only for information
4444
'token', // this is for a ERC20 token
4545
'multisigEthInfo', // this is for a MULTISIG eth wallet
46-
'hardwareSourcePublicKey' // public key from a hardware device for this copayer
46+
'hardwareSourcePublicKey', // public key from a hardware device for this copayer
47+
'clientDerivedPublicKey' // for public keys generated client side
4748
];
4849
version: number;
4950
account: number;
@@ -78,6 +79,7 @@ export class Credentials {
7879
externalSource?: boolean; // deprecated property?
7980
hardwareSourcePublicKey: string;
8081
personalEncryptingKey: string;
82+
clientDerivedPublicKey: string
8183

8284
constructor() {
8385
this.version = 2;
@@ -154,7 +156,7 @@ export class Credentials {
154156
requestPubKey: x.requestPubKey
155157
}
156158
];
157-
159+
x.clientDerivedPublicKey = opts.clientDerivedPublicKey
158160
return x;
159161
}
160162

@@ -248,6 +250,8 @@ export class Credentials {
248250
chainPath = '3';
249251
} else if (chain == 'ltc') {
250252
chainPath = '2';
253+
} else if (chain == 'sol') {
254+
chainPath = '501';
251255
} else {
252256
throw new Error('unknown chain: ' + chain);
253257
}
@@ -285,8 +289,8 @@ export class Credentials {
285289
x.account = x.account || 0;
286290

287291
$.checkState(
288-
x.xPrivKey || x.xPubKey || x.xPrivKeyEncrypted || x.hardwareSourcePublicKey,
289-
'Failed State: x.xPrivKey | x.xPubkey | x.xPrivKeyEncrypted | x.hardwareSourcePublicKey at fromObj'
292+
x.xPrivKey || x.xPubKey || x.xPrivKeyEncrypted || x.hardwareSourcePublicKey || x.clientDerivedPublicKey,
293+
'Failed State: x.xPrivKey | x.xPubkey | x.xPrivKeyEncrypted | x.hardwareSourcePublicKey | x.clientDerivedPublicKey at fromObj'
290294
);
291295
return x;
292296
}

0 commit comments

Comments
 (0)