@cvbb/bc-ur
Advanced tools
Comparing version 0.2.9 to 0.2.10
export declare const decodeUR: (workloads: string[], type?: string) => string; | ||
export declare const smartDecodeUR: (workloads: string[]) => { | ||
success: boolean; | ||
current: number; | ||
length: number; | ||
workloads: string[]; | ||
result: string; | ||
}; | ||
export declare const extractSingleWorkload: (workload: string) => [number, number]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extractSingleWorkload = exports.decodeUR = void 0; | ||
exports.extractSingleWorkload = exports.smartDecodeUR = exports.decodeUR = void 0; | ||
var utils_1 = require("./utils"); | ||
@@ -96,3 +96,3 @@ var miniCbor_1 = require("./miniCbor"); | ||
}; | ||
exports.decodeUR = function (workloads, type) { | ||
var decodeUR = function (workloads, type) { | ||
if (type === void 0) { type = 'bytes'; } | ||
@@ -106,3 +106,40 @@ var bc32Payload = getBC32Payload(workloads, type); | ||
}; | ||
exports.extractSingleWorkload = function (workload) { | ||
exports.decodeUR = decodeUR; | ||
var onlyUniq = function (value, index, self) { | ||
return self.indexOf(value) === index; | ||
}; | ||
var smartDecodeUR = function (workloads) { | ||
if (workloads.length > 0) { | ||
var _a = exports.extractSingleWorkload(workloads[0]), index = _a[0], total = _a[1]; | ||
if (workloads.length === total) { | ||
return { | ||
success: true, | ||
current: workloads.length, | ||
length: total, | ||
workloads: [], | ||
result: exports.decodeUR(workloads), | ||
}; | ||
} | ||
else { | ||
return { | ||
success: false, | ||
current: workloads.length, | ||
length: total, | ||
workloads: workloads.filter(onlyUniq), | ||
result: '', | ||
}; | ||
} | ||
} | ||
else { | ||
return { | ||
success: false, | ||
current: 0, | ||
length: 0, | ||
workloads: [], | ||
result: '', | ||
}; | ||
} | ||
}; | ||
exports.smartDecodeUR = smartDecodeUR; | ||
var extractSingleWorkload = function (workload) { | ||
var pieces = workload.toUpperCase().split('/'); | ||
@@ -123,2 +160,3 @@ switch (pieces.length) { | ||
}; | ||
exports.extractSingleWorkload = extractSingleWorkload; | ||
//# sourceMappingURL=decodeUR.js.map |
@@ -28,3 +28,3 @@ "use strict"; | ||
}; | ||
exports.encodeUR = function (payload, fragmentCapacity) { | ||
var encodeUR = function (payload, fragmentCapacity) { | ||
if (fragmentCapacity === void 0) { fragmentCapacity = 200; } | ||
@@ -41,2 +41,3 @@ var cborPayload = miniCbor_1.encodeSimpleCBOR(payload); | ||
}; | ||
exports.encodeUR = encodeUR; | ||
//# sourceMappingURL=encodeUR.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
exports.composeHeader = function (length) { | ||
var composeHeader = function (length) { | ||
var header; | ||
@@ -34,3 +34,4 @@ if (length > 0 && length <= 23) { | ||
}; | ||
exports.encodeSimpleCBOR = function (data) { | ||
exports.composeHeader = composeHeader; | ||
var encodeSimpleCBOR = function (data) { | ||
var bufferData = Buffer.from(data, 'hex'); | ||
@@ -44,3 +45,4 @@ if (bufferData.length <= 0 || bufferData.length >= Math.pow(2, 32)) { | ||
}; | ||
exports.decodeSimpleCBOR = function (data) { | ||
exports.encodeSimpleCBOR = encodeSimpleCBOR; | ||
var decodeSimpleCBOR = function (data) { | ||
var dataBuffer = Buffer.from(data, 'hex'); | ||
@@ -71,2 +73,3 @@ if (dataBuffer.length <= 0) { | ||
}; | ||
exports.decodeSimpleCBOR = decodeSimpleCBOR; | ||
//# sourceMappingURL=miniCbor.js.map |
@@ -8,8 +8,10 @@ "use strict"; | ||
var sha_js_1 = __importDefault(require("sha.js")); | ||
exports.sha256Hash = function (data) { | ||
var sha256Hash = function (data) { | ||
return sha_js_1.default('sha256').update(data).digest(); | ||
}; | ||
exports.compose3 = function (f, g, h) { return function (x) { | ||
exports.sha256Hash = sha256Hash; | ||
var compose3 = function (f, g, h) { return function (x) { | ||
return f(g(h(x))); | ||
}; }; | ||
exports.compose3 = compose3; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@cvbb/bc-ur", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "BlockChain Commons Uniform Resources", | ||
@@ -19,3 +19,3 @@ "author": "aaronisme <aarondongchen@gmail.com>", | ||
"dependencies": { | ||
"@cvbb/bc-bech32": "^1.1.9", | ||
"@cvbb/bc-bech32": "^1.1.10", | ||
"@types/sha.js": "^2.4.0", | ||
@@ -39,3 +39,3 @@ "sha.js": "^2.4.11" | ||
}, | ||
"gitHead": "476105b5dbc398efd1ca0bc7b672560f39a90b3a" | ||
"gitHead": "5afcf90b2b47d23aecfa56c73f6a0054da4cc8df" | ||
} |
@@ -99,2 +99,45 @@ import { sha256Hash } from './utils'; | ||
const onlyUniq = (value: string, index: number, self: string[]) => { | ||
return self.indexOf(value) === index; | ||
}; | ||
export const smartDecodeUR = ( | ||
workloads: string[], | ||
): { | ||
success: boolean; | ||
current: number; | ||
length: number; | ||
workloads: string[]; | ||
result: string; | ||
} => { | ||
if (workloads.length > 0) { | ||
const [index, total] = extractSingleWorkload(workloads[0]); | ||
if (workloads.length === total) { | ||
return { | ||
success: true, | ||
current: workloads.length, | ||
length: total, | ||
workloads: [], | ||
result: decodeUR(workloads), | ||
}; | ||
} else { | ||
return { | ||
success: false, | ||
current: workloads.length, | ||
length: total, | ||
workloads: workloads.filter(onlyUniq), | ||
result: '', | ||
}; | ||
} | ||
} else { | ||
return { | ||
success: false, | ||
current: 0, | ||
length: 0, | ||
workloads: [], | ||
result: '', | ||
}; | ||
} | ||
}; | ||
export const extractSingleWorkload = (workload: string): [number, number] => { | ||
@@ -101,0 +144,0 @@ const pieces = workload.toUpperCase().split('/'); |
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
33543
558
Updated@cvbb/bc-bech32@^1.1.10