aboutsummaryrefslogtreecommitdiffstats
path: root/library/sodium-plus/lib/keytypes
diff options
context:
space:
mode:
Diffstat (limited to 'library/sodium-plus/lib/keytypes')
-rw-r--r--library/sodium-plus/lib/keytypes/ed25519pk.js28
-rw-r--r--library/sodium-plus/lib/keytypes/ed25519sk.js29
-rw-r--r--library/sodium-plus/lib/keytypes/x25519pk.js29
-rw-r--r--library/sodium-plus/lib/keytypes/x25519sk.js29
4 files changed, 115 insertions, 0 deletions
diff --git a/library/sodium-plus/lib/keytypes/ed25519pk.js b/library/sodium-plus/lib/keytypes/ed25519pk.js
new file mode 100644
index 000000000..4c6dd911e
--- /dev/null
+++ b/library/sodium-plus/lib/keytypes/ed25519pk.js
@@ -0,0 +1,28 @@
+const CryptographyKey = require('../cryptography-key');
+
+class Ed25519PublicKey extends CryptographyKey {
+ constructor(buf) {
+ if (buf.length !== 32) {
+ throw new Error('Ed25519 public keys must be 32 bytes long');
+ }
+ super(buf);
+ this.keyType = 'ed25519';
+ this.publicKey = true;
+ }
+ /**
+ * @return {Ed25519PublicKey}
+ */
+ static from() {
+ return new Ed25519PublicKey(Buffer.from(...arguments));
+ }
+
+ isEd25519Key() {
+ return true;
+ }
+
+ isPublicKey() {
+ return true;
+ }
+}
+
+module.exports = Ed25519PublicKey;
diff --git a/library/sodium-plus/lib/keytypes/ed25519sk.js b/library/sodium-plus/lib/keytypes/ed25519sk.js
new file mode 100644
index 000000000..3c67286c2
--- /dev/null
+++ b/library/sodium-plus/lib/keytypes/ed25519sk.js
@@ -0,0 +1,29 @@
+const CryptographyKey = require('../cryptography-key');
+
+class Ed25519SecretKey extends CryptographyKey {
+ constructor(buf) {
+ if (buf.length !== 64) {
+ throw new Error('Ed25519 secret keys must be 64 bytes long');
+ }
+ super(buf);
+ this.keyType = 'ed25519';
+ this.publicKey = false;
+ }
+
+ /**
+ * @return {Ed25519SecretKey}
+ */
+ static from() {
+ return new Ed25519SecretKey(Buffer.from(...arguments));
+ }
+
+ isEd25519Key() {
+ return true;
+ }
+
+ isPublicKey() {
+ return false;
+ }
+}
+
+module.exports = Ed25519SecretKey; \ No newline at end of file
diff --git a/library/sodium-plus/lib/keytypes/x25519pk.js b/library/sodium-plus/lib/keytypes/x25519pk.js
new file mode 100644
index 000000000..322c899f8
--- /dev/null
+++ b/library/sodium-plus/lib/keytypes/x25519pk.js
@@ -0,0 +1,29 @@
+const CryptographyKey = require('../cryptography-key');
+
+class X25519PublicKey extends CryptographyKey {
+ constructor(buf) {
+ if (buf.length !== 32) {
+ throw new Error('X25519 public keys must be 32 bytes long');
+ }
+ super(buf);
+ this.keyType = 'x25519';
+ this.publicKey = true;
+ }
+
+ /**
+ * @return {X25519PublicKey}
+ */
+ static from() {
+ return new X25519PublicKey(Buffer.from(...arguments));
+ }
+
+ isX25519Key() {
+ return true;
+ }
+
+ isPublicKey() {
+ return true;
+ }
+}
+
+module.exports = X25519PublicKey;
diff --git a/library/sodium-plus/lib/keytypes/x25519sk.js b/library/sodium-plus/lib/keytypes/x25519sk.js
new file mode 100644
index 000000000..8b8016f83
--- /dev/null
+++ b/library/sodium-plus/lib/keytypes/x25519sk.js
@@ -0,0 +1,29 @@
+const CryptographyKey = require('../cryptography-key');
+
+class X25519SecretKey extends CryptographyKey {
+ constructor(buf) {
+ if (buf.length !== 32) {
+ throw new Error('X25519 secret keys must be 32 bytes long');
+ }
+ super(buf);
+ this.keyType = 'x25519';
+ this.publicKey = false;
+ }
+
+ /**
+ * @return {X25519SecretKey}
+ */
+ static from() {
+ return new X25519SecretKey(Buffer.from(...arguments));
+ }
+
+ isX25519Key() {
+ return true;
+ }
+
+ isPublicKey() {
+ return false;
+ }
+}
+
+module.exports = X25519SecretKey;