-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved to tsup with checks for CJS & ESM import styles
- Loading branch information
Showing
10 changed files
with
1,062 additions
and
86 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
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,22 @@ | ||
const deoxysii = require("@oasisprotocol/deoxysii"); | ||
console.log("cjs", deoxysii.AEAD); | ||
|
||
// Define a key (ensure the size matches requirements) | ||
const key = crypto.getRandomValues(new Uint8Array(deoxysii.KeySize)); | ||
const aead = new deoxysii.AEAD(key); | ||
|
||
// Encryption | ||
const nonce = crypto.getRandomValues(new Uint8Array(deoxysii.NonceSize)); | ||
const plaintext = new TextEncoder().encode("Hello World"); | ||
const associatedData = new Uint8Array([0x1, 0x2, 0x3]); | ||
|
||
const encrypted = aead.encrypt(nonce, plaintext, associatedData); | ||
console.log("Encrypted:", encrypted); | ||
|
||
// Decryption | ||
try { | ||
const decrypted = aead.decrypt(nonce, encrypted, associatedData); | ||
console.log("Decrypted:", new TextDecoder().decode(decrypted)); | ||
} catch (error) { | ||
console.error("Decryption failed:", error); | ||
} |
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,30 @@ | ||
import * as deoxysii from "@oasisprotocol/deoxysii"; | ||
console.log("star", deoxysii.AEAD); | ||
|
||
import deoxysiiDefault from "@oasisprotocol/deoxysii"; | ||
console.log("default", deoxysiiDefault.AEAD); | ||
|
||
import { AEAD } from "@oasisprotocol/deoxysii"; | ||
console.log("AEAD", AEAD); | ||
|
||
import { KeySize, NonceSize } from "@oasisprotocol/deoxysii"; | ||
|
||
// Define a key (ensure the size matches requirements) | ||
const key = crypto.getRandomValues(new Uint8Array(KeySize)); | ||
const aead = new AEAD(key); | ||
|
||
// Encryption | ||
const nonce = crypto.getRandomValues(new Uint8Array(NonceSize)); | ||
const plaintext = new TextEncoder().encode("Hello World"); | ||
const associatedData = new Uint8Array([0x1, 0x2, 0x3]); | ||
|
||
const encrypted = aead.encrypt(nonce, plaintext, associatedData); | ||
console.log("Encrypted:", encrypted); | ||
|
||
// Decryption | ||
try { | ||
const decrypted = aead.decrypt(nonce, encrypted, associatedData); | ||
console.log("Decrypted:", new TextDecoder().decode(decrypted)); | ||
} catch (error) { | ||
console.error("Decryption failed:", error); | ||
} |
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
Oops, something went wrong.