From 6b15627d34bf45e7be3571ffc6ed5ce8a26029c9 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Tue, 14 Sep 2021 16:52:46 +0200 Subject: [PATCH] Update keystore-idb (#286) * Update keystore-idb * Add changelog entry * Update to new stable keystore-idb --- CHANGELOG.md | 2 ++ package.json | 7 +++--- src/common/version.ts | 2 +- src/crypto/browser.ts | 6 ++--- src/crypto/index.ts | 8 +++---- src/did/local.ts | 2 +- src/setup/dependencies.ts | 8 +++---- src/setup/node.ts | 28 ++++++++++++------------ yarn.lock | 46 +++++++++++++++++++++++++-------------- 9 files changed, 63 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 937814165..f7f56468a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Added the `fs.addPublicExchangeKey()` function which adds the public exchange key of that domain/browser/device to your filesystem at `/public/.well-known/exchange/DID_KEY`. Along with the `fs.hasPublicExchangeKey()` to check if it's there. - Made the login low more resilient. Should work better with extensions triggering `postMessage`s now. +- Updated keystore-idb to v0.15.0, which renamed `publicReadKey()` to `publicExchangeKey()` (among other functions). The read key-pair is now properly named the exchange key-pair. + ### v0.27.0 diff --git a/package.json b/package.json index 0ffa1ce74..63531c679 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webnative", - "version": "0.27.1", + "version": "0.28.0", "description": "Fission Webnative SDK", "keywords": [ "WebCrypto", @@ -64,7 +64,7 @@ "publish-latest": "npm publish --tag latest" }, "devDependencies": { - "@ipld/car": "^3.1.8", + "@ipld/car": "^3.1.16", "@types/expect": "^24.3.0", "@types/mocha": "^9.0.0", "@types/node": "^16.4.1", @@ -96,8 +96,9 @@ "ipfs-message-port-client": "https://ipfs.runfission.com/ipfs/bafybeigx6q4aezve7my76s5vvfuiinbxtepapqvmjf2jbgrozrut6cjape/p/ipfs-message-port-client.tar.gz", "ipfs-message-port-protocol": "https://ipfs.runfission.com/ipfs/bafybeigx6q4aezve7my76s5vvfuiinbxtepapqvmjf2jbgrozrut6cjape/p/ipfs-message-port-protocol.tar.gz", "ipld-dag-pb": "^0.22.2", - "keystore-idb": "0.14.2", + "keystore-idb": "0.15.0", "localforage": "^1.9.0", + "multiformats": "^9.0.0", "noble-ed25519": "^1.2.4", "throttle-debounce": "^3.0.1", "uint8arrays": "^2.1.7" diff --git a/src/common/version.ts b/src/common/version.ts index 1bf4a4ca2..277f816d7 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1 +1 @@ -export const VERSION = "0.27.1" +export const VERSION = "0.28.0" diff --git a/src/crypto/browser.ts b/src/crypto/browser.ts index 7514786d0..cfcc14496 100644 --- a/src/crypto/browser.ts +++ b/src/crypto/browser.ts @@ -68,10 +68,10 @@ export const ed25519Verify = (message: Uint8Array, signature: Uint8Array, public return ed25519.verify(signature, message, publicKey) } -export const ksPublicReadKey = async (): Promise => { - assertBrowser("keystore.publicReadKey") +export const ksPublicExchangeKey = async (): Promise => { + assertBrowser("keystore.publicExchangeKey") const ks = await keystore.get() - return ks.publicReadKey() + return ks.publicExchangeKey() } export const ksPublicWriteKey = async (): Promise => { diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 5b8fa219e..844083ebe 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -15,9 +15,9 @@ export const hash = { sha256Str: sha256Str } export const aes = { - encrypt: (bytes: Uint8Array, key: string): Promise => + encrypt: (bytes: Uint8Array, key: string): Promise => impl.aes.encrypt(bytes, key), - decrypt: (bytes: Uint8Array, key: string): Promise => + decrypt: (bytes: Uint8Array, key: string): Promise => impl.aes.decrypt(bytes, key), genKeyStr: (): Promise => impl.aes.genKeyStr(), @@ -35,8 +35,8 @@ export const ed25519 = { } export const keystore = { - publicReadKey: (): Promise => - impl.keystore.publicReadKey(), + publicExchangeKey: (): Promise => + impl.keystore.publicExchangeKey(), publicWriteKey: (): Promise => impl.keystore.publicWriteKey(), decrypt: (encrypted: string): Promise => diff --git a/src/did/local.ts b/src/did/local.ts index f7848e1d9..12d17c56d 100644 --- a/src/did/local.ts +++ b/src/did/local.ts @@ -7,7 +7,7 @@ import { toKeyType } from "./util.js" * Create a DID based on the exchange key-pair. */ export async function exchange(): Promise { - const pubKeyB64 = await crypto.keystore.publicReadKey() + const pubKeyB64 = await crypto.keystore.publicExchangeKey() const ksAlg = await crypto.keystore.getAlg() return publicKeyToDid( diff --git a/src/setup/dependencies.ts b/src/setup/dependencies.ts index a836f3b1e..9617b6242 100644 --- a/src/setup/dependencies.ts +++ b/src/setup/dependencies.ts @@ -1,7 +1,7 @@ import * as browserCrypto from "../crypto/browser.js" import * as browserStorage from "../storage/browser.js" -export const DEFAULT_IMPLEMENTATION: Dependencies = { +export const DEFAULT_IMPLEMENTATION: Dependencies = { hash: { sha256: browserCrypto.sha256 }, @@ -18,7 +18,7 @@ export const DEFAULT_IMPLEMENTATION: Dependencies = { verify: browserCrypto.ed25519Verify }, keystore: { - publicReadKey: browserCrypto.ksPublicReadKey, + publicExchangeKey: browserCrypto.ksPublicExchangeKey, publicWriteKey: browserCrypto.ksPublicWriteKey, decrypt: browserCrypto.ksDecrypt, sign: browserCrypto.ksSign, @@ -65,7 +65,7 @@ export interface Dependencies { encrypt: (bytes: Uint8Array, key: string) => Promise decrypt: (bytes: Uint8Array, key: string) => Promise genKeyStr: () => Promise - decryptGCM: (encrypted: string, keyStr: string, ivStr: string) => Promise + decryptGCM: (encrypted: string, keyStr: string, ivStr: string) => Promise } rsa: { verify: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) => Promise @@ -74,7 +74,7 @@ export interface Dependencies { verify: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) => Promise } keystore: { - publicReadKey: () => Promise + publicExchangeKey: () => Promise publicWriteKey: () => Promise decrypt: (encrypted: string) => Promise sign: (message: string, charSize: number) => Promise diff --git a/src/setup/node.ts b/src/setup/node.ts index 91f176717..19efdd400 100644 --- a/src/setup/node.ts +++ b/src/setup/node.ts @@ -89,14 +89,14 @@ const ed25519Verify = (message: Uint8Array, signature: Uint8Array, publicKey: Ui class InMemoryRSAKeyStore implements KeyStore { cfg: Config - readKeyPair: CryptoKeyPair + exchangeKeyPair: CryptoKeyPair writeKeyPair: CryptoKeyPair inMemoryStore: Record - constructor(cfg: Config, readKeyPair: CryptoKeyPair, writeKeyPair: CryptoKeyPair) { + constructor(cfg: Config, exchangeKeyPair: CryptoKeyPair, writeKeyPair: CryptoKeyPair) { this.cfg = cfg this.inMemoryStore = {} - this.readKeyPair = readKeyPair + this.exchangeKeyPair = exchangeKeyPair this.writeKeyPair = writeKeyPair } @@ -108,14 +108,14 @@ class InMemoryRSAKeyStore implements KeyStore { const { rsaSize, hashAlg } = cfg - const readKeyPair = await rsa.makeKeypair(rsaSize, hashAlg, KeyUse.Read) + const exchangeKeyPair = await rsa.makeKeypair(rsaSize, hashAlg, KeyUse.Exchange) const writeKeyPair = await rsa.makeKeypair(rsaSize, hashAlg, KeyUse.Write) - return new InMemoryRSAKeyStore(cfg, readKeyPair, writeKeyPair) + return new InMemoryRSAKeyStore(cfg, exchangeKeyPair, writeKeyPair) } - async readKey() { - return this.readKeyPair + async exchangeKey() { + return this.exchangeKeyPair } async writeKey() { @@ -229,21 +229,21 @@ class InMemoryRSAKeyStore implements KeyStore { publicKey?: string | PublicKey, // unused param so that keystore interfaces match cfg?: Partial ): Promise { - const readKey = await this.readKey() + const exchangeKey = await this.exchangeKey() const mergedCfg = config.merge(this.cfg, cfg) return utils.arrBufToStr( await rsa.decrypt( cipherText, - readKey.privateKey, + exchangeKey.privateKey, ), mergedCfg.charSize ) } - async publicReadKey(): Promise { - const readKey = await this.readKey() - return rsa.getPublicKey(readKey) + async publicExchangeKey(): Promise { + const exchangeKey = await this.exchangeKey() + return rsa.getPublicKey(exchangeKey) } async publicWriteKey(): Promise { @@ -287,9 +287,9 @@ export const NODE_IMPLEMENTATION = { verify: ed25519Verify }, keystore: { - async publicReadKey(): Promise { + async publicExchangeKey(): Promise { const ks = await getKeystore() - return ks.publicReadKey() + return ks.publicExchangeKey() }, async publicWriteKey(): Promise { const ks = await getKeystore() diff --git a/yarn.lock b/yarn.lock index 0538297c9..d2f9df24d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -312,10 +312,10 @@ "@hapi/bourne" "2.x.x" "@hapi/hoek" "9.x.x" -"@ipld/car@^3.1.8": - version "3.1.8" - resolved "https://registry.yarnpkg.com/@ipld/car/-/car-3.1.8.tgz#e6e4154b888426f3f251681ca3fb56a863ce677a" - integrity sha512-6GbVnsgjlhia3glezx1Rbc4FPU9ZKS94GQwjab1J3auxIYXHrxQ3SV1WUUCjX5lO9qGCB10KiyiKEIY2Mj8/jA== +"@ipld/car@^3.1.16": + version "3.1.16" + resolved "https://registry.yarnpkg.com/@ipld/car/-/car-3.1.16.tgz#8b0acfef0e9a74fa285731486ab2d3a1b7c12236" + integrity sha512-LvIXl7BYmy8em1PFB1l2Iu3/bFHYHy3h3x7HcDi9veoGSYi70dAIthJsXgkoYoGfRSLONR1FDjaoFjbbXk87Qw== dependencies: "@ipld/dag-cbor" "^6.0.0" "@types/varint" "^6.0.0" @@ -794,7 +794,7 @@ "@typescript-eslint/types" "4.29.3" eslint-visitor-keys "^2.0.0" -"@ungap/global-this@^0.4.3": +"@ungap/global-this@^0.4.4": version "0.4.4" resolved "https://registry.yarnpkg.com/@ungap/global-this/-/global-this-0.4.4.tgz#8a1b2cfcd3e26e079a847daba879308c924dd695" integrity sha512-mHkm6FvepJECMNthFuIgpAEFmPOk71UyXuIxYfjytvFTnSDBIz7jmViO+LfHI/AjrazWije0PnSP3+/NlwzqtA== @@ -3541,14 +3541,14 @@ keypair@^1.0.1: resolved "https://registry.yarnpkg.com/keypair/-/keypair-1.0.3.tgz#4314109d94052a0acfd6b885695026ad29529c80" integrity sha512-0wjZ2z/SfZZq01+3/8jYLd8aEShSa+aat1zyPGQY3IuKoEAp6DJGvu2zt6snELrQU9jbCkIlCyNOD7RdQbHhkQ== -keystore-idb@0.14.2: - version "0.14.2" - resolved "https://registry.yarnpkg.com/keystore-idb/-/keystore-idb-0.14.2.tgz#409a488acf900123ee1c6758a19dd2efde5fdf78" - integrity sha512-1jjL3Tjn4NSjczl/KBBnK1JefmouMSHC18Gv+2Eo27PiBSNrfa9ipGZkpW4OsV/tdYC50JA1IQ2yZRpeiYmH+w== +keystore-idb@0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/keystore-idb/-/keystore-idb-0.15.0.tgz#87897f2bafa9ebe42d52970d59034e22e8652df3" + integrity sha512-CSUCwdSR/gv/ydyv0m4DiTVdtHw0WPKmiw1frMh0jI3Ri9eGwtLBnYefppb2zgC6xLk4aBrPpojpjrRCEaL0/A== dependencies: - "@ungap/global-this" "^0.4.3" - buffer "^6.0.3" - localforage "^1.7.3" + "@ungap/global-this" "^0.4.4" + localforage "^1.10.0" + uint8arrays "^3.0.0" level-codec@^10.0.0: version "10.0.0" @@ -3966,7 +3966,14 @@ lie@3.1.1: dependencies: immediate "~3.0.5" -localforage@^1.7.3, localforage@^1.9.0: +localforage@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4" + integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg== + dependencies: + lie "3.1.1" + +localforage@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.9.0.tgz#f3e4d32a8300b362b4634cc4e066d9d00d2f09d1" integrity sha512-rR1oyNrKulpe+VM9cYmcFn6tsHuokyVHFaCM3+osEmxaHTbEk8oQu6eGDfS6DQLWi/N67XRmB8ECG37OES368g== @@ -5653,9 +5660,16 @@ uint8arrays@^2.0.5, uint8arrays@^2.1.2, uint8arrays@^2.1.3, uint8arrays@^2.1.4, multibase "^4.0.1" uint8arrays@^2.1.7: - version "2.1.7" - resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-2.1.7.tgz#16719b54b7b17be66eb9e44698a45f8371750b84" - integrity sha512-k+yuEWEHQG/TuRaxL+JVEe8IBqyU5dhDkw+CISCDccOcW90dIju0A6i0Iwav0MK7kg73FZpowqOByS5e/B6GYA== + version "2.1.10" + resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-2.1.10.tgz#34d023c843a327c676e48576295ca373c56e286a" + integrity sha512-Q9/hhJa2836nQfEJSZTmr+pg9+cDJS9XEAp7N2Vg5MzL3bK/mkMVfjscRGYruP9jNda6MAdf4QD/y78gSzkp6A== + dependencies: + multiformats "^9.4.2" + +uint8arrays@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-3.0.0.tgz#260869efb8422418b6f04e3fac73a3908175c63b" + integrity sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA== dependencies: multiformats "^9.4.2"