@burstjs/util
Advanced tools
Comparing version 0.0.13 to 0.0.14
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## 2019-02-03 | ||
## 0.0.13 (2019-02-03) | ||
### Added | ||
@@ -6,0 +6,0 @@ - Added `@burstjs/utils` library for common utils. |
export * from './constructBurstAddress'; | ||
export * from './convertNumberToString'; | ||
export * from './convertStringToNumber'; | ||
export * from './decode'; | ||
export * from './encode'; | ||
export * from './convertNumberToNQTString'; | ||
export * from './convertNQTStringToNumber'; | ||
export * from './convertNumericIdToAddress'; | ||
export * from './convertAddressToNumericId'; | ||
export * from './isBurstAddress'; | ||
export * from './isValid'; | ||
export * from './splitBurstAddress'; | ||
@@ -14,9 +13,1 @@ export declare const burstAddressPattern: { | ||
}; | ||
export declare const initialCodeword: number[]; | ||
export declare const gexp: number[]; | ||
export declare const glog: number[]; | ||
export declare const cwmap: number[]; | ||
export declare const alphabet: string[]; | ||
export declare const base32Length = 13; | ||
export declare const ginv: (a: any) => number; | ||
export declare const gmult: (a: any, b: any) => number; |
@@ -7,8 +7,7 @@ "use strict"; | ||
__export(require("./constructBurstAddress")); | ||
__export(require("./convertNumberToString")); | ||
__export(require("./convertStringToNumber")); | ||
__export(require("./decode")); | ||
__export(require("./encode")); | ||
__export(require("./convertNumberToNQTString")); | ||
__export(require("./convertNQTStringToNumber")); | ||
__export(require("./convertNumericIdToAddress")); | ||
__export(require("./convertAddressToNumericId")); | ||
__export(require("./isBurstAddress")); | ||
__export(require("./isValid")); | ||
__export(require("./splitBurstAddress")); | ||
@@ -18,18 +17,2 @@ exports.burstAddressPattern = { | ||
}; | ||
exports.initialCodeword = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
exports.gexp = [1, 2, 4, 8, 16, 5, 10, 20, 13, 26, 17, 7, 14, 28, 29, 31, 27, 19, 3, 6, 12, 24, 21, 15, 30, 25, 23, 11, 22, 9, 18, 1]; | ||
exports.glog = [0, 0, 1, 18, 2, 5, 19, 11, 3, 29, 6, 27, 20, 8, 12, 23, 4, 10, 30, 17, 7, 22, 28, 26, 21, 25, 9, 16, 13, 14, 24, 15]; | ||
exports.cwmap = [3, 2, 1, 0, 7, 6, 5, 4, 13, 14, 15, 16, 12, 8, 9, 10, 11]; | ||
exports.alphabet = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'.split(''); | ||
exports.base32Length = 13; | ||
exports.ginv = (a) => { | ||
return exports.gexp[31 - exports.glog[a]]; | ||
}; | ||
exports.gmult = (a, b) => { | ||
if (a === 0 || b === 0) { | ||
return 0; | ||
} | ||
const idx = (exports.glog[a] + exports.glog[b]) % 31; | ||
return exports.gexp[idx]; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
export declare const isValid: (address: string) => boolean; | ||
export declare const isBurstAddress: (address: string) => boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const isValid_1 = require("./isValid"); | ||
const internal_1 = require("./internal"); | ||
exports.isValid = (address) => { | ||
if (address.indexOf('BURST-') === 0) { | ||
address = address.substr(6); | ||
} | ||
const codeword = internal_1.initialCodeword.slice(); | ||
let codewordLength = 0; | ||
for (let i = 0; i < address.length; i++) { | ||
const pos = internal_1.alphabet.indexOf(address.charAt(i)); | ||
if (pos <= -1 || pos > internal_1.alphabet.length) { | ||
continue; | ||
} | ||
if (codewordLength > 16) { | ||
return false; | ||
} | ||
const codeworkIndex = internal_1.cwmap[codewordLength]; | ||
codeword[codeworkIndex] = pos; | ||
codewordLength++; | ||
} | ||
if (codewordLength !== 17) { | ||
return false; | ||
} | ||
let sum = 0; | ||
for (let i = 1; i < 5; i++) { | ||
let t = 0; | ||
for (let j = 0; j < 31; j++) { | ||
if (j > 12 && j < 27) { | ||
continue; | ||
} | ||
let pos = j; | ||
if (j > 26) { | ||
pos -= 14; | ||
} | ||
t ^= internal_1.gmult(codeword[pos], internal_1.gexp[(i * j) % 31]); | ||
} | ||
sum |= t; | ||
} | ||
return (sum === 0); | ||
}; | ||
exports.isBurstAddress = (address) => { | ||
return /^BURST\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{5}/i.test(address) && isValid_1.isValid(address); | ||
return /^BURST\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{5}/i | ||
.test(address) && exports.isValid(address); | ||
}; | ||
//# sourceMappingURL=isBurstAddress.js.map |
{ | ||
"name": "@burstjs/util", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Useful utilities and tools for building Burstcoin applications", | ||
@@ -59,3 +59,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "d270043990cbfc28dd72c675499b4502eb7a1c40" | ||
"gitHead": "52816c035b215eeff299acec2dc9877ec69622ae" | ||
} |
@@ -0,4 +1,5 @@ | ||
// @todo review the need of this function...IMHO too trivial | ||
/** | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Modified work Copyright (c) 2019 Burst Apps Team | ||
@@ -13,2 +14,3 @@ */ | ||
return 'BURST-' + parts[0] + '-' + parts[1] + '-' + parts[2] + '-' + parts[3]; | ||
} | ||
}; | ||
/** @module util */ | ||
export * from './constructBurstAddress'; | ||
export * from './convertNumberToString'; | ||
export * from './convertStringToNumber'; | ||
export * from './decode'; | ||
export * from './encode'; | ||
export * from './convertNumberToNQTString'; | ||
export * from './convertNQTStringToNumber'; | ||
export * from './convertNumericIdToAddress'; | ||
export * from './convertAddressToNumericId'; | ||
export * from './isBurstAddress'; | ||
export * from './isValid'; | ||
export * from './splitBurstAddress'; | ||
@@ -17,23 +16,1 @@ | ||
}; | ||
export const initialCodeword = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
// tslint:disable-next-line:max-line-length | ||
export const gexp: number[] = [1, 2, 4, 8, 16, 5, 10, 20, 13, 26, 17, 7, 14, 28, 29, 31, 27, 19, 3, 6, 12, 24, 21, 15, 30, 25, 23, 11, 22, 9, 18, 1]; | ||
// tslint:disable-next-line:max-line-length | ||
export const glog: number[] = [0, 0, 1, 18, 2, 5, 19, 11, 3, 29, 6, 27, 20, 8, 12, 23, 4, 10, 30, 17, 7, 22, 28, 26, 21, 25, 9, 16, 13, 14, 24, 15]; | ||
export const cwmap: number[] = [3, 2, 1, 0, 7, 6, 5, 4, 13, 14, 15, 16, 12, 8, 9, 10, 11]; | ||
export const alphabet: string[] = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'.split(''); | ||
export const base32Length = 13; | ||
export const ginv = (a) => { | ||
return gexp[31 - glog[a]]; | ||
} | ||
export const gmult = (a, b) => { | ||
if (a === 0 || b === 0) { | ||
return 0; | ||
} | ||
const idx = (glog[a] + glog[b]) % 31; | ||
return gexp[idx]; | ||
} |
@@ -0,14 +1,80 @@ | ||
// tslint:disable:no-bitwise | ||
/** | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Modified work Copyright (c) 2019 Burst Apps Team | ||
*/ | ||
import { isValid } from "./isValid"; | ||
import { initialCodeword, alphabet, cwmap, gexp, gmult } from './internal'; | ||
/** | ||
* Validation Check. Quick validation of Burst addresses included | ||
* @param address Burst Address | ||
* Check for valid Burst address (format: BURST-XXXX-XXXX-XXXX-XXXXX, XXXX-XXXX-XXXX-XXXXX) | ||
* @param {string} address The address | ||
* @return {boolean} true, if is a valid address, else false | ||
*/ | ||
export const isValid = (address: string): boolean => { | ||
if (address.indexOf('BURST-') === 0) { | ||
address = address.substr(6); | ||
} | ||
const codeword = initialCodeword.slice(); | ||
let codewordLength = 0; | ||
for (let i = 0; i < address.length; i++) { | ||
const pos = alphabet.indexOf(address.charAt(i)); | ||
if (pos <= -1 || pos > alphabet.length) { | ||
continue; | ||
} | ||
if (codewordLength > 16) { | ||
return false; | ||
} | ||
const codeworkIndex = cwmap[codewordLength]; | ||
codeword[codeworkIndex] = pos; | ||
codewordLength++; | ||
} | ||
if (codewordLength !== 17) { | ||
return false; | ||
} | ||
let sum = 0; | ||
for (let i = 1; i < 5; i++) { | ||
let t = 0; | ||
for (let j = 0; j < 31; j++) { | ||
if (j > 12 && j < 27) { | ||
continue; | ||
} | ||
let pos = j; | ||
if (j > 26) { | ||
pos -= 14; | ||
} | ||
t ^= gmult(codeword[pos], gexp[(i * j) % 31]); | ||
} | ||
sum |= t; | ||
} | ||
return (sum === 0); | ||
}; | ||
/** | ||
* Check for valid Burst address (format: BURST-XXXX-XXXX-XXXX-XXXXX, XXXX-XXXX-XXXX-XXXXX) | ||
* @note This is with prior quick check | ||
* @param {string} address The address | ||
* @return {boolean} true, if is a valid address, else false | ||
*/ | ||
export const isBurstAddress = (address: string): boolean => { | ||
return /^BURST\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{5}/i.test(address) && isValid(address); | ||
} | ||
return /^BURST\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{5}/i | ||
.test(address) && isValid(address); | ||
}; | ||
/** | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Original work Copyright (c) 2018 PoC-Consortium | ||
* Modified work Copyright (c) 2019 Burst Apps Team | ||
@@ -18,2 +18,3 @@ */ | ||
} | ||
} | ||
}; | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39279
39
43
685
2