Skip to content

Commit

Permalink
Merge pull request #5 from COINiD/feature/sign-message
Browse files Browse the repository at this point in the history
Feature/sign message
  • Loading branch information
rikardwissing committed Apr 10, 2019
2 parents 4a6b4b9 + 485a0ea commit b5fd25e
Show file tree
Hide file tree
Showing 24 changed files with 726 additions and 26 deletions.
30 changes: 30 additions & 0 deletions __tests__/__snapshots__/coinid-public-test.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`bitcoin COINiDPublic can create message signing data 1`] = `"MSG/BTC:49-*0-*0-*0*5+3GO7JP:49-*0-*0-*0*5:This%20is%20a%20test%20message"`;

exports[`bitcoin COINiDPublic can create transaction data 1`] = `"TX/BTC:49-*0-*0-*0*5+3GO7JP:49-*0-*0-*0*5+49-*0-*0-*1*2:0100000002A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C020000000000000000A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C01000000000000000005400D03000000000017A914A89F3493631D141E847A15CB3BA68234CC6ACC2E87B08F0600000000001976A9147E6257D509CCDD623F4AB33416F17A44A0A5F7BC88AC10270000000000001600147E6257D509CCDD623F4AB33416F17A44A0A5F7BC307500000000000017A91461F05801F6931D95CD0180917B6CACF84C767E818738FA01000000000017A914CD05CE4F0D4B88D2E00A9FE7CF3AA8FEEAF773628700000000:4:369796+430000"`;

exports[`bitcoin COINiDPublic fails to generate message with invalid address 1`] = `undefined`;

exports[`bitcoin COINiDPublic fails to verify invalid signature 1`] = `undefined`;

exports[`bitcoin COINiDPublic generates a correct P2PKH addresses 1`] = `
Array [
"16FoVqrkVAAUWK7RVduXt1RKZRAuCXXoxi",
Expand Down Expand Up @@ -57,8 +63,14 @@ exports[`bitcoin COINiDPublic throws error when address not valid 1`] = `"3H4cAG

exports[`bitcoin COINiDPublic throws error when having insufficient funds 1`] = `undefined`;

exports[`groestlcoin COINiDPublic can create message signing data 1`] = `"MSG/GRS:49-*17-*0-*0*5+3LXPYO:49-*17-*0-*0*5:This%20is%20a%20test%20message"`;

exports[`groestlcoin COINiDPublic can create transaction data 1`] = `"TX/GRS:49-*17-*0-*0*3+3HMJUS:49-*17-*0-*0*3+49-*17-*0-*1*1:0100000002A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C020000000000000000A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C01000000000000000005400D03000000000017A914C50D589AE0965FBB3484D51AF1271A6BC2851E8987B08F0600000000001976A914EF20271534095EA2A69064620164F248997D64CB88AC1027000000000000160014EF20271534095EA2A69064620164F248997D64CB307500000000000017A914609796DC6E5DFFB0948A3D268ACE1FCFE2B4A96B8738FA01000000000017A914263482828E92FF4510191F10A3FA2CDBC1D047118700000000:4:369796+430000"`;

exports[`groestlcoin COINiDPublic fails to generate message with invalid address 1`] = `undefined`;

exports[`groestlcoin COINiDPublic fails to verify invalid signature 1`] = `undefined`;

exports[`groestlcoin COINiDPublic generates a correct P2PKH addresses 1`] = `
Array [
"FXKSZ871pjUFXdGX3Jo1usNkusbKQSr5Nk",
Expand Down Expand Up @@ -114,8 +126,14 @@ exports[`groestlcoin COINiDPublic throws error when address not valid 1`] = `"3K

exports[`groestlcoin COINiDPublic throws error when having insufficient funds 1`] = `undefined`;

exports[`groestlcoin-testnet COINiDPublic can create message signing data 1`] = `"MSG/tGRS:49-*1-*0-*0*5+2N7UPZ:49-*1-*0-*0*5:This%20is%20a%20test%20message"`;

