From bbe19a6bfd2906b3d7f381a358edfe66a195bd60 Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Thu, 21 Mar 2019 16:49:53 -0400 Subject: [PATCH] Update webln to 0.2.0, simplify all import paths and update signature format. --- package.json | 2 +- src/app/modules/sign/reducers.ts | 2 +- src/app/modules/sign/sagas.ts | 19 ++++++++++++++++--- src/app/modules/sign/types.ts | 10 +++++----- src/app/prompts/invoice.tsx | 2 +- src/app/prompts/payment.tsx | 2 +- src/app/prompts/sign.tsx | 2 +- src/background_script/getNodeInfo.ts | 2 +- src/webln/provider.ts | 2 +- yarn.lock | 7 ++++--- 10 files changed, 32 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 75715974..7655f198 100755 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "tslint-react": "^3.6.0", "typescript": "3.1.6", "url-loader": "^1.1.1", - "webln": "0.0.3", + "webln": "0.2.0", "webpack": "^4.19.0", "webpack-cli": "^3.1.0", "zip-webpack-plugin": "3.0.0", diff --git a/src/app/modules/sign/reducers.ts b/src/app/modules/sign/reducers.ts index e818c949..60659a81 100644 --- a/src/app/modules/sign/reducers.ts +++ b/src/app/modules/sign/reducers.ts @@ -1,5 +1,5 @@ import types from './types'; -import { SignMessageResponse } from 'webln/lib/provider'; +import { SignMessageResponse } from 'webln'; export interface SignState { signReceipt: SignMessageResponse | null; diff --git a/src/app/modules/sign/sagas.ts b/src/app/modules/sign/sagas.ts index 509976ee..e1baa8bf 100644 --- a/src/app/modules/sign/sagas.ts +++ b/src/app/modules/sign/sagas.ts @@ -1,17 +1,30 @@ import { SagaIterator } from 'redux-saga'; import { takeLatest, select, call, put } from 'redux-saga/effects'; +import { SignMessageResponse as WebLNSignMessageResponse } from 'webln'; import { selectNodeLibOrThrow } from 'modules/node/selectors'; import { requirePassword } from 'modules/crypto/sagas'; import { signMessage, verifyMessage } from './actions'; import types from './types'; -import { SignMessageResponse, VerifyMessageResponse } from 'lib/lnd-http/types'; +import { + SignMessageResponse as LndSignMessageResponse, + VerifyMessageResponse as LndVerifyMessageResponse, +} from 'lib/lnd-http/types'; import { safeGetNodeInfo } from 'utils/misc'; export function* handleSignMessage(action: ReturnType): SagaIterator { try { yield call(requirePassword); const nodeLib: Yielded = yield select(selectNodeLibOrThrow); - const payload: Yielded = yield call(nodeLib.signMessage, action.payload); + const res: Yielded = yield call(nodeLib.signMessage, action.payload); + + if (!res.signature) { + throw new Error('Message failed to sign, missing signature'); + } + + const payload: WebLNSignMessageResponse = { + message: action.payload, + signature: res.signature, + }; yield put({ type: types.SIGN_MESSAGE_SUCCESS, @@ -29,7 +42,7 @@ export function* handleVerifyMessage(action: ReturnType): try { yield call(requirePassword); const nodeLib: Yielded = yield select(selectNodeLibOrThrow); - const verification: Yielded = yield call(nodeLib.verifyMessage, action.payload); + const verification: Yielded = yield call(nodeLib.verifyMessage, action.payload); const nodeInfo: Yielded = yield call(safeGetNodeInfo, nodeLib, verification.pubkey); const payload = { ...verification, diff --git a/src/app/modules/sign/types.ts b/src/app/modules/sign/types.ts index b50640ad..fe0dadb0 100644 --- a/src/app/modules/sign/types.ts +++ b/src/app/modules/sign/types.ts @@ -1,11 +1,11 @@ enum SignTypes { SIGN_MESSAGE = 'SIGN_MESSAGE', - SIGN_MESSAGE_SUCCESS = "SIGN_MESSAGE_SUCCESS", - SIGN_MESSAGE_FAILURE = "SIGN_MESSAGE_FAILURE", + SIGN_MESSAGE_SUCCESS = 'SIGN_MESSAGE_SUCCESS', + SIGN_MESSAGE_FAILURE = 'SIGN_MESSAGE_FAILURE', VERIFY_MESSAGE = 'VERIFY_MESSAGE', - VERIFY_MESSAGE_VALID = "VERIFY_MESSAGE_VALID", - VERIFY_MESSAGE_INVALID = "VERIFY_MESSAGE_INVALID", - VERIFY_MESSAGE_FAILURE = "VERIFY_MESSAGE_FAILURE", + VERIFY_MESSAGE_VALID = 'VERIFY_MESSAGE_VALID', + VERIFY_MESSAGE_INVALID = 'VERIFY_MESSAGE_INVALID', + VERIFY_MESSAGE_FAILURE = 'VERIFY_MESSAGE_FAILURE', } export default SignTypes; diff --git a/src/app/prompts/invoice.tsx b/src/app/prompts/invoice.tsx index d95e3f92..ddd66a5c 100644 --- a/src/app/prompts/invoice.tsx +++ b/src/app/prompts/invoice.tsx @@ -2,7 +2,7 @@ import React from 'react'; import BN from 'bn.js'; import { connect } from 'react-redux'; import { Form, Input, Select, Button } from 'antd'; -import { RequestInvoiceArgs, RequestInvoiceResponse } from 'webln/lib/provider'; +import { RequestInvoiceArgs, RequestInvoiceResponse } from 'webln'; import PromptTemplate from 'components/PromptTemplate'; import { getPromptArgs, getPromptOrigin, watchUntilPropChange, OriginData } from 'utils/prompt'; import { removeDomainPrefix } from 'utils/formatters'; diff --git a/src/app/prompts/payment.tsx b/src/app/prompts/payment.tsx index b518dc59..04481afb 100644 --- a/src/app/prompts/payment.tsx +++ b/src/app/prompts/payment.tsx @@ -2,7 +2,7 @@ import React from 'react'; import moment from 'moment'; import { connect } from 'react-redux'; import { Tabs, Input, Select } from 'antd'; -import { SendPaymentResponse } from 'webln/lib/provider'; +import { SendPaymentResponse } from 'webln'; import PromptTemplate from 'components/PromptTemplate'; import NodeInfo from 'components/PromptTemplate/NodeInfo'; import Loader from 'components/Loader'; diff --git a/src/app/prompts/sign.tsx b/src/app/prompts/sign.tsx index 0a27135c..5929b21e 100644 --- a/src/app/prompts/sign.tsx +++ b/src/app/prompts/sign.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; -import { SignMessageResponse } from 'webln/lib/provider'; +import { SignMessageResponse } from 'webln'; import { AppState } from 'store/reducers'; import PromptTemplate from 'components/PromptTemplate'; import SwapGraphic from 'components/PromptTemplate/SwapGraphic'; diff --git a/src/background_script/getNodeInfo.ts b/src/background_script/getNodeInfo.ts index f34aeb21..00b892b3 100644 --- a/src/background_script/getNodeInfo.ts +++ b/src/background_script/getNodeInfo.ts @@ -1,4 +1,4 @@ -import { GetInfoResponse } from 'webln/lib/provider'; +import { GetInfoResponse } from 'webln'; import runSelector from '../content_script/runSelector'; import { LndHttpClient } from 'lib/lnd-http'; import { selectSyncedUnencryptedNodeState } from 'modules/node/selectors'; diff --git a/src/webln/provider.ts b/src/webln/provider.ts index 6323dd09..84483380 100644 --- a/src/webln/provider.ts +++ b/src/webln/provider.ts @@ -5,7 +5,7 @@ import { RequestInvoiceArgs, RequestInvoiceResponse, SignMessageResponse, -} from 'webln/lib/provider'; +} from 'webln'; import { PROMPT_TYPE } from './types'; export default class JouleWebLNProvider implements WebLNProvider { diff --git a/yarn.lock b/yarn.lock index da1b1e88..038b0075 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7778,9 +7778,10 @@ webidl-conversions@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" -webln@0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/webln/-/webln-0.0.3.tgz#d8bd43accfb2f85216441a3f67f58349835c9aa9" +webln@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/webln/-/webln-0.2.0.tgz#841a19a315efb407dc065ab6827bd64e61051cdd" + integrity sha512-8fuN3k6Aif6HkAeKtvhnWHUdkOwZDf5igQc+jtOR3Id1x1q6/hklJqnixSOIARu1VUrhInLeVBTr1QdKatGlkw== dependencies: "@types/chrome" "0.0.74"