Browse Source

sign and verify msg using signer RPC server

hosting-provider
Evan Feenstra 5 years ago
parent
commit
fd6f1cdbb7
  1. 2
      api/helpers.ts
  2. 13
      api/network/receive.ts
  3. 3
      api/network/send.ts
  4. 4
      dist/api/helpers.js
  5. 2
      dist/api/helpers.js.map
  6. 12
      dist/api/network/receive.js
  7. 2
      dist/api/network/receive.js.map
  8. 3
      dist/api/network/send.js
  9. 2
      dist/api/network/send.js.map

2
api/helpers.ts

@ -201,7 +201,7 @@ function newkeyexchangemsg(type, sender){
return {
type: type,
sender: {
// pub_key: sender.publicKey,
pub_key: sender.publicKey,
contact_key: sender.contactKey,
...sender.alias && {alias: sender.alias},
...includePhotoUrl && {photo_url: sender.photoUrl}

13
api/network/receive.ts

@ -3,7 +3,8 @@ import * as lndService from '../grpc'
import {getInfo} from '../utils/lightning'
import {ACTIONS} from '../controllers'
import * as tribes from '../utils/tribes'
import {SPHINX_CUSTOM_RECORD_KEY, verifyAscii} from '../utils/lightning'
import {SPHINX_CUSTOM_RECORD_KEY} from '../utils/lightning'
import * as signer from '../utils/signer'
import { models } from '../models'
import {sendMessage} from './send'
import {modifyPayloadAndSaveMediaKey,purchaseFromOriginalSender,sendFinalMemeIfFirstPurchaser} from './modify'
@ -175,15 +176,15 @@ async function parseAndVerifyPayload(data){
const sig = data.substring(li+1)
try {
payload = JSON.parse(msg)
if(payload) {
const v = await verifyAscii(msg, sig)
if(v && v.valid && v.pubkey) {
payload.sender = payload.sender||{}
payload.sender.pub_key=v.pubkey
if(payload && payload.sender && payload.sender.pub_key) {
const v = await signer.verifyAscii(msg, sig, payload.sender.pub_key)
if(v && v.valid) {
return payload
} else {
return payload // => RM THIS
}
} else {
return payload // => RM THIS
}
} catch(e) {
if(payload) return payload // => RM THIS

3
api/network/send.ts

@ -1,5 +1,6 @@
import { models } from '../models'
import * as LND from '../utils/lightning'
import * as signer from '../utils/signer'
import {personalizeMessage, decryptMessage} from '../utils/msg'
import * as path from 'path'
import * as tribes from '../utils/tribes'
@ -101,7 +102,7 @@ export function signAndSend(opts, mqttTopic?:string){
let data = JSON.stringify(opts.data||{})
opts.amt = opts.amt || 0
const sig = await LND.signAscii(data)
const sig = await signer.signAscii(data)
data = data + sig
// console.log("ACTUALLY SEND", mqttTopic)

4
dist/api/helpers.js

@ -206,9 +206,7 @@ function newkeyexchangemsg(type, sender) {
const includePhotoUrl = sender && sender.photoUrl && !sender.privatePhoto;
return {
type: type,
sender: Object.assign(Object.assign({
// pub_key: sender.publicKey,
contact_key: sender.contactKey }, sender.alias && { alias: sender.alias }), includePhotoUrl && { photo_url: sender.photoUrl })
sender: Object.assign(Object.assign({ pub_key: sender.publicKey, contact_key: sender.contactKey }, sender.alias && { alias: sender.alias }), includePhotoUrl && { photo_url: sender.photoUrl })
};
}
//# sourceMappingURL=helpers.js.map

2
dist/api/helpers.js.map

File diff suppressed because one or more lines are too long

12
dist/api/network/receive.js

@ -15,6 +15,7 @@ const lightning_1 = require("../utils/lightning");
const controllers_1 = require("../controllers");
const tribes = require("../utils/tribes");
const lightning_2 = require("../utils/lightning");
const signer = require("../utils/signer");
const models_1 = require("../models");
const send_1 = require("./send");
const modify_1 = require("./modify");
@ -199,17 +200,18 @@ function parseAndVerifyPayload(data) {
const sig = data.substring(li + 1);
try {
payload = JSON.parse(msg);
if (payload) {
const v = yield lightning_2.verifyAscii(msg, sig);
if (v && v.valid && v.pubkey) {
payload.sender = payload.sender || {};
payload.sender.pub_key = v.pubkey;
if (payload && payload.sender && payload.sender.pub_key) {
const v = yield signer.verifyAscii(msg, sig, payload.sender.pub_key);
if (v && v.valid) {
return payload;
}
else {
return payload; // => RM THIS
}
}
else {
return payload; // => RM THIS
}
}
catch (e) {
if (payload)

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

3
dist/api/network/send.js

@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
const LND = require("../utils/lightning");
const signer = require("../utils/signer");
const msg_1 = require("../utils/msg");
const path = require("path");
const tribes = require("../utils/tribes");
@ -110,7 +111,7 @@ function signAndSend(opts, mqttTopic) {
}
let data = JSON.stringify(opts.data || {});
opts.amt = opts.amt || 0;
const sig = yield LND.signAscii(data);
const sig = yield signer.signAscii(data);
data = data + sig;
// console.log("ACTUALLY SEND", mqttTopic)
try {

2
dist/api/network/send.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save