exports[`groestlcoin-testnet COINiDPublic can create transaction data 1`] = `"TX/TGRS:49-*1-*0-*0*2+2NA5BU:49-*1-*0-*0*2+49-*1-*0-*1*1:0100000002A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C020000000000000000A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C01000000000000000005400D03000000000017A914D7EF101DAA78E7656CA3C49B30B854E8C4D7A2BF87B08F0600000000001976A9147E8EB917EAB0DA74EE21769044B8E36562BF5D3288AC10270000000000001600147E8EB917EAB0DA74EE21769044B8E36562BF5D32307500000000000017A914E1BCEA2765A83B1D688CF113A93F78E2D119EA2A8738FA01000000000017A9142E95CFDD61B2F735E6BEDF5291B6F0873E4F1D008700000000:4:369796+430000"`;

exports[`groestlcoin-testnet COINiDPublic fails to generate message with invalid address 1`] = `undefined`;

exports[`groestlcoin-testnet COINiDPublic fails to verify invalid signature 1`] = `undefined`;

exports[`groestlcoin-testnet COINiDPublic generates a correct P2PKH addresses 1`] = `
Array [
"mkwr5sX93GcwRDb38NXXcLb9j9YqpDycMz",
Expand Down Expand Up @@ -171,8 +189,14 @@ exports[`groestlcoin-testnet COINiDPublic throws error when address not valid 1`

exports[`groestlcoin-testnet COINiDPublic throws error when having insufficient funds 1`] = `undefined`;

exports[`myriad COINiDPublic can create message signing data 1`] = `"MSG/XMY:49-*90-*0-*0*5+4OV111:49-*90-*0-*0*5:This%20is%20a%20test%20message"`;

exports[`myriad COINiDPublic can create transaction data 1`] = `"TX/XMY:49-*90-*0-*0*2+4FY57D:49-*90-*0-*0*2:01000000010D4E4F1E87B9F1D14727A9472640F74F4A18BA448CB063ED3574D21FCF74673800000000000000000004400D0300000000001976A9149E9DCD04CF375691FDFA2D19A52AE404B9EF03DE88ACB08F06000000000017A914594F6D51146D61F84C7027A466069E47DE69712C871027000000000000160014293DBC2B6B7CED3D7F363496A4E00B332F209B94E9645E2C0100000017A914556AA879860E42C377B13639C27350469972A71B8700000000:3:5039991221"`;

exports[`myriad COINiDPublic fails to generate message with invalid address 1`] = `undefined`;

exports[`myriad COINiDPublic fails to verify invalid signature 1`] = `undefined`;

exports[`myriad COINiDPublic generates a correct P2PKH addresses 1`] = `
Array [
"MBzgcG2PyPS3xk9FZcRoa6GcEHSW5MoobK",
Expand Down Expand Up @@ -228,8 +252,14 @@ exports[`myriad COINiDPublic throws error when address not valid 1`] = `"MNMer2w

exports[`myriad COINiDPublic throws error when having insufficient funds 1`] = `undefined`;

exports[`testnet COINiDPublic can create message signing data 1`] = `"MSG/tBTC:49-*1-*0-*0*5+2N7UPZ:49-*1-*0-*0*5:This%20is%20a%20test%20message"`;

exports[`testnet COINiDPublic can create transaction data 1`] = `"TX/TBTC:49-*1-*0-*1*0+2MTRGW:49-*1-*0-*1*0+49-*1-*0-*0*5:0100000002A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C020000000000000000A06364D80225EA2181D41AD469B2D5560E594F2C783BBB41CAAA652B493A104C01000000000000000005400D03000000000017A91466A8A442F12B2B8A9C45D3D4CB1CCBDCA952D9A387B08F06000000000017A914D170EE37EA45FBB9DC81598C8445237EC47E8A678710270000000000001976A914F12F2C6E408B3CDFF1991B8783D1EB428F57814B88AC307500000000000016001408C3E3704FC510BEE9F2F05686CBF2A9F541E23F38FA01000000000017A9142E95CFDD61B2F735E6BEDF5291B6F0873E4F1D008700000000:4:369796+430000"`;

exports[`testnet COINiDPublic fails to generate message with invalid address 1`] = `undefined`;

exports[`testnet COINiDPublic fails to verify invalid signature 1`] = `undefined`;

exports[`testnet COINiDPublic generates a correct P2PKH addresses 1`] = `
Array [
"mkwr5sX93GcwRDb38NXXcLb9j9YqowH5DE",
Expand Down
32 changes: 32 additions & 0 deletions __tests__/coinid-public-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ coinArray.forEach(coin => {
correctPayments,
insufficientPayments,
wrongAddressPayments,
messageSignature,
messageAddress,
message,
anotherMessage,
} = require(`./data/${coin}.json`);

var i = 0;
Expand Down Expand Up @@ -85,6 +89,34 @@ coinArray.forEach(coin => {
expect(coinid.P2WPKH.getAllAddresses()).toMatchSnapshot();
});

it('can create message signing data', () => {
const address = coinid.P2SHP2WPKH.getReceiveAddress();
const message = 'This is a test message';
const messageData = coinid.P2SHP2WPKH.buildMsgCoinIdData(address, message);

expect(messageData).toMatchSnapshot();
});

it('fails to generate message with invalid address', () => {
const address = coinid.P2PKH.getReceiveAddress();
const message = 'This is a test message that will fail';

expect(() => {
coinid.P2SHP2WPKH.buildMsgCoinIdData(address, message);
}).toThrowErrorMatchingSnapshot();
});

it('can verify message', () => {
const verify = coinid.P2PKH.verifyMessage(message, messageAddress, messageSignature);
expect(verify).toEqual(true);
});

it('fails to verify invalid signature', () => {
expect(() => {
coinid.P2PKH.verifyMessage(anotherMessage, messageAddress, messageSignature);
}).toThrowErrorMatchingSnapshot();
});

});
});

Expand Down
6 changes: 5 additions & 1 deletion __tests__/data/bitcoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@
"wrongAddressPayments": [
{ "amount": 0.002, "address": "3H4cAGZ7qPd4HcgSQzad9oX4AbSVxs9hMS5", "note": "" },
{ "amount": 0.0043, "address": "1CXFxAnFzeCa61ChFB7iHnFe2NekG74YZE", "note": "" }
]
],
"message": "This is a test message",
"anotherMessage": "This is another test message",
"messageAddress": "3Go7JpcBu7XdYa93EUfvTD4hFbECWRr1Ew",
"messageSignature": "IGqfHR/PVMDAafnYx0nvyeFabcBpwf120CCpzIfvJlhBA7pceh6zUTYtYF8q2Gb61naZuItvVRMsCMgGvAtErIw="
}
6 changes: 5 additions & 1 deletion __tests__/data/groestlcoin-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@
"wrongAddressPayments": [
{ "amount": 0.002, "address": "2NCCvyeutPLBED5fVbPtydrvGX2dUjvaBvUP", "note": "" },
{ "amount": 0.0043, "address": "ms48Qo1Kb8qQEb5A7UNSLf16pTmdsSWju1", "note": "" }
]
],
"message": "This is a test message",
"anotherMessage": "This is another test message",
"messageAddress": "2N7UPz9tH9hkmAoKnR1VhkgBq9TyyDoc3xX",
"messageSignature": "IBCqq4n0DQ8lJQ/VZk+69VcxJQ32KEs0b1dnEjbiRm0AfsVwmmppVcYWCW3m/nOEID8FWpJVyKihbvfJnopEpb4="
}
6 changes: 5 additions & 1 deletion __tests__/data/groestlcoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@
"wrongAddressPayments": [
{ "amount": 0.002, "address": "3KKew2dzLeMDUMchRrVse1e1SVYW3odQM3w", "note": "" },
{ "amount": 0.0043, "address": "Fry6TmG62wfuFP4JKhjuKNjKv8wmjiTVou", "note": "" }
]
],
"message": "This is a test message",
"anotherMessage": "This is another test message",
"messageAddress": "3LXpYowXikyPUATLPCyYASzzomZUKfuKk4",
"messageSignature": "IBBoUR8KwpwrB9EohYzV9f/M+nRXyCEi8kGTGJSKOZPMfubRI0/QDcLzAkPJ3BfGEndJVYv+TkGh40WAMerEAvc="
}
6 changes: 5 additions & 1 deletion __tests__/data/myriad.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
{ "amount": 0.002, "address": "MNMer2wBZNHXpqXJKfwqFzHxNhUNa3PFvPG", "note": "" },
{ "amount": 0.0043, "address": "4mBf9jhXHGNP2PY22uoGo4FQL5dErYxcJr", "note": "" },
{ "amount": 0.0001, "address": "my1q9y7mc2mt0nkn6lekxjt2fcqtxvhjpxu5thhhqj", "note": "" }
]
],
"message": "This is a test message",
"anotherMessage": "This is another test message",
"messageAddress": "4oV111FHy1kR739yXdVv2fp9WhvrhfN4eT",
"messageSignature": "IFK83t6NlHfb0SPHhdnTdmL0hBFbJf+TEQ4ZVzFT4Kz6GHfTJyrQtOwfIO6ipBMdpd+sO9in21K2NNCST2Vtz9Y="
}
6 changes: 5 additions & 1 deletion __tests__/data/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@
"wrongAddressPayments": [
{ "amount": 0.002, "address": "2N2c2wfH4LcxhRjGXxggzmDL2iXsVBQEjwsK", "note": "" },
{ "amount": 0.0043, "address": "2NCLeVvnAoXZou3LrZv9bJMcykSrXnjcRR1", "note": "" }
]
],
"message": "This is a test message",
"anotherMessage": "This is another test message",
"messageAddress": "2N7UPz9tH9hkmAoKnR1VhkgBq9TyyHVL68t",
"messageSignature": "H1ox+mmOF5Wh0LK8RgRtL5YSoSHt3l03qjEEMVLlJzCkEvUzfbEBClNji+OeJ65NepKHDB3vm99DHGqa5vTi/8w="
}
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ android {
applicationId "org.coinid.wallet.tbtc"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 315
versionName "1.6.0"
versionCode 320
versionName "1.7.0"
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
}
Expand Down
4 changes: 2 additions & 2 deletions ios/COINiDWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@
buildSettings = {
APP_RETURN_SCHEME = "coinid-tbtc";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 312;
CURRENT_PROJECT_VERSION = 317;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = GC88SQF2BV;
HEADER_SEARCH_PATHS = (
Expand Down Expand Up @@ -1748,7 +1748,7 @@
buildSettings = {
APP_RETURN_SCHEME = "coinid-tbtc";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 312;
CURRENT_PROJECT_VERSION = 317;
DEVELOPMENT_TEAM = GC88SQF2BV;
HEADER_SEARCH_PATHS = (
"$(inherited)",
Expand Down
4 changes: 2 additions & 2 deletions ios/COINiDWallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.6.0</string>
<string>1.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>312</string>
<string>317</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false />
<key>LSApplicationQueriesSchemes</key>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "COINiDWallet",
"version": "1.6.0",
"version": "1.7.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
Expand All @@ -21,7 +21,7 @@
"bip21": "^2.0.2",
"bip32-utils": "^0.11.1",
"bitcoinjs-lib": "https://github.com/wlc-/bitcoinjs-lib",
"bitcoinjs-message": "^2.0.0",
"bitcoinjs-message": "https://github.com/COINiD/bitcoinjs-message.git#coinid-version",
"buffer": "^4.9.1",
"buffer-reverse": "^1.0.1",
"coinid-address-functions": "https://github.com/wlc-/coinid-address-functions.git",
Expand Down
39 changes: 39 additions & 0 deletions src/actionmenus/VerifyMessageActionMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ActionMenuRouter from './ActionMenuRouter';

class VerifyMessageActionMenu {
constructor({ showActionSheetWithOptions, ...params }) {
this.params = params;
this.actionRouter = new ActionMenuRouter({ showFn: showActionSheetWithOptions });
}

getRootMenu = () => {
const { onParseClipboard } = this.params;
return [
{
name: 'Parse clipboard data',
callback: () => setTimeout(onParseClipboard, 100),
},
{
name: 'Cancel',
isCancel: true,
},
];
};

getActionRoutes = () => {
const actionRoutes = {
root: {
menu: this.getRootMenu(),
},
};

return actionRoutes;
};

show = () => {
this.actionRouter.setRoutes(this.getActionRoutes());
this.actionRouter.goTo('root');
};
}

export default VerifyMessageActionMenu;
Loading

0 comments on commit b5fd25e

Please sign in to comment.