@stratumn/js-crypto
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -61,3 +61,3 @@ 'use strict'; | ||
var keyBytes = (0, _utils.unicodeToBuffer)(capture.privateKey); | ||
var keyBytes = (0, _utils.unicodeToUint8Array)(capture.privateKey); | ||
return new ED25519PrivateKey(keyBytes); | ||
@@ -80,3 +80,3 @@ }; | ||
encoding: 'binary', | ||
signature: (0, _utils.unicodeToBuffer)(signature) | ||
signature: (0, _utils.unicodeToUint8Array)(signature) | ||
}); | ||
@@ -96,3 +96,3 @@ }; | ||
// We need to pad the key with the byte 0 (zero). | ||
_nodeForge.util.createBuffer(Buffer.concat([Buffer.from([0]), _this2._key])).getBytes())]); | ||
_nodeForge.util.createBuffer((0, _utils.concatUint8Arrays)([0], _this2._key)).getBytes())]); | ||
}; | ||
@@ -99,0 +99,0 @@ |
@@ -108,6 +108,6 @@ 'use strict'; | ||
return { | ||
signature: (0, _utils.encodeSignature)(sig), | ||
message: message, | ||
signature: _nodeForge.util.encode64((0, _utils.encodeSignature)(sig)), | ||
message: _nodeForge.util.encode64(message), | ||
algorithm: _this._algo, | ||
public_key: _this.publicKey().export() | ||
public_key: _nodeForge.util.encode64(_this.publicKey().export()) | ||
}; | ||
@@ -114,0 +114,0 @@ }; |
@@ -53,3 +53,3 @@ 'use strict'; | ||
case _constants.SIGNING_ALGO_ED25519.oid: | ||
_this._key = new _curve.ED25519PublicKey((0, _utils.unicodeToBuffer)(asn1Data.curve25519PublicKey)); | ||
_this._key = new _curve.ED25519PublicKey((0, _utils.unicodeToUint8Array)(asn1Data.curve25519PublicKey)); | ||
_this._algo = _constants.SIGNING_ALGO_ED25519.name; | ||
@@ -56,0 +56,0 @@ break; |
@@ -18,6 +18,18 @@ 'use strict'; | ||
}); | ||
var unicodeToBuffer = exports.unicodeToBuffer = function unicodeToBuffer(str) { | ||
return Buffer.from(str.split('').map(function (s) { | ||
return s.charCodeAt(0); | ||
})); | ||
var unicodeToUint8Array = exports.unicodeToUint8Array = function unicodeToUint8Array(str) { | ||
var res = new Uint8Array(str.length); | ||
var idx = 0; | ||
str.split('').forEach(function (s) { | ||
res[idx] = s.charCodeAt(0); | ||
idx += 1; | ||
}); | ||
return res; | ||
}; | ||
var concatUint8Arrays = exports.concatUint8Arrays = function concatUint8Arrays(a1, a2) { | ||
var res = new Uint8Array(a1.length + a2.length); | ||
res.set(a1); | ||
res.set(a2, a1.length); | ||
return res; | ||
}; |
{ | ||
"name": "@stratumn/js-crypto", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Browser compatible crypto", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { asn1, ed25519, util } from 'node-forge'; | ||
import { unicodeToBuffer } from '../utils'; | ||
import { unicodeToUint8Array, concatUint8Arrays } from '../utils'; | ||
@@ -49,3 +49,3 @@ export const X25519_OID = '1.3.101.110'; | ||
const keyBytes = unicodeToBuffer(capture.privateKey); | ||
const keyBytes = unicodeToUint8Array(capture.privateKey); | ||
return new ED25519PrivateKey(keyBytes); | ||
@@ -68,3 +68,3 @@ }; | ||
encoding: 'binary', | ||
signature: unicodeToBuffer(signature) | ||
signature: unicodeToUint8Array(signature) | ||
}); | ||
@@ -92,5 +92,3 @@ | ||
// We need to pad the key with the byte 0 (zero). | ||
util | ||
.createBuffer(Buffer.concat([Buffer.from([0]), this._key])) | ||
.getBytes() | ||
util.createBuffer(concatUint8Arrays([0], this._key)).getBytes() | ||
) | ||
@@ -97,0 +95,0 @@ ]); |
@@ -1,2 +0,2 @@ | ||
import { pki } from 'node-forge'; | ||
import { pki, util } from 'node-forge'; | ||
@@ -84,6 +84,6 @@ import { | ||
return { | ||
signature: encodeSignature(sig), | ||
message, | ||
signature: util.encode64(encodeSignature(sig)), | ||
message: util.encode64(message), | ||
algorithm: this._algo, | ||
public_key: this.publicKey().export() | ||
public_key: util.encode64(this.publicKey().export()) | ||
}; | ||
@@ -90,0 +90,0 @@ }; |
@@ -11,3 +11,3 @@ import { pki } from 'node-forge'; | ||
decodeSignature, | ||
unicodeToBuffer | ||
unicodeToUint8Array | ||
} from '../utils'; | ||
@@ -41,3 +41,3 @@ | ||
this._key = new ED25519PublicKey( | ||
unicodeToBuffer(asn1Data.curve25519PublicKey) | ||
unicodeToUint8Array(asn1Data.curve25519PublicKey) | ||
); | ||
@@ -44,0 +44,0 @@ this._algo = SIGNING_ALGO_ED25519.name; |
export * from './encoding'; | ||
export const unicodeToBuffer = str => | ||
Buffer.from(str.split('').map(s => s.charCodeAt(0))); | ||
export const unicodeToUint8Array = str => { | ||
const res = new Uint8Array(str.length); | ||
let idx = 0; | ||
str.split('').forEach(s => { | ||
res[idx] = s.charCodeAt(0); | ||
idx += 1; | ||
}); | ||
return res; | ||
}; | ||
export const concatUint8Arrays = (a1, a2) => { | ||
const res = new Uint8Array(a1.length + a2.length); | ||
res.set(a1); | ||
res.set(a2, a1.length); | ||
return res; | ||
}; |
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
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
89506
2039