mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-03 17:29:23 +00:00
update bip47 lib
This commit is contained in:
parent
8e959e06e3
commit
76794f14b8
9 changed files with 3343 additions and 3142 deletions
|
@ -176,17 +176,18 @@ mixin PaynymWalletInterface {
|
||||||
PaymentCode sender,
|
PaymentCode sender,
|
||||||
int index,
|
int index,
|
||||||
) async {
|
) async {
|
||||||
final myPrivateKey = await deriveReceivingPrivateKey(
|
final myPrivateKeyNode = await deriveReceivingPrivateKeyNode(
|
||||||
mnemonic: (await _getMnemonicString())!,
|
mnemonic: (await _getMnemonicString())!,
|
||||||
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
||||||
index: index,
|
index: index,
|
||||||
);
|
);
|
||||||
|
|
||||||
final paymentAddress = PaymentAddress.initWithPrivateKey(
|
final paymentAddress = PaymentAddress(
|
||||||
myPrivateKey,
|
bip32Node: myPrivateKeyNode,
|
||||||
sender,
|
paymentCode: sender,
|
||||||
0,
|
networkType: networkType,
|
||||||
);
|
);
|
||||||
|
|
||||||
final pair = paymentAddress.getReceiveAddressKeyPair();
|
final pair = paymentAddress.getReceiveAddressKeyPair();
|
||||||
final address = await generatePaynymReceivingAddressFromKeyPair(
|
final address = await generatePaynymReceivingAddressFromKeyPair(
|
||||||
pair: pair,
|
pair: pair,
|
||||||
|
@ -248,7 +249,7 @@ mixin PaynymWalletInterface {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Uint8List> deriveNotificationPrivateKey({
|
Future<bip32.BIP32> deriveNotificationBip32Node({
|
||||||
required String mnemonic,
|
required String mnemonic,
|
||||||
required String mnemonicPassphrase,
|
required String mnemonicPassphrase,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -257,10 +258,10 @@ mixin PaynymWalletInterface {
|
||||||
mnemonicPassphrase: mnemonicPassphrase,
|
mnemonicPassphrase: mnemonicPassphrase,
|
||||||
);
|
);
|
||||||
final node = root.derivePath(kPaynymDerivePath).derive(0);
|
final node = root.derivePath(kPaynymDerivePath).derive(0);
|
||||||
return node.privateKey!;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Uint8List> deriveReceivingPrivateKey({
|
Future<bip32.BIP32> deriveReceivingPrivateKeyNode({
|
||||||
required String mnemonic,
|
required String mnemonic,
|
||||||
required String mnemonicPassphrase,
|
required String mnemonicPassphrase,
|
||||||
required int index,
|
required int index,
|
||||||
|
@ -270,7 +271,7 @@ mixin PaynymWalletInterface {
|
||||||
mnemonicPassphrase: mnemonicPassphrase,
|
mnemonicPassphrase: mnemonicPassphrase,
|
||||||
);
|
);
|
||||||
final node = root.derivePath(kPaynymDerivePath).derive(index);
|
final node = root.derivePath(kPaynymDerivePath).derive(index);
|
||||||
return node.privateKey!;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// fetch or generate this wallet's bip47 payment code
|
/// fetch or generate this wallet's bip47 payment code
|
||||||
|
@ -287,11 +288,12 @@ mixin PaynymWalletInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Uint8List> signWithNotificationKey(Uint8List data) async {
|
Future<Uint8List> signWithNotificationKey(Uint8List data) async {
|
||||||
final privateKey = await deriveNotificationPrivateKey(
|
final myPrivateKeyNode = await deriveNotificationBip32Node(
|
||||||
mnemonic: (await _getMnemonicString())!,
|
mnemonic: (await _getMnemonicString())!,
|
||||||
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
||||||
);
|
);
|
||||||
final pair = btc_dart.ECPair.fromPrivateKey(privateKey, network: _network);
|
final pair = btc_dart.ECPair.fromPrivateKey(myPrivateKeyNode.privateKey!,
|
||||||
|
network: _network);
|
||||||
final signed = pair.sign(SHA256Digest().process(data));
|
final signed = pair.sign(SHA256Digest().process(data));
|
||||||
return signed;
|
return signed;
|
||||||
}
|
}
|
||||||
|
@ -310,13 +312,13 @@ mixin PaynymWalletInterface {
|
||||||
throw PaynymSendException(
|
throw PaynymSendException(
|
||||||
"No notification transaction sent to $paymentCode");
|
"No notification transaction sent to $paymentCode");
|
||||||
} else {
|
} else {
|
||||||
final myPrivateKey = await deriveNotificationPrivateKey(
|
final myPrivateKeyNode = await deriveNotificationBip32Node(
|
||||||
mnemonic: (await _getMnemonicString())!,
|
mnemonic: (await _getMnemonicString())!,
|
||||||
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
||||||
);
|
);
|
||||||
final sendToAddress = await nextUnusedSendAddressFrom(
|
final sendToAddress = await nextUnusedSendAddressFrom(
|
||||||
pCode: paymentCode,
|
pCode: paymentCode,
|
||||||
privateKey: myPrivateKey,
|
privateKeyNode: myPrivateKeyNode,
|
||||||
);
|
);
|
||||||
|
|
||||||
return _prepareSend(
|
return _prepareSend(
|
||||||
|
@ -331,7 +333,7 @@ mixin PaynymWalletInterface {
|
||||||
/// and your own private key
|
/// and your own private key
|
||||||
Future<Address> nextUnusedSendAddressFrom({
|
Future<Address> nextUnusedSendAddressFrom({
|
||||||
required PaymentCode pCode,
|
required PaymentCode pCode,
|
||||||
required Uint8List privateKey,
|
required bip32.BIP32 privateKeyNode,
|
||||||
int startIndex = 0,
|
int startIndex = 0,
|
||||||
}) async {
|
}) async {
|
||||||
// https://en.bitcoin.it/wiki/BIP_0047#Path_levels
|
// https://en.bitcoin.it/wiki/BIP_0047#Path_levels
|
||||||
|
@ -356,10 +358,11 @@ mixin PaynymWalletInterface {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final pair = PaymentAddress.initWithPrivateKey(
|
final pair = PaymentAddress(
|
||||||
privateKey,
|
bip32Node: privateKeyNode,
|
||||||
pCode,
|
index: i, // index to use
|
||||||
i, // index to use
|
paymentCode: pCode,
|
||||||
|
networkType: networkType,
|
||||||
).getSendAddressKeyPair();
|
).getSendAddressKeyPair();
|
||||||
|
|
||||||
// add address to local db
|
// add address to local db
|
||||||
|
@ -607,8 +610,9 @@ mixin PaynymWalletInterface {
|
||||||
final blindingMask = PaymentCode.getMask(S.ecdhSecret(), rev);
|
final blindingMask = PaymentCode.getMask(S.ecdhSecret(), rev);
|
||||||
|
|
||||||
final blindedPaymentCode = PaymentCode.blind(
|
final blindedPaymentCode = PaymentCode.blind(
|
||||||
myCode.getPayload(),
|
payload: myCode.getPayload(),
|
||||||
blindingMask,
|
mask: blindingMask,
|
||||||
|
unBlind: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
final opReturnScript = bscript.compile([
|
final opReturnScript = bscript.compile([
|
||||||
|
@ -758,19 +762,23 @@ mixin PaynymWalletInterface {
|
||||||
|
|
||||||
final pubKey = designatedInput.scriptSigAsm!.split(" ")[1].fromHex;
|
final pubKey = designatedInput.scriptSigAsm!.split(" ")[1].fromHex;
|
||||||
|
|
||||||
final myPrivateKey = await deriveNotificationPrivateKey(
|
final myPrivateKey = (await deriveNotificationBip32Node(
|
||||||
mnemonic: (await _getMnemonicString())!,
|
mnemonic: (await _getMnemonicString())!,
|
||||||
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
||||||
);
|
))
|
||||||
|
.privateKey!;
|
||||||
|
|
||||||
final S = SecretPoint(myPrivateKey, pubKey);
|
final S = SecretPoint(myPrivateKey, pubKey);
|
||||||
|
|
||||||
final mask = PaymentCode.getMask(S.ecdhSecret(), rev);
|
final mask = PaymentCode.getMask(S.ecdhSecret(), rev);
|
||||||
|
|
||||||
final unBlindedPayload = PaymentCode.blind(blindedCodeBytes, mask);
|
final unBlindedPayload = PaymentCode.blind(
|
||||||
|
payload: blindedCodeBytes,
|
||||||
|
mask: mask,
|
||||||
|
unBlind: true,
|
||||||
|
);
|
||||||
|
|
||||||
final unBlindedPaymentCode =
|
final unBlindedPaymentCode = PaymentCode.fromPayload(unBlindedPayload);
|
||||||
PaymentCode.initFromPayload(unBlindedPayload);
|
|
||||||
|
|
||||||
return unBlindedPaymentCode;
|
return unBlindedPaymentCode;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -904,7 +912,7 @@ mixin PaynymWalletInterface {
|
||||||
final mnemonic = (await _getMnemonicString())!;
|
final mnemonic = (await _getMnemonicString())!;
|
||||||
final mnemonicPassphrase = (await _getMnemonicPassphrase())!;
|
final mnemonicPassphrase = (await _getMnemonicPassphrase())!;
|
||||||
|
|
||||||
final mySendPrivateKey = await deriveNotificationPrivateKey(
|
final mySendBip32Node = await deriveNotificationBip32Node(
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
mnemonicPassphrase: mnemonicPassphrase,
|
mnemonicPassphrase: mnemonicPassphrase,
|
||||||
);
|
);
|
||||||
|
@ -924,10 +932,11 @@ mixin PaynymWalletInterface {
|
||||||
outgoingGapCounter < maxUnusedAddressGap);
|
outgoingGapCounter < maxUnusedAddressGap);
|
||||||
i++) {
|
i++) {
|
||||||
if (outgoingGapCounter < maxUnusedAddressGap) {
|
if (outgoingGapCounter < maxUnusedAddressGap) {
|
||||||
final paymentAddressSending = PaymentAddress.initWithPrivateKey(
|
final paymentAddressSending = PaymentAddress(
|
||||||
mySendPrivateKey,
|
paymentCode: other,
|
||||||
other,
|
bip32Node: mySendBip32Node,
|
||||||
i, // index to use
|
index: i,
|
||||||
|
networkType: networkType,
|
||||||
);
|
);
|
||||||
final pair = paymentAddressSending.getSendAddressKeyPair();
|
final pair = paymentAddressSending.getSendAddressKeyPair();
|
||||||
final address = await generatePaynymSendAddressFromKeyPair(
|
final address = await generatePaynymSendAddressFromKeyPair(
|
||||||
|
@ -948,12 +957,13 @@ mixin PaynymWalletInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivingGapCounter < maxUnusedAddressGap) {
|
if (receivingGapCounter < maxUnusedAddressGap) {
|
||||||
final myReceivingPrivateKey = receivingNode.derive(i).privateKey!;
|
final paymentAddressReceiving = PaymentAddress(
|
||||||
final paymentAddressReceiving = PaymentAddress.initWithPrivateKey(
|
paymentCode: other,
|
||||||
myReceivingPrivateKey,
|
bip32Node: receivingNode.derive(i),
|
||||||
other,
|
index: 0,
|
||||||
0,
|
networkType: networkType,
|
||||||
);
|
);
|
||||||
|
|
||||||
final pair = paymentAddressReceiving.getReceiveAddressKeyPair();
|
final pair = paymentAddressReceiving.getReceiveAddressKeyPair();
|
||||||
final address = await generatePaynymReceivingAddressFromKeyPair(
|
final address = await generatePaynymReceivingAddressFromKeyPair(
|
||||||
pair: pair,
|
pair: pair,
|
||||||
|
@ -1168,9 +1178,8 @@ mixin PaynymWalletInterface {
|
||||||
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
mnemonicPassphrase: (await _getMnemonicPassphrase())!,
|
||||||
);
|
);
|
||||||
final node = root.derivePath(kPaynymDerivePath);
|
final node = root.derivePath(kPaynymDerivePath);
|
||||||
final paymentCode = PaymentCode.initFromPubKey(
|
final paymentCode = PaymentCode.fromBip32Node(
|
||||||
node.publicKey,
|
node,
|
||||||
node.chainCode,
|
|
||||||
_network,
|
_network,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "87bb760be323228aed6ca7bd4532a709a4f10690"
|
ref: "7b7c0b9284e7457f40dc60ea4420d8badf1aed39"
|
||||||
resolved-ref: "87bb760be323228aed6ca7bd4532a709a4f10690"
|
resolved-ref: "7b7c0b9284e7457f40dc60ea4420d8badf1aed39"
|
||||||
url: "https://github.com/cypherstack/bip47.git"
|
url: "https://github.com/cypherstack/bip47.git"
|
||||||
source: git
|
source: git
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
|
|
|
@ -59,7 +59,7 @@ dependencies:
|
||||||
bip47:
|
bip47:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cypherstack/bip47.git
|
url: https://github.com/cypherstack/bip47.git
|
||||||
ref: 87bb760be323228aed6ca7bd4532a709a4f10690
|
ref: 7b7c0b9284e7457f40dc60ea4420d8badf1aed39
|
||||||
|
|
||||||
# Utility plugins
|
# Utility plugins
|
||||||
# provider: ^6.0.1
|
# provider: ^6.0.1
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue