From ebae9117a294a989f648562a151ab9a12a985611 Mon Sep 17 00:00:00 2001 From: Greg S Date: Thu, 20 Feb 2020 15:39:01 +0100 Subject: [PATCH 1/2] changed all occurences of KECCAK and SHA3 to standard ED25519 SHA512 derivations (SLIP10 compatible) --- index.ts | 1 - package-lock.json | 595 +++++++++++++++++++++++++-------- package.json | 8 +- src/CatapultECC.ts | 236 ------------- src/Compat/DeterministicKey.ts | 5 +- src/Cryptography.ts | 7 +- src/CurveAlgorithm.ts | 1 - src/Curves/NodeEd25519.ts | 46 ++- src/Network.ts | 26 +- src/Wallet.ts | 4 - test/CatapultECC.spec.ts | 278 --------------- test/DerivationEd25519.spec.ts | 72 +--- test/DerivationKMAC.spec.ts | 16 +- test/ExtendedKey.spec.ts | 62 ++-- test/Network.spec.ts | 29 +- test/Wallet.spec.ts | 6 +- 16 files changed, 556 insertions(+), 836 deletions(-) delete mode 100644 src/CatapultECC.ts delete mode 100644 test/CatapultECC.spec.ts diff --git a/index.ts b/index.ts index 17bb44e..50c42a2 100644 --- a/index.ts +++ b/index.ts @@ -25,7 +25,6 @@ export { KeyEncoding } from './src/KeyEncoding'; export { Network } from './src/Network'; export { Cryptography } from './src/Cryptography'; export { HasherInterface } from './src/HasherInterface'; -export { CatapultECC } from './src/CatapultECC'; export { NodeInterface } from './src/NodeInterface'; export { DeterministicKey } from './src/Compat/DeterministicKey'; export { NodeEd25519 } from './src/Curves/NodeEd25519'; diff --git a/package-lock.json b/package-lock.json index 3eea535..fe034ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -130,10 +130,20 @@ "@types/node": "*" } }, + "@types/bluebird": { + "version": "3.5.29", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.29.tgz", + "integrity": "sha512-kmVtnxTuUuhCET669irqQmPAez4KFnFVKvpleVRyfC3g+SHD1hIkFZcWLim9BVcwUBLO59o8VZE4yGCmTif8Yw==" + }, + "@types/caseless": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz", + "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==" + }, "@types/chai": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.5.tgz", - "integrity": "sha512-YvbLiIc0DbbhiANrfVObdkLEHJksQZVq0Uvfg550SRAKVYaEJy+V70j65BVe2WNp6E3HtKsUczeijHFCjba3og==", + "version": "4.2.9", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.9.tgz", + "integrity": "sha512-NeXgZj+MFL4izGqA4sapdYzkzQG+MtGra9vhQ58dnmDY++VgJaRUws+aLVV5zRJCYJl/8s9IjMmhiUw1WsKSmw==", "dev": true }, "@types/mocha": { @@ -147,6 +157,34 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==" }, + "@types/request": { + "version": "2.48.4", + "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz", + "integrity": "sha512-W1t1MTKYR8PxICH+A4HgEIPuAC3sbljoEVfyZbeFJJDbr30guDspJri2XOaM2E+Un7ZjrihaDi7cf6fPa2tbgw==", + "requires": { + "@types/caseless": "*", + "@types/node": "*", + "@types/tough-cookie": "*", + "form-data": "^2.5.0" + }, + "dependencies": { + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + } + } + }, + "@types/tough-cookie": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz", + "integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ==" + }, "ajv": { "version": "6.10.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", @@ -158,6 +196,11 @@ "uri-js": "^4.2.2" } }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -236,11 +279,245 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + } + } + }, + "babel-core": { + "version": "6.26.3", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", + "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", + "requires": { + "babel-code-frame": "^6.26.0", + "babel-generator": "^6.26.0", + "babel-helpers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-register": "^6.26.0", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "convert-source-map": "^1.5.1", + "debug": "^2.6.9", + "json5": "^0.5.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.4", + "path-is-absolute": "^1.0.1", + "private": "^0.1.8", + "slash": "^1.0.0", + "source-map": "^0.5.7" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, + "babel-generator": { + "version": "6.26.1", + "resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz", + "integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==", + "requires": { + "babel-messages": "^6.23.0", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "detect-indent": "^4.0.0", + "jsesc": "^1.3.0", + "lodash": "^4.17.4", + "source-map": "^0.5.7", + "trim-right": "^1.0.1" + }, + "dependencies": { + "jsesc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", + "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=" + } + } + }, + "babel-helpers": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-helpers/-/babel-helpers-6.24.1.tgz", + "integrity": "sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI=", + "requires": { + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-messages": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", + "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-block-scoping": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz", + "integrity": "sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=", + "requires": { + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "lodash": "^4.17.4" + } + }, + "babel-register": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-register/-/babel-register-6.26.0.tgz", + "integrity": "sha1-btAhFz4vy0htestFxgCahW9kcHE=", + "requires": { + "babel-core": "^6.26.0", + "babel-runtime": "^6.26.0", + "core-js": "^2.5.0", + "home-or-tmp": "^2.0.0", + "lodash": "^4.17.4", + "mkdirp": "^0.5.1", + "source-map-support": "^0.4.15" + }, + "dependencies": { + "source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", + "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "requires": { + "source-map": "^0.5.6" + } + } + } + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "requires": { + "core-js": "^2.4.0", + "regenerator-runtime": "^0.11.0" + } + }, + "babel-template": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz", + "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", + "requires": { + "babel-runtime": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "lodash": "^4.17.4" + } + }, + "babel-traverse": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz", + "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", + "requires": { + "babel-code-frame": "^6.26.0", + "babel-messages": "^6.23.0", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "debug": "^2.6.8", + "globals": "^9.18.0", + "invariant": "^2.2.2", + "lodash": "^4.17.4" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "globals": { + "version": "9.18.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", + "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, + "babel-types": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz", + "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", + "requires": { + "babel-runtime": "^6.26.0", + "esutils": "^2.0.2", + "lodash": "^4.17.4", + "to-fast-properties": "^1.0.3" + }, + "dependencies": { + "to-fast-properties": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", + "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=" + } + } + }, + "babylon": { + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", + "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base-x": { "version": "3.0.5", @@ -309,7 +586,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -378,6 +654,11 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, + "catbuffer": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/catbuffer/-/catbuffer-0.0.11.tgz", + "integrity": "sha512-xcv43mcBDeZ1NldCsKwD28gBIs/mj+QBMiu3BI9511Wqeo5VfIsqKULAI9OGTOKaf48G7AYYZHWKKov/EkhcfQ==" + }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -469,63 +750,6 @@ } } }, - "cobertura-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/cobertura-parse/-/cobertura-parse-1.0.5.tgz", - "integrity": "sha512-uYJfkGhzw1wibe/8jqqHmSaPNWFguzq/IlSj83u3cSnZho/lUnfj0mLTmZGmB3AiKCOTYr22TYwpR1sXy2JEkg==", - "dev": true, - "requires": { - "mocha": "5.0.5", - "xml2js": "0.4.19" - }, - "dependencies": { - "commander": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", - "dev": true - }, - "growl": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", - "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", - "dev": true - }, - "has-flag": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", - "dev": true - }, - "mocha": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.5.tgz", - "integrity": "sha512-3MM3UjZ5p8EJrYpG7s+29HAI9G7sTzKEe4+w37Dg0QP7qL4XGsV+Q2xet2cE37AqdgN1OtYQB6Vl98YiPV3PgA==", - "dev": true, - "requires": { - "browser-stdout": "1.3.1", - "commander": "2.11.0", - "debug": "3.1.0", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.3", - "he": "1.1.1", - "mkdirp": "0.5.1", - "supports-color": "4.4.0" - } - }, - "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", - "dev": true, - "requires": { - "has-flag": "^2.0.0" - } - } - } - }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -564,30 +788,32 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "convert-source-map": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", - "dev": true, "requires": { "safe-buffer": "~5.1.1" } }, + "core-js": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "coveralls": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.8.tgz", - "integrity": "sha512-lkQlg29RhV9zwB0gDaEAWoap8xPgFxtPsVIpTNiDDtWNrvtP1/RmGJRRAV/Loz2gihmppObkSL0wnptEGUXaOQ==", + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.9.tgz", + "integrity": "sha512-nNBg3B1+4iDox5A5zqHKzUTiwl2ey4k2o0NEcVZYvl+GOSJdKBj4AJGKLv6h3SvWch7tABHePAQOSZWM9E2hMg==", "dev": true, "requires": { - "cobertura-parse": "^1.0.5", "js-yaml": "^3.13.1", "lcov-parse": "^1.0.0", "log-driver": "^1.2.7", @@ -644,9 +870,9 @@ } }, "crypto-js": { - "version": "3.1.9-1", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz", - "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg=" + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.3.0.tgz", + "integrity": "sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==" }, "dashdash": { "version": "1.14.1", @@ -656,23 +882,6 @@ "assert-plus": "^1.0.0" } }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - }, - "dependencies": { - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - } - } - }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -702,6 +911,14 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "detect-indent": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz", + "integrity": "sha1-920GQ1LN9Docts5hnE7jqUdd4gg=", + "requires": { + "repeating": "^2.0.0" + } + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -764,8 +981,7 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "esprima": { "version": "4.0.1", @@ -776,8 +992,7 @@ "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" }, "execa": { "version": "1.0.0", @@ -885,6 +1100,11 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "futoin-hkdf": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/futoin-hkdf/-/futoin-hkdf-1.3.1.tgz", + "integrity": "sha512-k1DvCXIFAIx3hK8CSwApotX3JUDwA2Wb55zxyIgqwQpCBF2ZHgVqfHpyjG8mRpmsjRH7SWS1N/vj8EdSF9zBhw==" + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -992,6 +1212,14 @@ "har-schema": "^2.0.0" } }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -1041,6 +1269,15 @@ "minimalistic-crypto-utils": "^1.0.1" } }, + "home-or-tmp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", + "integrity": "sha1-42w/LSyufXRqhX440Y1fMqeILbg=", + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.1" + } + }, "hosted-git-info": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", @@ -1078,6 +1315,14 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "invariant": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", + "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "requires": { + "loose-envify": "^1.0.0" + } + }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", @@ -1095,6 +1340,11 @@ "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" }, + "is-finite": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.1.0.tgz", + "integrity": "sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==" + }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -1231,11 +1481,15 @@ "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" }, + "js-sha512": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha512/-/js-sha512-0.8.0.tgz", + "integrity": "sha512-PWsmefG6Jkodqt+ePTvBZCSMFgN7Clckjd0O7su3I0+BW2QWUTJNzjktHsztGLhncP2h8mcF9V9Y2Ha59pAViQ==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { "version": "3.13.1", @@ -1279,6 +1533,11 @@ "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, + "json5": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", + "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -1357,6 +1616,14 @@ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", @@ -1436,9 +1703,9 @@ "integrity": "sha1-grjbrnXieneFOItz+ddyXQ9vMyY=" }, "merkletreejs": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.1.7.tgz", - "integrity": "sha512-PIuNeX2YN84VKzfAVVkhmoC/KGOIk5BiN+sJ9WG2S17kw9TuSoIifK85xzujff0mbtfbTjtaT/9fKvMVq9A1aw==", + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.1.11.tgz", + "integrity": "sha512-nJN3VIHeIAyB/PjO5Dj/Y0SEK7CGCCLD2IbV4el2kUIwlOtX3GOr5MwVO4EU+0AXvoDnJ0nmaLe5O86uIjWz/Q==", "requires": { "buffer-reverse": "^1.0.1", "crypto-js": "^3.1.9-1", @@ -1480,7 +1747,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1495,7 +1761,6 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, "requires": { "minimist": "0.0.8" }, @@ -1503,8 +1768,7 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" } } }, @@ -1556,24 +1820,48 @@ "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" }, "nem2-sdk": { - "version": "0.16.0", - "resolved": "https://registry.npmjs.org/nem2-sdk/-/nem2-sdk-0.16.0.tgz", - "integrity": "sha512-dGErDsbQar5/qDsGkAIr2vRHMO+KZQLEj2DRydOf4dXsOyG7oM+nAPkefP4XC6nea5LnGSv2uPYC/G06u06Tvg==", + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/nem2-sdk/-/nem2-sdk-0.17.0.tgz", + "integrity": "sha512-mKWedYm/DKKbubQ/1cPNgIS/ckRqyxWqKTOLmnqisFGiT4RxOyPGcidYWstoZgjlN8Rz48asJOz7VvKDA2dwaw==", "requires": { "bluebird": "^3.5.5", + "catbuffer": "0.0.11", "crypto-js": "^3.1.9-1", + "futoin-hkdf": "^1.3.1", "js-joda": "^1.6.2", "js-sha256": "^0.9.0", "js-sha3": "^0.8.0", + "js-sha512": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", + "nem2-sdk-openapi-typescript-node-client": "0.8.4", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", - "rxjs": "^6.2.1", - "rxjs-compat": "^6.2.1", + "rxjs": "^6.5.3", + "rxjs-compat": "^6.5.3", + "tweetnacl": "^1.0.3", "utf8": "^2.1.2", "ws": "^5.2.0" + }, + "dependencies": { + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + } + } + }, + "nem2-sdk-openapi-typescript-node-client": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.4.tgz", + "integrity": "sha512-53DukFQUCKr0+bH1fm3fLzIT/v10lv5kdMqBHX4h4jDUslQeXnlBpPi/qX/XDmu2hyjwOWZa7hFzLhlt8xqhdQ==", + "requires": { + "@types/bluebird": "*", + "@types/request": "*", + "bluebird": "^3.5.0", + "request": "^2.81.0", + "rewire": "^3.0.2" } }, "neo-async": { @@ -1699,8 +1987,7 @@ "os-homedir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" }, "os-locale": { "version": "3.1.0", @@ -1713,6 +2000,11 @@ "mem": "^4.0.0" } }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, "p-defer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", @@ -1786,8 +2078,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-key": { "version": "2.0.1", @@ -1862,6 +2153,11 @@ "integrity": "sha512-vPvPe8TKgp4FLgY3+DfxCE5PIfoXBK2lyLfNCxsRbDsV6vS4oU5RG/IWxrblMn6heagbnMED3MemUQllQ2bQUg==", "dev": true }, + "private": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", + "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==" + }, "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -1907,6 +2203,11 @@ "read-pkg": "^3.0.0" } }, + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + }, "release-zalgo": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", @@ -1916,6 +2217,14 @@ "es6-error": "^4.0.1" } }, + "repeating": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz", + "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", + "requires": { + "is-finite": "^1.0.0" + } + }, "request": { "version": "2.88.0", "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", @@ -1995,6 +2304,15 @@ "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, + "rewire": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rewire/-/rewire-3.0.2.tgz", + "integrity": "sha512-ejkkt3qYnsQ38ifc9llAAzuHiGM7kR8N5/mL3aHWgmWwet0OMFcmJB8aTsMV2PBHCWxNVTLCeRfBpEa8X2+1fw==", + "requires": { + "babel-core": "^6.26.0", + "babel-plugin-transform-es2015-block-scoping": "^6.26.0" + } + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -2030,17 +2348,17 @@ } }, "rxjs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.3.tgz", - "integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", + "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", "requires": { "tslib": "^1.9.0" } }, "rxjs-compat": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/rxjs-compat/-/rxjs-compat-6.5.3.tgz", - "integrity": "sha512-BIJX2yovz3TBpjJoAZyls2QYuU6ZiCaZ+U96SmxQpuSP/qDUfiXPKOVLbThBB2WZijNHkdTTJXKRwvv5Y48H7g==" + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs-compat/-/rxjs-compat-6.5.4.tgz", + "integrity": "sha512-rkn+lbOHUQOurdd74J/hjmDsG9nFx0z66fvnbs8M95nrtKvNqCKdk7iZqdY51CGmDemTQk+kUPy4s8HVOHtkfA==" }, "safe-buffer": { "version": "5.1.2", @@ -2052,12 +2370,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", - "dev": true - }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", @@ -2100,11 +2412,15 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, + "slash": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", + "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=" + }, "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" }, "source-map-support": { "version": "0.5.11", @@ -2197,6 +2513,14 @@ "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -2288,8 +2612,7 @@ "trim-right": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", - "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", - "dev": true + "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" }, "ts-node": { "version": "7.0.1", @@ -2517,22 +2840,6 @@ "async-limiter": "~1.0.0" } }, - "xml2js": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", - "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", - "dev": true, - "requires": { - "sax": ">=0.6.0", - "xmlbuilder": "~9.0.1" - } - }, - "xmlbuilder": { - "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", - "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=", - "dev": true - }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", diff --git a/package.json b/package.json index f42ef5d..fe27ab0 100644 --- a/package.json +++ b/package.json @@ -17,15 +17,15 @@ "create-hash": "^1.2.0", "create-hmac": "^1.1.7", "js-sha3": "^0.8.0", - "nem2-sdk": "^0.16.0", - "rxjs": "^6.5.3", + "nem2-sdk": "^0.17.0", + "rxjs": "^6.5.4", "tiny-secp256k1": "^1.1.3" }, "devDependencies": { - "@types/chai": "^4.2.5", + "@types/chai": "^4.2.9", "@types/mocha": "^5.2.7", "chai": "^4.1.2", - "coveralls": "^3.0.8", + "coveralls": "^3.0.9", "mocha": "^5.2.0", "nyc": "^14.1.1", "ts-node": "^7.0.0", diff --git a/src/CatapultECC.ts b/src/CatapultECC.ts deleted file mode 100644 index b5f3a0d..0000000 --- a/src/CatapultECC.ts +++ /dev/null @@ -1,236 +0,0 @@ -/** - * Copyright 2019 NEM - * - * Licensed under the BSD 2-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-2-Clause - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import * as nacl_catapult from 'nem2-sdk'; -import { - RawArray as array, - SignSchema, -}from 'nem2-sdk'; - -// internal dependencies -import { - HasherInterface, -} from '../index'; - -export class CatapultECC { - - public static readonly KEY_SIZE: number = 32; - public static readonly SIGNATURE_SIZE: number = 64; - public static readonly HALF_SIGNATURE_SIZE: number = CatapultECC.SIGNATURE_SIZE / 2; - public static readonly HASH_SIZE: number = 64; - public static readonly HALF_HASH_SIZE: number = CatapultECC.HASH_SIZE / 2; - - /** - * - */ - protected static encodedSChecker = (function () { - const Is_Reduced = 1; - const Is_Zero = 2; - - function validateEncodedSPart( - s: Uint8Array - ): number { - if (array.isZeroFilled(s)) - return Is_Zero | Is_Reduced; - - const copy = new Uint8Array(CatapultECC.SIGNATURE_SIZE); - array.copy(copy, s, CatapultECC.HALF_SIGNATURE_SIZE); - - nacl_catapult.reduce(copy); - return array.deepEqual(s, copy, CatapultECC.HALF_SIGNATURE_SIZE) ? Is_Reduced : 0; - } - - return { - isCanonical: (s: Uint8Array): boolean => Is_Reduced === validateEncodedSPart(s), - - requireValid: (s: Uint8Array): void => { - if (0 === (validateEncodedSPart(s) & Is_Reduced)) - throw Error('S part of signature invalid'); - } - }; - })(); - - /** - * - * @param d - */ - protected static clamp( - d: Uint8Array - ): void { - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - } - - /** - * - * @param sk - * @param hashfunc - */ - protected static prepareForScalarMult( - sk: Uint8Array, - hashfunc: Function, - signSchema: SignSchema = SignSchema.SHA3 - ): Uint8Array { - const d = new Uint8Array(CatapultECC.HASH_SIZE); - hashfunc(d, sk, CatapultECC.HASH_SIZE, signSchema); - CatapultECC.clamp(d); - return d; - } - - public static extractPublicKey( - sk: Uint8Array, - hashfunc: Function, - signSchema: SignSchema = SignSchema.SHA3 - ): Uint8Array { - const c = nacl_catapult; - const d = CatapultECC.prepareForScalarMult(sk, hashfunc, signSchema); - - const p = [c.gf(), c.gf(), c.gf(), c.gf()]; - const pk = new Uint8Array(CatapultECC.KEY_SIZE); - c.scalarbase(p, d); - c.pack(pk, p); - return pk; - } - - public static sign( - m: Uint8Array, - pk: Uint8Array, - sk: Uint8Array, - hasher: HasherInterface - ): Uint8Array { - const c = nacl_catapult; - - const d = new Uint8Array(CatapultECC.HASH_SIZE); - hasher.reset(); - hasher.update(sk); - hasher.finalize(d); - CatapultECC.clamp(d); - - const r = new Uint8Array(CatapultECC.HASH_SIZE); - hasher.reset(); - hasher.update(d.subarray(CatapultECC.HALF_HASH_SIZE)); - hasher.update(m); - hasher.finalize(r); - - const p = [c.gf(), c.gf(), c.gf(), c.gf()]; - const signature = new Uint8Array(CatapultECC.SIGNATURE_SIZE); - c.reduce(r); - c.scalarbase(p, r); - c.pack(signature, p); - - const h = new Uint8Array(CatapultECC.HASH_SIZE); - hasher.reset(); - hasher.update(signature.subarray(0, CatapultECC.HALF_SIGNATURE_SIZE)); - hasher.update(pk); - hasher.update(m); - hasher.finalize(h); - - c.reduce(h); - - // muladd - const x = new Float64Array(CatapultECC.HASH_SIZE); - array.copy(x, r, CatapultECC.HALF_HASH_SIZE); - - for (let i = 0; i < CatapultECC.HALF_HASH_SIZE; ++i) { - for (let j = 0; j < CatapultECC.HALF_HASH_SIZE; ++j) - x[i + j] += h[i] * d[j]; - } - - c.modL(signature.subarray(CatapultECC.HALF_SIGNATURE_SIZE), x); - CatapultECC.encodedSChecker.requireValid(signature.subarray(CatapultECC.HALF_SIGNATURE_SIZE)); - return signature; - } - - public static verify( - pk: Uint8Array, - m: Uint8Array, - signature: Uint8Array, - hasher: HasherInterface - ): boolean { - // reject non canonical signature - if (!CatapultECC.encodedSChecker.isCanonical(signature.subarray(CatapultECC.HALF_SIGNATURE_SIZE))) - return false; - - // reject weak (zero) public key - if (array.isZeroFilled(pk)) - return false; - - const c = nacl_catapult; - const p = [c.gf(), c.gf(), c.gf(), c.gf()]; - const q = [c.gf(), c.gf(), c.gf(), c.gf()]; - - if (c.unpackneg(q, pk)) - return false; - - const h = new Uint8Array(CatapultECC.HASH_SIZE); - hasher.reset(); - hasher.update(signature.subarray(0, CatapultECC.HALF_SIGNATURE_SIZE)); - hasher.update(pk); - hasher.update(m); - hasher.finalize(h); - - c.reduce(h); - c.scalarmult(p, q, h); - - const t = new Uint8Array(CatapultECC.SIGNATURE_SIZE); - c.scalarbase(q, signature.subarray(CatapultECC.HALF_SIGNATURE_SIZE)); - c.add(p, q); - c.pack(t, p); - - return 0 === c.crypto_verify_32(signature, 0, t, 0); - } - - public static deriveSharedKey( - salt: Uint8Array, - sk: Uint8Array, - pk: Uint8Array, - hashfunc: Function, - signSchema: SignSchema = SignSchema.SHA3 - ): Uint8Array { - const c = nacl_catapult; - const d = CatapultECC.prepareForScalarMult(sk, hashfunc, signSchema); - - // sharedKey = pack(p = d (derived from sk) * q (derived from pk)) - const q = [c.gf(), c.gf(), c.gf(), c.gf()]; - const p = [c.gf(), c.gf(), c.gf(), c.gf()]; - const sharedKey = new Uint8Array(CatapultECC.KEY_SIZE); - c.unpackneg(q, pk); - c.scalarmult(p, q, d); - c.pack(sharedKey, p); - - // salt the shared key - for (let i = 0; i < CatapultECC.KEY_SIZE; ++i) - sharedKey[i] ^= salt[i]; - - // return the hash of the result - const sharedKeyHash = new Uint8Array(CatapultECC.KEY_SIZE); - hashfunc(sharedKeyHash, sharedKey, CatapultECC.KEY_SIZE, signSchema); - return sharedKeyHash; - } - - public static keyToUint8( - key: string - ): Uint8Array { - const buffer = Buffer.from(key); - return Uint8Array.from(buffer); - } -} diff --git a/src/Compat/DeterministicKey.ts b/src/Compat/DeterministicKey.ts index 1c063e0..777cad9 100644 --- a/src/Compat/DeterministicKey.ts +++ b/src/Compat/DeterministicKey.ts @@ -22,7 +22,6 @@ const bs58check = require('bs58check'); // internal dependencies import { - CatapultECC, Cryptography, Network, NodeInterface, @@ -124,7 +123,7 @@ export abstract class DeterministicKey implements NodeInterface { * Sign binary data with current node. * * Overloads the `bitcoinjs/bip32` method named `sign` in order to - * be ED25519 compliant and use `CatapultECC` with ed25519 instead + * be ED25519 compliant and use `tweetnacl` with ed25519 instead * of secp256k1. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L277 @@ -140,7 +139,7 @@ export abstract class DeterministicKey implements NodeInterface { * `hash` with the current node. * * Overloads the `bitcoinjs/bip32` method named `verify` in order to - * be ED25519 compliant and use `CatapultECC` with ed25519 instead + * be ED25519 compliant and use `tweetnacl` with ed25519 instead * of secp256k1. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L281 diff --git a/src/Cryptography.ts b/src/Cryptography.ts index 62f4ba2..e3ae018 100644 --- a/src/Cryptography.ts +++ b/src/Cryptography.ts @@ -21,7 +21,6 @@ import { SHA3Hasher as sha3Hasher, - SignSchema } from 'nem2-sdk'; import { kmac256 } from 'js-sha3'; const createHash = require('create-hash'); @@ -96,9 +95,8 @@ export class Cryptography { dest: Uint8Array, data: Uint8Array, length: number = 64, - signSchema: SignSchema = SignSchema.SHA3 ): Uint8Array { - sha3Hasher.func(dest, data, length, signSchema); + sha3Hasher.func(dest, data, length); return dest; } @@ -109,8 +107,7 @@ export class Cryptography { */ public static createSha3Hasher( length: number = 64, - signSchema: SignSchema = SignSchema.SHA3 ): HasherInterface { - return sha3Hasher.createHasher(length, signSchema); + return sha3Hasher.createHasher(length); } } diff --git a/src/CurveAlgorithm.ts b/src/CurveAlgorithm.ts index 5be8d37..3b13001 100644 --- a/src/CurveAlgorithm.ts +++ b/src/CurveAlgorithm.ts @@ -28,5 +28,4 @@ export enum CurveAlgorithm { secp256k1 = 0, ed25519 = 1, - ed25519_keccak = 2, } diff --git a/src/Curves/NodeEd25519.ts b/src/Curves/NodeEd25519.ts index 759fdd4..95c5397 100644 --- a/src/Curves/NodeEd25519.ts +++ b/src/Curves/NodeEd25519.ts @@ -18,13 +18,12 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import * as nacl from 'tweetnacl' const bs58check = require('bs58check'); -import { SignSchema } from 'nem2-sdk'; // internal dependencies import { Cryptography, - CatapultECC, CurveAlgorithm, DeterministicKey, MACType, @@ -102,8 +101,7 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { * * Depending on the curve algorithm, the seed is prepended with one of: * - * - `ed25519-keccak seed` for ed25519-keccak implementation (Network.CATAPULT_PUBLIC) - * - `ed25519 seed` for ed25519[-sha3] implementation (Network.CATAPULT) + * - `ed25519 seed` for ed25519[-sha512] implementation (Network.CATAPULT|Network.CATAPULT_PUBLIC) * * @see https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js#L258 * @param seed {Buffer} @@ -120,9 +118,8 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { if (seed.length > 64) throw new TypeError('Seed should be at most 512 bits'); // (1) depending on curve algorithm, prepend the seed with one of: - // `ed25519-keccak seed` for ed25519-keccak implementation (Network.CATAPULT_PUBLIC) - // `ed25519 seed` for ed25519[-sha3] implementation (Network.CATAPULT) - const prefix = network.curve == CurveAlgorithm.ed25519 ? 'ed25519 seed' : 'ed25519-keccak seed'; + // `ed25519 seed` for ed25519[-sha512] implementation (Network.CATAPULT|Network.CATAPULT_PUBLIC) + const prefix = 'ed25519 seed'; const I = MACImpl.create(macType, Buffer.from(prefix, 'utf8'), seed); // (2) Split in 2 parts: privateKey and chainCode @@ -229,14 +226,9 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { return this.getQ()!; } - // if the publicKey is not set, derive from private key - const extract = CatapultECC.extractPublicKey( - (this.privateKey as Buffer), - Cryptography.sha3Hash, - Network.resolveSignSchema(this.network) - ); - - return Buffer.from(extract); + // use tweetnacl to generate key pair (SHA512) + const keyPair = nacl.sign.keyPair.fromSeed(this.privateKey as Buffer); + return Buffer.from(keyPair.publicKey) } /** @@ -368,22 +360,27 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { * Sign binary data with current node. * * Overloads the `bitcoinjs/bip32` method named `sign` in order to - * be ED25519 compliant and use `CatapultECC` with ed25519 instead + * be ED25519 compliant and use `tweetnacl` with ed25519 instead * of secp256k1. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L277 * @param hash {Buffer} The binary data to sign. - * @param length {number} (Optional) The byte size of the produced SHA3 hash, defaults to 64 * @return {NodeInterface} */ public sign( hash: Buffer ): Buffer { - const secretKey = this.privateKey as Buffer; - const hasher = Cryptography.createSha3Hasher(64); // 64=size - const signature = CatapultECC.sign(hash, this.publicKey, secretKey, hasher); + // use tweetnacl to generate key pair (SHA512) + const keyPair = nacl.sign.keyPair.fromSeed(this.privateKey as Buffer); + + // generate shared secret + const secretKey = new Uint8Array(64); + secretKey.set(this.privateKey); + secretKey.set(keyPair.publicKey, 32); - return Buffer.from(signature); + // use tweetnacl to sign + const signature = nacl.sign.detached(hash, secretKey); + return Buffer.from(signature) } /** @@ -391,7 +388,7 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { * `hash` with the current node. * * Overloads the `bitcoinjs/bip32` method named `verify` in order to - * be ED25519 compliant and use `CatapultECC` with ed25519 instead + * be ED25519 compliant and use `tweetnacl` with ed25519 instead * of secp256k1. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L281 @@ -403,9 +400,8 @@ export class NodeEd25519 extends DeterministicKey implements NodeInterface { hash: Buffer, signature: Buffer ): boolean { - const length = signature.byteLength === 32 ? 32 : 64; - const hasher = Cryptography.createSha3Hasher(length); - return CatapultECC.verify(hash, this.publicKey, signature, hasher); + // use tweetnacl to verify signature + return nacl.sign.detached.verify(hash, signature, this.publicKey); } /** diff --git a/src/Network.ts b/src/Network.ts index 9b69cdd..11f9407 100644 --- a/src/Network.ts +++ b/src/Network.ts @@ -18,8 +18,6 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import { SignSchema } from 'nem2-sdk'; - // internal dependencies import { CurveAlgorithm, @@ -81,7 +79,7 @@ export class Network { public static readonly CATAPULT_PUBLIC: Network = new Network( 0x0488b21e, // base58 'xpub' 0x0488ade4, // base58 'xprv' - CurveAlgorithm.ed25519_keccak + CurveAlgorithm.ed25519 ); /** @@ -109,28 +107,6 @@ export class Network { } - /** - * Resolve the signature schema that must be used. This method is only - * relevant for Catapult key derivation and will/must not affect BITCOIN - * key derivation. - * - * In case of a `curve` field set to `CurveAlgorithm.ed25519_keccak`, the - * underlying SHA3 hasher should use Keccak ; This is to be compatible with - * Catapult public network implementations. - * - * @param network {Network} The network object to interpret - * @return {SignSchema} Returns the signature schema needed. - */ - public static resolveSignSchema( - network: Network - ): SignSchema { - if (network.curve === CurveAlgorithm.ed25519_keccak) { - return SignSchema.KECCAK; - } - - return SignSchema.SHA3; - } - /** * Checks whether current network instance **is identical** * to given `b` network instance. diff --git a/src/Wallet.ts b/src/Wallet.ts index 221adf2..ec7cb33 100644 --- a/src/Wallet.ts +++ b/src/Wallet.ts @@ -239,10 +239,6 @@ export class Wallet { * Checks whether said `networkType` network type can be used * to derive an (child) account or not. * - * Extended Keys for `Network.CATAPULT` and `Network.CATAPULT_PUBLIC` - * networks are different because the first uses SHA3 and the latter - * uses Keccak (NIS compatibility). - * * @param networkType {NetworkType} The network type to test. */ protected canDeriveForNetworkType(networkType: NetworkType): boolean { diff --git a/test/CatapultECC.spec.ts b/test/CatapultECC.spec.ts deleted file mode 100644 index 07c8946..0000000 --- a/test/CatapultECC.spec.ts +++ /dev/null @@ -1,278 +0,0 @@ -/** - * Copyright 2019 NEM - * - * Licensed under the BSD 2-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-2-Clause - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -import {expect} from "chai"; -import {Convert, Crypto, SignSchema} from 'nem2-sdk'; - -// internal dependencies -import { - CatapultECC, - Cryptography, -} from "../index"; - -describe('CatapultECC -->', () => { - - const Private_Keys = [ - '8D31B712AB28D49591EAF5066E9E967B44507FC19C3D54D742F7B3A255CFF4AB', - '15923F9D2FFFB11D771818E1F7D7DDCD363913933264D58533CB3A5DD2DAA66A', - 'A9323CEF24497AB770516EA572A0A2645EE2D5A75BC72E78DE534C0A03BC328E', - 'D7D816DA0566878EE739EDE2131CD64201BCCC27F88FA51BA5815BCB0FE33CC8', - '27FC9998454848B987FAD89296558A34DEED4358D1517B953572F3E0AAA0A22D' - ]; - - describe('sign() should', () => { - it('fill the signature', () => { - - // Arrange: - const privateKey = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey = CatapultECC.extractPublicKey(privateKey, Cryptography.sha3Hash); - const payload = Crypto.randomBytes(100); - - // Act: - const signature = CatapultECC.sign(payload, publicKey, privateKey, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(signature).to.not.deep.equal(new Uint8Array(CatapultECC.SIGNATURE_SIZE)); - }); - - it('return same signature for same data signed by same key pairs', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const privateKey_2 = CatapultECC.keyToUint8(Private_Keys[0]); // SAME - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const publicKey_2 = CatapultECC.extractPublicKey(privateKey_2, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - - // Act: - const signature1 = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - const signature2 = CatapultECC.sign(payload, publicKey_2, privateKey_2, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(signature2).to.deep.equal(signature1); - }); - - it('return different signature for same data signed by different key pairs', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const privateKey_2 = CatapultECC.keyToUint8(Private_Keys[1]); // DIFFERENT - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const publicKey_2 = CatapultECC.extractPublicKey(privateKey_2, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - - // Act: - const signature1 = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - const signature2 = CatapultECC.sign(payload, publicKey_2, privateKey_2, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(signature2).to.not.deep.equal(signature1); - }); - - it('not allow signing unsupported data type', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - - // Assert: - expect(() => { - CatapultECC.sign({} as Uint8Array, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - }).to.throw('unsupported data type'); - }); - }); - - describe('verify() should', () => { - it('return true for data signed with same key pair', () => { - // Arrange: - const privateKey = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey = CatapultECC.extractPublicKey(privateKey, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - const signature = CatapultECC.sign(payload, publicKey, privateKey, Cryptography.createSha3Hasher(64)); - - // Act: - const isVerified = CatapultECC.verify(publicKey, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified).to.equal(true); - }); - - it('returns false for data signed with different key pair', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const privateKey_2 = CatapultECC.keyToUint8(Private_Keys[1]); // DIFFERENT - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const publicKey_2 = CatapultECC.extractPublicKey(privateKey_2, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - - // Act: - const isVerified = CatapultECC.verify(publicKey_2, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified).to.equal(false); - }); - - it('returns false if signature has been modified', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - - for (let i = 0; i < CatapultECC.SIGNATURE_SIZE; i += 4) { - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - signature[i] ^= 0xFF; - - // Act: - const isVerified = CatapultECC.verify(publicKey_1, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified, `signature modified at ${i}`).to.equal(false); - } - }); - - it('returns false if payload has been modified', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(44); - - for (let i = 0; i < payload.length; i += 4) { - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - payload[i] ^= 0xFF; - - // Act: - const isVerified = CatapultECC.verify(publicKey_1, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified, `payload modified at ${i}`).to.equal(false); - } - }); - - it('fails if public key is not on curve', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - publicKey_1.fill(0); - publicKey_1[publicKey_1.length - 1] = 1; - - const payload = Crypto.randomBytes(100); - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - - // Act: - const isVerified = CatapultECC.verify(publicKey_1, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified).to.equal(false); - }); - - it('fails if public key does not correspond to private key', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = Crypto.randomBytes(100); - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - - for (let i = 0; i < publicKey_1.length; ++i) - publicKey_1[i] ^= 0xFF; - - // Act: - const isVerified = CatapultECC.verify(publicKey_1, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified).to.equal(false); - }); - - it('rejects zero public key', () => { - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - publicKey_1.fill(0); - - const payload = Crypto.randomBytes(100); - const signature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - - // Act: - const isVerified = CatapultECC.verify(publicKey_1, payload, signature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isVerified).to.equal(false); - }); - - it('cannot verify non canonical signature', () => { - function scalarAddGroupOrder(scalar: Uint8Array) { - // 2^252 + 27742317777372353535851937790883648493, little endian - const Group_Order = [ - 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 - ]; - - let r = 0; - for (let i = 0; i < scalar.length; ++i) { - const t = scalar[i] + Group_Order[i]; - scalar[i] += Group_Order[i] + r; - r = (t >> 8) & 0xFF; - } - } - - // Arrange: - const privateKey_1 = CatapultECC.keyToUint8(Private_Keys[0]); - const publicKey_1 = CatapultECC.extractPublicKey(privateKey_1, Cryptography.sha3Hash, SignSchema.SHA3); - const payload = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); - const canonicalSignature = CatapultECC.sign(payload, publicKey_1, privateKey_1, Cryptography.createSha3Hasher(64)); - - // this is signature with group order added to 'encodedS' part of signature - const nonCanonicalSignature = canonicalSignature.slice(); - scalarAddGroupOrder(nonCanonicalSignature.subarray(32)); - - // Act: - const isCanonicalVerified = CatapultECC.verify(publicKey_1, payload, canonicalSignature, Cryptography.createSha3Hasher(64)); - const isNonCanonicalVerified = CatapultECC.verify(publicKey_1, payload, nonCanonicalSignature, Cryptography.createSha3Hasher(64)); - - // Assert: - expect(isCanonicalVerified).to.equal(true); - expect(isNonCanonicalVerified).to.equal(false); - }); - }); - - describe('extractPublicKey() should', () => { - it('extract correct public key from private key with SignSchema.SHA3', () => { - const privateKey = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPublicKey = 'BD8D3F8B7E1B3839C650F458234AB1FF87CDB1EDA36338D9E446E27D454717F2'.toLowerCase(); - - const extract = CatapultECC.extractPublicKey( - Buffer.from(Convert.hexToUint8(privateKey)), - Cryptography.sha3Hash, - SignSchema.SHA3, - ); - - expect(Buffer.from(extract).toString('hex')).to.equal(expectPublicKey); - }); - it('extract correct public key from private key with SignSchema.KECCAK', () => { - const privateKey = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPublicKey = 'c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844'; - - const extract = CatapultECC.extractPublicKey( - Buffer.from(Convert.hexToUint8Reverse(privateKey)), // REVERSE - Cryptography.sha3Hash, - SignSchema.KECCAK, - ); - - expect(Buffer.from(extract).toString('hex')).to.equal(expectPublicKey); - }); - }); -}); diff --git a/test/DerivationEd25519.spec.ts b/test/DerivationEd25519.spec.ts index 265d5f4..b9ed69d 100644 --- a/test/DerivationEd25519.spec.ts +++ b/test/DerivationEd25519.spec.ts @@ -50,45 +50,33 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors const extendedKeys = [ // Test vector 1: https://github.com/satoshilabs/slips/blob/master/slip-0010.md#test-vector-1-for-ed25519 - // Catapult neutered nodes are different from SLIP-10 because of SHA3-256 usage. - // Extended Private Keys (nonNeutered nodes) are copied from SLIP-10 but Public Keys - // in SLIP-10 are generated with SHA512 while for Catapult we use SHA3-256 { label: 'Vector #1', seedHex: '000102030405060708090a0b0c0d0e0f', chainCode: '90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb', masterPub: 'a4b2856bfec510abab89753fac1ac0e1112364e7d250545963f135f2a33188ed', masterPrv: '2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7', - catapultPub: '398d57dda0faae646097435e648a2c10f0f367b67e9a1e99a3d9170948d85750', - // Catapult neutered nodes are different from SLIP-10 because of SHA3-256 usage. neutered: [ {path: 'm/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'b133c1d14999199ddefb03e815072f6fb14f1c22b201dab15f3373da8e26b17f', + key: '8c8a13df77a28f3445213a0f432fde644acaa215fc72dcdf300d5efaa85d350c', chain: '8b59aa11380b624e81507a27fedda59fea6d0b779a778918a2fd3590e16e9c69'}, {path: 'm/0\'/1\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'b4f591ac319f122425eaf5eb25f8d2b729d4009c59e56eebb54e697328f07fea', + key: '1932a5270f335bed617d5b935c80aedb1a35bd9fc1e31acafd5372c30f5c1187', chain: 'a320425f77d1b5c2505a6b1b27382b37368ee640e3557c315416801243552f14'}, {path: 'm/0\'/1\'/2\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'e51e8260001a2788cbf3e9dd89d21cef34080670c2b182236f85ee48cdabfec1', + key: 'ae98736566d30ed0e9d2f4486a64bc95740d89c7db33f52121f8ea8f76ff0fc1', chain: '2e69929e00b5ab250f49c3fb1c12f252de4fed2c1db88387094a0f8c4c9ccd6c'}, {path: 'm/0\'/1\'/2\'/2\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '3a14558899d4ebcc220afff7012f690e9f625006686b4eef3f1d7125e3e87222', + key: '8abae2d66361c879b900d204ad2cc4984fa2aa344dd7ddc46007329ac76c429c', chain: '8f6d87f93d750e0efccda017d662a1b31a266e4a6f5993b15f5c1f07f74dd5cc'}, {path: 'm/0\'/1\'/2\'/2\'/1000000000\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'c53618757b76cc34376b7464902b18e495651c69f47cd2e7a2910d401fba2f94', + key: '3c24da049451555d51a7014a37337aa4e12d41e485abccfa46b47dfb2af54b7a', chain: '68789923a0cac2cd5a29172a475fe9e0fb14cd6adb5ad98a3fa70333e7afa230'}, {path: 'm/44\'/43\'/0\'/0\'/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '81357c2d65be8b12aa2506fc315b6e1e2b6ab847727d460c3c7d13755ab62395', + key: '2daecee59b39e0e1095005162cf2879c30a21c1868f0474eba02d41bd1d0f969', chain: 'c428a9ed5355167f312292c4e4ef3aae680145009197c4f6b23bfeed0780643e'}, {path: 'm/44\'/43\'/1\'/0\'/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'af0868a6edcc3e768854fae2e3534bed3cce222893b16fdc5d780f82cd8990dd', + key: '0ad5eb7d7c2d0f0e673651732d415b54333adb8a5a67fbce7b07852b355d457a', chain: '5619e49ec9c210ac75e89000e9c3266a388ae913615449790c4cbefff990b00e'}, ], nonNeutered: [ @@ -108,11 +96,9 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { key: '8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793', chain: '68789923a0cac2cd5a29172a475fe9e0fb14cd6adb5ad98a3fa70333e7afa230'}, {path: 'm/44\'/43\'/0\'/0\'/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) key: '4ce1c399f5f72acf16e7231a406f6e8284033f686d565100fed376960ea8c871', chain: 'c428a9ed5355167f312292c4e4ef3aae680145009197c4f6b23bfeed0780643e'}, {path: 'm/44\'/43\'/1\'/0\'/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) key: '1b05cb9db696df7216bd6a551c0e2b441234a59b23d785f4c803a41d64ce4d69', chain: '5619e49ec9c210ac75e89000e9c3266a388ae913615449790c4cbefff990b00e'}, ], @@ -124,27 +110,21 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { chainCode: 'ef70a74db9c3a5af931b5fe73ed8e1a53464133654fd55e7a66f8570b8e33c3b', masterPub: '8fe9693f8fa62a4305a140b9764c5ee01e455963744fe18204b4fb948249308a', masterPrv: '171cb88b1b3c1db25add599712e36245d75bc65a1a5c9e18d76f9f2b1eab4012', - catapultPub: '8d806491b531735af494d211d801cc87c0c66703634a016cd1e3dd188b4ca1e6', neutered: [ {path: 'm/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '5e2d0e53f031fc783a664ab03a7e0c6e980e87c515b968590eff09eb34de6db3', + key: '86fab68dcb57aa196c77c5f264f215a112c22a912c10d123b0d03c3c28ef1037', chain: '0b78a3226f915c082bf118f83618a618ab6dec793752624cbeb622acb562862d'}, {path: 'm/0\'/2147483647\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '4fd948675902bf11678bda28ba3faec9798bedfd8c8d702652d5a5e6ea73c8b2', + key: '5ba3b9ac6e90e83effcd25ac4e58a1365a9e35a3d3ae5eb07b9e4d90bcf7506d', chain: '138f0b2551bcafeca6ff2aa88ba8ed0ed8de070841f0c4ef0165df8181eaad7f'}, {path: 'm/0\'/2147483647\'/1\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '8a326dd01e22229d043434140982b1f538332ae4e745b15f0b359501c2b9bb9a', + key: '2e66aa57069c86cc18249aecf5cb5a9cebbfd6fadeab056254763874a9352b45', chain: '73bd9fff1cfbde33a1b846c27085f711c0fe2d66fd32e139d3ebc28e5a4a6b90'}, {path: 'm/0\'/2147483647\'/1\'/2147483646\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'd774ca736001d91d8048e102702ffe32b306d43103dfb54df7d3869a0d1cc3b7', + key: 'e33c0f7d81d843c572275f287498e8d408654fdf0d1e065b84e2e6f157aab09b', chain: '0902fe8a29f9140480a00ef244bd183e8a13288e4412d8389d140aac1794825a'}, {path: 'm/0\'/2147483647\'/1\'/2147483646\'/2\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'f3fd8f892731eda80e8c21f2b4167ea8b9b59bda85101f8595f78041cde1d303', + key: '47150c75db263559a70d5778bf36abbab30fb061ad69f69ece61a72b0cfa4fc0', chain: '5d70af781f3a37b829f0d060924d5e960bdc02e85423494afc0b1a41bbe196d4'}, ], nonNeutered: [ @@ -180,7 +160,7 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { }); it (extendedKey.label + ': create correct master extended public key', () => { - expect(masterKey.getPublicKey()).to.be.equal(extendedKey.catapultPub); + expect(masterKey.getPublicKey()).to.be.equal(extendedKey.masterPub); }); it(extendedKey.label + ': derive correct extended public key given seed (' + (extendedKey.seedHex.length/2) + ' bytes) and paths', () => { @@ -217,7 +197,7 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { describe('NodeEd25519 should', () => { it('forward network property in CKDPriv (derivePath) and derive correct public key with SHA3', () => { const privateKey = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPublicKey = 'BD8D3F8B7E1B3839C650F458234AB1FF87CDB1EDA36338D9E446E27D454717F2'.toLowerCase(); + const expectPublicKey = '2e834140fd66cf87b254a693a2c7862c819217b676d3943267156625e816ec6f'; const privateBytes = Convert.hexToUint8(privateKey); const node = new NodeEd25519(Buffer.from(privateBytes), undefined, Buffer.from(''), Network.CATAPULT); @@ -225,29 +205,9 @@ describe('BIP32-Ed15519 Extended Keys -->', () => { expect(node.publicKey.toString('hex')).to.equal(expectPublicKey); }); - it('forward network property in CKDPriv (derivePath) and derive correct public key with KECCAK', () => { + it('forward network property in CKDPriv (derivePath) and derive correct public key with REVERSED private key', () => { const privateKey = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPublicKey = 'd6c3845431236c5a5a907a9e45bd60da0e12efd350b970e7f58e3499e2e7a2f0'; - - const privateBytes = Convert.hexToUint8(privateKey); - const node = new NodeEd25519(Buffer.from(privateBytes), undefined, Buffer.from(''), Network.CATAPULT_PUBLIC); - - expect(node.publicKey.toString('hex')).to.equal(expectPublicKey); - }); - - it('forward network property in CKDPriv (derivePath) and derive correct public key with KECCAK and trezor private key', () => { - const privateKey = '52019c4235e2a7e1473b9ccacdf8e3ce7053388ab00bd316cd8614535b9e341e'; - const expectPublicKey = 'a8f70e4d5c357273968b12417ae8b742e35e530623c2488d0a73306b41271500'; - - const privateBytes = Convert.hexToUint8(privateKey); - const node = new NodeEd25519(Buffer.from(privateBytes), undefined, Buffer.from(''), Network.CATAPULT_PUBLIC); - - expect(node.publicKey.toString('hex')).to.equal(expectPublicKey); - }); - - it('forward network property in CKDPriv (derivePath) and derive correct public key with KECCAK and REVERSED private key', () => { - const privateKey = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPublicKey = 'c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844'; + const expectPublicKey = '5112ba143b78132af616af1a94e911ead890fdb51b164a1b57c352ecd9ca1894'; // REVERSED private key (NIS) const privateBytes = Convert.hexToUint8Reverse(privateKey); diff --git a/test/DerivationKMAC.spec.ts b/test/DerivationKMAC.spec.ts index b300858..0b13993 100644 --- a/test/DerivationKMAC.spec.ts +++ b/test/DerivationKMAC.spec.ts @@ -46,15 +46,13 @@ describe('BIP32-Ed15519 KMAC derivation -->', () => { const HMAC = { chainCode: '90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb', masterPrv: '2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7', - masterPub: '398d57dda0faae646097435e648a2c10f0f367b67e9a1e99a3d9170948d85750', + masterPub: 'a4b2856bfec510abab89753fac1ac0e1112364e7d250545963f135f2a33188ed', neutered: [ {path: 'm/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'b133c1d14999199ddefb03e815072f6fb14f1c22b201dab15f3373da8e26b17f', + key: '8c8a13df77a28f3445213a0f432fde644acaa215fc72dcdf300d5efaa85d350c', chain: '8b59aa11380b624e81507a27fedda59fea6d0b779a778918a2fd3590e16e9c69'}, {path: 'm/0\'/1\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: 'b4f591ac319f122425eaf5eb25f8d2b729d4009c59e56eebb54e697328f07fea', + key: '1932a5270f335bed617d5b935c80aedb1a35bd9fc1e31acafd5372c30f5c1187', chain: 'a320425f77d1b5c2505a6b1b27382b37368ee640e3557c315416801243552f14'} ], nonNeutered: [ @@ -70,15 +68,13 @@ describe('BIP32-Ed15519 KMAC derivation -->', () => { const KMAC = { chainCode: '0589895ba87aa5d28d6e5d9d94f3323d22414ce3c91d5c63a223e1b045b0549f', masterPrv: '8297bf032455d6b42e544cbe3d4861a28c94a75071905c516a1a16ef17ecac5c', - masterPub: 'aa16cb5de7b47df9eb805715d871c4ad9d346fa89b5874aa19a7765b681052dd', + masterPub: 'fef030d292cf1bd09258109b836763ad447c3061f95c0e8af37737c6f5635ba0', neutered: [ {path: 'm/0\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '6d282315ad30a08184f01ec1fa3453f814155b151c09c31de4853ec69d47df40', + key: 'b464e285d624970a10e48ae91e0e3f8da84a77b856e7b631f8401f6a739b190b', chain: '1d615993bde463a451d6553f4deac7488a54062a0aebe09ecc35c3d01d47d08a'}, {path: 'm/0\'/1\'', - // Ed25519-compliant SHA3-256 instead of SHA512!! (different from SLIP-10) - key: '888b147936663c7eca406450f69951f190c7c4ca19dede9f5a8493843119c3ab', + key: '3497dcad20d3fa850754cce887e9d2bd1912644d02103a10d5fe3103801a36be', chain: 'a408fef3c6fd2aac83bbdd6b48eb865dc844793be117a90b86be215d2c163127'} ], nonNeutered: [ diff --git a/test/ExtendedKey.spec.ts b/test/ExtendedKey.spec.ts index d889793..5718e54 100644 --- a/test/ExtendedKey.spec.ts +++ b/test/ExtendedKey.spec.ts @@ -97,8 +97,8 @@ describe('ExtendedKey -->', () => { const nodeEd25519 = neuteredMaster.node as NodeEd25519; expect(nodeEd25519).to.be.instanceof(NodeEd25519); - expect(neuteredMaster.network.curve).to.be.equal(CurveAlgorithm.ed25519_keccak); - expect(nodeEd25519.network.curve).to.be.equal(CurveAlgorithm.ed25519_keccak); + expect(neuteredMaster.network.curve).to.be.equal(CurveAlgorithm.ed25519); + expect(nodeEd25519.network.curve).to.be.equal(CurveAlgorithm.ed25519); }); it('create master key with payload for "m" path', () => { @@ -163,7 +163,7 @@ describe('ExtendedKey -->', () => { // check that Network.CATAPULT was used correctly expect(neuteredNode.network.privateKeyPrefix).to.be.equal(Network.CATAPULT_PUBLIC.privateKeyPrefix); expect(neuteredNode.network.publicKeyPrefix).to.be.equal(Network.CATAPULT_PUBLIC.publicKeyPrefix); - expect(neuteredNode.network.curve).to.be.equal(CurveAlgorithm.ed25519_keccak); + expect(neuteredNode.network.curve).to.be.equal(CurveAlgorithm.ed25519); // also check node implementation that was used expect(neuteredNode.node).to.be.instanceof(NodeEd25519); @@ -217,7 +217,7 @@ describe('ExtendedKey -->', () => { // check that Network.CATAPULT was used correctly expect(masterFromSeed.network.privateKeyPrefix).to.be.equal(Network.CATAPULT_PUBLIC.privateKeyPrefix); expect(masterFromSeed.network.publicKeyPrefix).to.be.equal(Network.CATAPULT_PUBLIC.publicKeyPrefix); - expect(masterFromSeed.network.curve).to.be.equal(CurveAlgorithm.ed25519_keccak); + expect(masterFromSeed.network.curve).to.be.equal(CurveAlgorithm.ed25519); // also check node implementation that was used expect(masterFromSeed.node).to.be.instanceof(NodeEd25519); @@ -346,9 +346,44 @@ describe('ExtendedKey -->', () => { expect(Array.from(uintArray)).to.be.deep.equal(expectedBytes); }); - it('produce SHA3 public key given Network.CATAPULT', () => { + // http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=blob;f=tests/t-ed25519.inp + // - extracted vectors: #1, #2, #3, #166, #218, #219. #220, #337, #500, #501 + const vectorED25519 = [ + {sk: '9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60', + pk: 'd75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a'}, + {sk: '4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb', + pk: '3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c'}, + {sk: 'c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7', + pk: 'fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025'}, + {sk: '3558d3a74395bdcba560e2c45a91960cec6cb3edbcd30e722f7f055210f37b51', + pk: '534f43eba403a84f25967c152d93a0175ec8293e6f4375319eadf957401fbbd2'}, + {sk: 'bfbcd867027a199978d53e359d70318fc78c7cc7bb5c7996ba797c8554f3f0f0', + pk: '7c5ae3bab9201199dfbe74b7d1ec157125bdbaa4520f501da3f248579dc6c22d'}, + {sk: 'df2df8a9d66d5638cdee09324e7b10f8ed29ab91387e3147b7dc03f7cd800508', + pk: '5c042e157fb7fb12d4d4fef2847141ecfb57c1253e14eaf3004d6513f52fe625'}, + {sk: 'e8ee065f9907f1efa2daecb23a0425f353094da02bc2c931f0a587efc0d13de1', + pk: 'c72651b7fb7ac0337a172977496fd7f2a72aea889385835e563c6b6053a32dc1'}, + {sk: 'c57a43dcd7bab8516009546918d71ad459b7345efdca8d4f19929875c839d722', + pk: '2083b444236b9ab31d4e00c89d55c6260fee71ac1a47c4b5ba227404d382b82d'}, + {sk: 'afcecea92439e44a43ed61b673043dcbc4e360f2f30cd07896cda20cb988d4e3', + pk: 'd231f69235a2e3a1dd5f6c2a9aaf20c03454b9a29f4e3a29ab94689d0d723e50'}, + {sk: 'b834c6e0facbff580dd3b23753959a4c2154c219521b3d27035d071f6599bd02', + pk: 'd1c384715e3b3d02c13e090605534c7db740da2aa560f53200a3ced8beae8cf8'}, + ] + it('produce SHA512 ED25519 compliant public key', () => { + // http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=blob;f=tests/t-ed25519.inp + vectorED25519.map(vec => { + const privateKey = Buffer.from(Convert.hexToUint8(vec.sk)); + const bip32Node = new NodeEd25519(privateKey, undefined, Buffer.from(''), Network.CATAPULT); + + expect(bip32Node.privateKey.toString('hex')).to.be.equal(vec.sk); + expect(bip32Node.publicKey.toString('hex')).to.be.equal(vec.pk); + }) + }) + + it('produce SHA512 public key given Network.CATAPULT', () => { const privateHex = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPub = 'BD8D3F8B7E1B3839C650F458234AB1FF87CDB1EDA36338D9E446E27D454717F2'.toLowerCase(); + const expectPub = '2e834140fd66cf87b254a693a2c7862c819217b676d3943267156625e816ec6f'; const privateKey = Buffer.from(Convert.hexToUint8(privateHex)); const bip32Node = new NodeEd25519(privateKey, undefined, Buffer.from(''), Network.CATAPULT); @@ -356,20 +391,9 @@ describe('ExtendedKey -->', () => { expect(bip32Node.publicKey.toString('hex')).to.be.equal(expectPub); }); - it('produce correct KECCAK public key given Network.CATAPULT_PUBLIC and private key', () => { - const privateHex = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPub = 'd6c3845431236c5a5a907a9e45bd60da0e12efd350b970e7f58e3499e2e7a2f0'; - - const privateKey = Buffer.from(Convert.hexToUint8(privateHex)); - const bip32Node = new NodeEd25519(privateKey, undefined, Buffer.from(''), Network.CATAPULT_PUBLIC); - - expect(bip32Node.privateKey.toString('hex')).to.be.equal(privateKey.toString('hex')); - expect(bip32Node.publicKey.toString('hex')).to.be.equal(expectPub); - }); - - it('produce correct KECCAK public key given Network.CATAPULT_PUBLIC and REVERSED private key', () => { + it('produce correct SHA512 public key given REVERSED private key', () => { const privateHex = '575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced'; - const expectPub = 'c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844'; + const expectPub = '5112ba143b78132af616af1a94e911ead890fdb51b164a1b57c352ecd9ca1894'; // NIS compatibility requires "key reversal". const reversedKey = Buffer.from(Convert.hexToUint8Reverse(privateHex)); diff --git a/test/Network.spec.ts b/test/Network.spec.ts index b4a90a4..1089291 100644 --- a/test/Network.spec.ts +++ b/test/Network.spec.ts @@ -19,7 +19,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import {expect} from "chai"; -import {SignSchema} from "nem2-sdk" // internal dependencies import { @@ -44,38 +43,24 @@ describe('Network -->', () => { it('set correct curve algorithm', () => { const network1 = new Network(1, 2, CurveAlgorithm.secp256k1) const network2 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) - const network3 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519_keccak) + const network3 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) expect(network1.curve).to.be.equal(CurveAlgorithm.secp256k1) expect(network2.curve).to.be.equal(CurveAlgorithm.ed25519) - expect(network3.curve).to.be.equal(CurveAlgorithm.ed25519_keccak) - }); - }); - - describe('resolveSignSchema() should', () => { - - it('set correct signature schema Keccak given curve ed25519-keccak', () => { - const network = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519_keccak) - expect(Network.resolveSignSchema(network)).to.be.equal(SignSchema.KECCAK) - }); - - it('set correct signature schema SHA3 given curve ed25519', () => { - const network = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) - expect(Network.resolveSignSchema(network)).to.be.equal(SignSchema.SHA3) + expect(network3.curve).to.be.equal(CurveAlgorithm.ed25519) }); }); describe('equals() should', () => { - it('return false given non-identical object', () => { - const network1 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519_keccak) - const network2 = new Network(1, 2, CurveAlgorithm.ed25519_keccak) + const network1 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) + const network2 = new Network(1, 2, CurveAlgorithm.ed25519) expect(network1.equals(network2)).to.be.equal(false) }); - it('return true given non-identical object', () => { - const network1 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519_keccak) - const network2 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519_keccak) + it('return true given identical object', () => { + const network1 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) + const network2 = new Network(0x0488b21e, 0x0488ade4, CurveAlgorithm.ed25519) expect(network1.equals(network2)).to.be.equal(true) }); }); diff --git a/test/Wallet.spec.ts b/test/Wallet.spec.ts index 3cbb2a7..dec0ba7 100644 --- a/test/Wallet.spec.ts +++ b/test/Wallet.spec.ts @@ -43,15 +43,15 @@ describe('Wallet -->', () => { // m const masterPriv = '2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7'; - const masterPub = '398d57dda0faae646097435e648a2c10f0f367b67e9a1e99a3d9170948d85750'; + const masterPub = 'a4b2856bfec510abab89753fac1ac0e1112364e7d250545963f135f2a33188ed'; // m/44'/43'/0'/0'/0' const defaultPriv = '4ce1c399f5f72acf16e7231a406f6e8284033f686d565100fed376960ea8c871'; - const defaultPub = '81357c2d65be8b12aa2506fc315b6e1e2b6ab847727d460c3c7d13755ab62395'; + const defaultPub = '2daecee59b39e0e1095005162cf2879c30a21c1868f0474eba02d41bd1d0f969'; // m/44'/43'/1'/0'/0' const secondPriv = '1b05cb9db696df7216bd6a551c0e2b441234a59b23d785f4c803a41d64ce4d69'; - const secondPub = 'af0868a6edcc3e768854fae2e3534bed3cce222893b16fdc5d780f82cd8990dd'; + const secondPub = '0ad5eb7d7c2d0f0e673651732d415b54333adb8a5a67fbce7b07852b355d457a'; describe('constructor should', () => { From 91da32c2136b36d2ee25c77e5c29bd70119c5e29 Mon Sep 17 00:00:00 2001 From: Greg S Date: Thu, 20 Feb 2020 16:34:54 +0100 Subject: [PATCH 2/2] update CHANGELOG and add tweetnacl dependency --- CHANGELOG.md | 9 +++++++++ package-lock.json | 20 +++++++++++++++++--- package.json | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d400d8d..595f61b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +# v0.8.0 + +- upgrade upstream nem2-sdk@v0.17.0 +- dropped KECCAK/SHA3 key derivation for SHA512 +- added compatibility with SLIP-10 key derivation +- dropped SHA3/KECCAK derivation dependent on Network sign schema +- dropped usage of SignSchema +- dropped class CatapultECC in favor of `tweetnacl` + # v0.7.0 - upgraded upstream nem2-sdk@v0.16.0 diff --git a/package-lock.json b/package-lock.json index fe034ad..f2cce11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -533,6 +533,13 @@ "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "requires": { "tweetnacl": "^0.14.3" + }, + "dependencies": { + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + } } }, "bindings": { @@ -2506,6 +2513,13 @@ "jsbn": "~0.1.0", "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" + }, + "dependencies": { + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + } } }, "stealthy-require": { @@ -2644,9 +2658,9 @@ } }, "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, "type-detect": { "version": "4.0.8", diff --git a/package.json b/package.json index fe27ab0..f272424 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "js-sha3": "^0.8.0", "nem2-sdk": "^0.17.0", "rxjs": "^6.5.4", - "tiny-secp256k1": "^1.1.3" + "tiny-secp256k1": "^1.1.3", + "tweetnacl": "^1.0.3" }, "devDependencies": { "@types/chai": "^4.2.9",