Browse Source

Merge pull request #52 from stakwork/sig

Sig
hosting-provider v0.9.18
Evan Feenstra 5 years ago
committed by GitHub
parent
commit
a0495a8496
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      api/helpers.ts
  2. 16
      api/network/receive.ts
  3. 3
      api/network/send.ts
  4. 14
      api/utils/signer.ts
  5. 4
      dist/api/helpers.js
  6. 2
      dist/api/helpers.js.map
  7. 15
      dist/api/network/receive.js
  8. 2
      dist/api/network/receive.js.map
  9. 3
      dist/api/network/send.js
  10. 2
      dist/api/network/send.js.map
  11. 14
      dist/api/utils/signer.js
  12. 2
      dist/api/utils/signer.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}

16
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'
@ -176,15 +177,18 @@ 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) {
let v
if(sig.length===96) { // => RM THIS
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)

14
api/utils/signer.ts

@ -38,7 +38,8 @@ export const signMessage = (msg) => {
if(err || !sig.signature) {
reject(err)
} else {
resolve(sig.signature)
const buf = ByteBuffer.wrap(sig.signature);
resolve(buf.toBase64())
}
})
} catch(e) {
@ -56,7 +57,8 @@ export const signBuffer = (msg) => {
if(err || !sig.signature) {
reject(err)
} else {
resolve(sig.signature)
const buf = ByteBuffer.wrap(sig.signature);
resolve(buf.toBase64())
}
})
} catch(e) {
@ -68,10 +70,16 @@ export const signBuffer = (msg) => {
function verifyMessage(msg,sig,pubkey): Promise<{[k:string]:any}> {
return new Promise(async(resolve, reject)=> {
let signer = await loadSigner()
if(sig.length!==96) {
return reject('invalid sig')
}
if(pubkey.length!==66) {
return reject('invalid pubkey')
}
try {
const options = {
msg:ByteBuffer.fromHex(msg),
signature:sig,
signature:ByteBuffer.fromBase64(sig),
pubkey:ByteBuffer.fromHex(pubkey),
}
signer.verifyMessage(options, function(err,res){

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

15
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");
@ -200,17 +201,21 @@ 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) {
let v;
if (sig.length === 96) { // => RM THIS
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

14
dist/api/utils/signer.js

@ -47,7 +47,8 @@ exports.signMessage = (msg) => {
reject(err);
}
else {
resolve(sig.signature);
const buf = ByteBuffer.wrap(sig.signature);
resolve(buf.toBase64());
}
});
}
@ -66,7 +67,8 @@ exports.signBuffer = (msg) => {
reject(err);
}
else {
resolve(sig.signature);
const buf = ByteBuffer.wrap(sig.signature);
resolve(buf.toBase64());
}
});
}
@ -78,10 +80,16 @@ exports.signBuffer = (msg) => {
function verifyMessage(msg, sig, pubkey) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let signer = yield exports.loadSigner();
if (sig.length !== 96) {
return reject('invalid sig');
}
if (pubkey.length !== 66) {
return reject('invalid pubkey');
}
try {
const options = {
msg: ByteBuffer.fromHex(msg),
signature: sig,
signature: ByteBuffer.fromBase64(sig),
pubkey: ByteBuffer.fromHex(pubkey),
};
signer.verifyMessage(options, function (err, res) {

2
dist/api/utils/signer.js.map

@ -1 +1 @@
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../api/utils/signer.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,6BAA4B;AAC5B,2CAA2C;AAC3C,6BAA4B;AAC5B,yCAAwC;AAExC,kDAAkD;AAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzE,IAAI,YAAY,GAAS,IAAI,CAAC;AAEjB,QAAA,UAAU,GAAG,GAAG,EAAE;IAC7B,IAAI,YAAY,EAAE;QAChB,OAAO,YAAY,CAAA;KACpB;SAAM;QACL,IAAG;YACD,IAAI,WAAW,GAAG,2BAAe,EAAE,CAAA;YACnC,IAAI,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAChD,IAAI,MAAM,GAAQ,eAAe,CAAC,OAAO,CAAA;YACzC,YAAY,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YACtF,OAAO,YAAY,CAAA;SACpB;QAAC,OAAM,CAAC,EAA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