This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
583 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/keys/keys.proto.js |
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 |
---|---|---|
|
@@ -43,3 +43,4 @@ test/test-data/go-ipfs-repo/LOG.old | |
|
||
# while testing npm5 | ||
package-lock.json | ||
yarn.lock |
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,55 @@ | ||
'use strict' | ||
|
||
const asm = require('asmcrypto.js') | ||
const setImmediate = require('async/setImmediate') | ||
|
||
exports.create = function (key, iv, callback) { | ||
const done = (err, res) => setImmediate(() => callback(err, res)) | ||
|
||
if (key.length !== 16 && key.length !== 32) { | ||
return done(new Error('Invalid key length')) | ||
} | ||
|
||
const enc = new asm.AES_CTR.Encrypt({ | ||
key: key, | ||
nonce: iv | ||
}) | ||
const dec = new asm.AES_CTR.Decrypt({ | ||
key: key, | ||
nonce: iv | ||
}) | ||
|
||
const res = { | ||
encrypt (data, cb) { | ||
const done = (err, res) => setImmediate(() => cb(err, res)) | ||
|
||
let res | ||
try { | ||
res = Buffer.from( | ||
enc.process(data).result | ||
) | ||
} catch (err) { | ||
return done(err) | ||
} | ||
|
||
done(null, res) | ||
}, | ||
|
||
decrypt (data, cb) { | ||
const done = (err, res) => setImmediate(() => cb(err, res)) | ||
|
||
let res | ||
try { | ||
res = Buffer.from( | ||
dec.process(data).result | ||
) | ||
} catch (err) { | ||
return done(err) | ||
} | ||
|
||
done(null, res) | ||
} | ||
} | ||
|
||
done(null, res) | ||
} |
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
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,15 @@ | ||
enum KeyType { | ||
RSA = 0; | ||
Ed25519 = 1; | ||
Secp256k1 = 2; | ||
} | ||
|
||
message PublicKey { | ||
required KeyType Type = 1; | ||
required bytes Data = 2; | ||
} | ||
|
||
message PrivateKey { | ||
required KeyType Type = 1; | ||
required bytes Data = 2; | ||
} |
Oops, something went wrong.