-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update changelog; remove deprecated functions; replace with new ones;…
… promote functions
- Loading branch information
Showing
27 changed files
with
106 additions
and
391 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Submodule bindings
updated
9 files
+1 −1 | compiled/node_bindings/o1js_node.bc.map | |
+1,259 −1,261 | compiled/node_bindings/plonk_wasm.cjs | |
+471 −471 | compiled/node_bindings/plonk_wasm.d.cts | |
+ − | compiled/node_bindings/plonk_wasm_bg.wasm | |
+470 −470 | compiled/node_bindings/plonk_wasm_bg.wasm.d.ts | |
+965 −965 | compiled/web_bindings/plonk_wasm.d.ts | |
+1,559 −1,559 | compiled/web_bindings/plonk_wasm.js | |
+ − | compiled/web_bindings/plonk_wasm_bg.wasm | |
+385 −385 | compiled/web_bindings/plonk_wasm_bg.wasm.d.ts |
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 |
---|---|---|
@@ -1,90 +1,32 @@ | ||
import assert from 'assert'; | ||
import { | ||
Encryption, | ||
Encoding, | ||
Bytes, | ||
PrivateKey, | ||
Provable, | ||
initializeBindings, | ||
Encryption, | ||
Encoding, | ||
} from 'o1js'; | ||
|
||
await initializeBindings(); | ||
|
||
// generate keys | ||
let privateKey = PrivateKey.random(); | ||
let publicKey = privateKey.toPublicKey(); | ||
|
||
// message | ||
let message = 'This is a secret.'; | ||
let messageFields = Encoding.stringToFields(message); | ||
|
||
// encrypt | ||
let cipherText = Encryption.encrypt(messageFields, publicKey); | ||
|
||
// decrypt | ||
let decryptedFields = Encryption.decrypt(cipherText, privateKey); | ||
let decryptedMessage = Encoding.stringFromFields(decryptedFields); | ||
|
||
if (decryptedMessage !== message) throw Error('decryption failed'); | ||
console.log(`Original message: "${message}"`); | ||
console.log(`Recovered message: "${decryptedMessage}"`); | ||
|
||
// the same but in a checked computation | ||
|
||
await Provable.runAndCheck(() => { | ||
// encrypt | ||
let cipherText = Encryption.encrypt(messageFields, publicKey); | ||
|
||
// decrypt | ||
let decryptedFields = Encryption.decrypt(cipherText, privateKey); | ||
|
||
messageFields.forEach((m, i) => { | ||
m.assertEquals(decryptedFields[i]); | ||
}); | ||
}); | ||
|
||
// With a longer message | ||
message = JSON.stringify({ | ||
coinbase: { | ||
btc: 40000.0, | ||
eth: 3000.0, | ||
usdc: 1.0, | ||
ada: 1.02, | ||
avax: 70.43, | ||
mina: 2.13, | ||
}, | ||
binance: { | ||
btc: 39999.0, | ||
eth: 3001.0, | ||
usdc: 1.01, | ||
ada: 0.99, | ||
avax: 70.21, | ||
mina: 2.07, | ||
}, | ||
}); | ||
messageFields = Encoding.stringToFields(message); | ||
|
||
// encrypt | ||
cipherText = Encryption.encrypt(messageFields, publicKey); | ||
|
||
// decrypt | ||
decryptedFields = Encryption.decrypt(cipherText, privateKey); | ||
decryptedMessage = Encoding.stringFromFields(decryptedFields); | ||
|
||
if (decryptedMessage !== message) throw Error('decryption failed'); | ||
console.log(`Original message: "${message}"`); | ||
console.log(`Recovered message: "${decryptedMessage}"`); | ||
|
||
// the same but in a checked computation | ||
class Bytes256 extends Bytes(256) {} | ||
const priv = PrivateKey.random(); | ||
const pub = priv.toPublicKey(); | ||
|
||
await Provable.runAndCheck(() => { | ||
// encrypt | ||
let cipherText = Encryption.encrypt(messageFields, publicKey); | ||
const plainMsg = 'The quick brown fox jumped over the angry dog.'; | ||
|
||
// decrypt | ||
let decryptedFields = Encryption.decrypt(cipherText, privateKey); | ||
console.log('en/decryption of field elements'); | ||
const cipher2 = Encryption.encrypt(Encoding.stringToFields(plainMsg), pub); | ||
const plainText2 = Encryption.decrypt(cipher2, priv); | ||
|
||
messageFields.forEach((m, i) => { | ||
m.assertEquals(decryptedFields[i]); | ||
}); | ||
}); | ||
assert( | ||
Encoding.stringFromFields(plainText2) === plainMsg, | ||
'Plain message and decrypted message are the same' | ||
); | ||
|
||
console.log('everything works!'); | ||
console.log('en/decryption of bytes'); | ||
const message = Bytes256.fromString(plainMsg); | ||
console.log('plain message', plainMsg); | ||
const cipher = Encryption.encryptBytes(message, pub); | ||
const plainText = Encryption.decryptBytes(cipher, priv); | ||
console.log('decrypted message', Buffer.from(plainText.toBytes()).toString()); |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.