-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aac96f
commit 5500d1c
Showing
29 changed files
with
1,100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) | ||
for (var k in mod) | ||
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result['default'] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const typeFields_js_1 = require('../../typeFields.cjs'); | ||
const tools = __importStar(require('uint8array-tools')); | ||
function decode(keyVal) { | ||
if (keyVal.key[0] !== typeFields_js_1.OutputTypes.SP_V0_LABEL) { | ||
throw new Error( | ||
'Decode Error: could not decode silentPaymentOutputLabel with key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
return Number(tools.readUInt32(keyVal.value, 0, 'LE')); | ||
} | ||
exports.decode = decode; | ||
function encode(data) { | ||
const key = Uint8Array.from([typeFields_js_1.OutputTypes.SP_V0_LABEL]); | ||
const value = new Uint8Array(4); | ||
tools.writeUInt32(value, 0, data, 'LE'); | ||
return { | ||
key, | ||
value, | ||
}; | ||
} | ||
exports.encode = encode; | ||
exports.expected = 'number'; | ||
function check(data) { | ||
return typeof data === 'number'; | ||
} | ||
exports.check = check; | ||
function canAdd(currentData, newData) { | ||
return ( | ||
!!currentData && | ||
!!newData && | ||
currentData.silentPaymentOutputLabel === undefined | ||
); | ||
} | ||
exports.canAdd = canAdd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) | ||
for (var k in mod) | ||
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result['default'] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const typeFields_js_1 = require('../../typeFields.cjs'); | ||
const tools = __importStar(require('uint8array-tools')); | ||
const isValidPubKey = pubkey => | ||
pubkey.length === 33 && [2, 3].includes(pubkey[0]); | ||
function decode(keyVal) { | ||
if (keyVal.key[0] !== typeFields_js_1.OutputTypes.SP_V0_INFO) { | ||
throw new Error( | ||
'Decode Error: could not decode silentPaymentV0Info with key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
if (keyVal.value.length !== 66) { | ||
throw new Error('Decode Error: SP_V0_INFO is not proper length'); | ||
} | ||
const scanKey = keyVal.value.slice(0, 33); | ||
if (!isValidPubKey(scanKey)) { | ||
throw new Error('Decode Error: SP_V0_INFO scanKey is not a valid pubkey'); | ||
} | ||
const spendKey = keyVal.value.slice(33); | ||
if (!isValidPubKey(spendKey)) { | ||
throw new Error('Decode Error: SP_V0_INFO spendKey is not a valid pubkey'); | ||
} | ||
return { | ||
scanKey, | ||
spendKey, | ||
}; | ||
} | ||
exports.decode = decode; | ||
function encode(data) { | ||
const key = new Uint8Array([typeFields_js_1.OutputTypes.SP_V0_INFO]); | ||
return { | ||
key, | ||
value: Uint8Array.from([...data.scanKey, ...data.spendKey]), | ||
}; | ||
} | ||
exports.encode = encode; | ||
exports.expected = '{ scanKey: Uint8Array; spendKey: Uint8Array; }'; | ||
function check(data) { | ||
return ( | ||
data.scanKey instanceof Uint8Array && | ||
data.spendKey instanceof Uint8Array && | ||
isValidPubKey(data.scanKey) && | ||
isValidPubKey(data.spendKey) | ||
); | ||
} | ||
exports.check = check; | ||
function canAdd(currentData, newData) { | ||
return ( | ||
!!currentData && !!newData && currentData.silentPaymentV0Info === undefined | ||
); | ||
} | ||
exports.canAdd = canAdd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) | ||
for (var k in mod) | ||
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result['default'] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const tools = __importStar(require('uint8array-tools')); | ||
const isValidPubKey = pubkey => | ||
pubkey.length === 33 && [2, 3].includes(pubkey[0]); | ||
function makeConverter(TYPE_BYTE, isValidPubkey = isValidPubKey) { | ||
function decode(keyVal) { | ||
if (keyVal.key[0] !== TYPE_BYTE) { | ||
throw new Error( | ||
'Decode Error: could not decode silentPaymentDleq with key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
const scanKey = keyVal.key.slice(1); | ||
if (!isValidPubkey(scanKey)) { | ||
throw new Error( | ||
'Decode Error: silentPaymentDleq has invalid scanKey in key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
if (keyVal.value.length !== 64) { | ||
throw new Error('Decode Error: silentPaymentDleq not a 64-byte proof'); | ||
} | ||
return { | ||
scanKey, | ||
proof: keyVal.value, | ||
}; | ||
} | ||
function encode(data) { | ||
const head = Uint8Array.from([TYPE_BYTE]); | ||
const key = tools.concat([head, data.scanKey]); | ||
return { | ||
key, | ||
value: data.proof, | ||
}; | ||
} | ||
const expected = '{ scanKey: Uint8Array; proof: Uint8Array; }'; | ||
function check(data) { | ||
return ( | ||
data.scanKey instanceof Uint8Array && | ||
data.proof instanceof Uint8Array && | ||
isValidPubkey(data.scanKey) && | ||
data.proof.length === 64 | ||
); | ||
} | ||
function canAddToArray(array, item, dupeSet) { | ||
const dupeString = tools.toHex(item.scanKey); | ||
if (dupeSet.has(dupeString)) return false; | ||
dupeSet.add(dupeString); | ||
return ( | ||
array.filter(v => tools.compare(v.scanKey, item.scanKey) === 0).length === | ||
0 | ||
); | ||
} | ||
return { | ||
decode, | ||
encode, | ||
check, | ||
expected, | ||
canAddToArray, | ||
}; | ||
} | ||
exports.makeConverter = makeConverter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) | ||
for (var k in mod) | ||
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result['default'] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const tools = __importStar(require('uint8array-tools')); | ||
const isValidDERKey = pubkey => | ||
(pubkey.length === 33 && [2, 3].includes(pubkey[0])) || | ||
(pubkey.length === 65 && 4 === pubkey[0]); | ||
function makeConverter(TYPE_BYTE, isValidPubkey = isValidDERKey) { | ||
function decode(keyVal) { | ||
if (keyVal.key[0] !== TYPE_BYTE) { | ||
throw new Error( | ||
'Decode Error: could not decode silentPaymentEcdhShare with key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
const scanKey = keyVal.key.slice(1); | ||
if (!isValidPubkey(scanKey)) { | ||
throw new Error( | ||
'Decode Error: silentPaymentEcdhShare has invalid scanKey in key 0x' + | ||
tools.toHex(keyVal.key), | ||
); | ||
} | ||
if (!isValidPubkey(keyVal.value)) { | ||
throw new Error( | ||
'Decode Error: silentPaymentEcdhShare not a 33-byte pubkey', | ||
); | ||
} | ||
return { | ||
scanKey, | ||
share: keyVal.value, | ||
}; | ||
} | ||
function encode(data) { | ||
const head = Uint8Array.from([TYPE_BYTE]); | ||
const key = tools.concat([head, data.scanKey]); | ||
return { | ||
key, | ||
value: data.share, | ||
}; | ||
} | ||
const expected = '{ scanKey: Uint8Array; share: Uint8Array; }'; | ||
function check(data) { | ||
return ( | ||
data.scanKey instanceof Uint8Array && | ||
data.share instanceof Uint8Array && | ||
isValidPubkey(data.scanKey) && | ||
isValidPubkey(data.share) | ||
); | ||
} | ||
function canAddToArray(array, item, dupeSet) { | ||
const dupeString = tools.toHex(item.scanKey); | ||
if (dupeSet.has(dupeString)) return false; | ||
dupeSet.add(dupeString); | ||
return ( | ||
array.filter(v => tools.compare(v.scanKey, item.scanKey) === 0).length === | ||
0 | ||
); | ||
} | ||
return { | ||
decode, | ||
encode, | ||
check, | ||
expected, | ||
canAddToArray, | ||
}; | ||
} | ||
exports.makeConverter = makeConverter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.