Comments (4)
The 'secret' returned from generateSigningKeyPair
is useful as the first 32 bytes are the derived x25519 secret for use with Sapphire.deriveSymmetricKey
. But, without a working CURVE25519_PUBLIC_KEY
operation I needed to convert the Ed25519 point to its montgomery coordinates (see js snippet below).
Have provided an example of client<->contract encryption at: https://gist.github.com/HarryR/eb5fd5fb77eda9f509cb94c91fe76fef
Using this method I am able to establish a known secret between contract and an ephemeral x25519 key.
const nacl = require('tweetnacl');
// XXX: why isn't this exported in nacl.lowlevel, field inversion is useful!
function inv25519(o, i) {
const {gf, S, M} = nacl.lowlevel;
var c = gf();
var a;
for (a = 0; a < 16; a++) c[a] = i[a];
for (a = 253; a >= 0; a--) {
S(c, c);
if(a !== 2 && a !== 4) M(c, c, i);
}
for (a = 0; a < 16; a++) o[a] = c[a];
}
/**
* convert ed25519 public key to its montgomery coordinate
*
* ed25519 is birationally equiv. to montgomery curve
*
* (u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)
* (x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))
*
* Examples:
* - https://github.com/StableLib/stablelib/blob/master/packages/ed25519/ed25519.ts#L861 (convertPublicKeyToX25519)
* - https://docs.rs/ed25519_to_curve25519/latest/src/ed25519_to_curve25519/lib.rs.html#1-108
*/
function ed25519_public_to_mont25519(publicKey) {
const {gf, pack25519, unpack25519, A, Z, M} = nacl.lowlevel;
var AY = gf();
unpack25519(AY, publicKey);
var one_minus_y = gf([1]);
Z(one_minus_y, one_minus_y, AY);
inv25519(one_minus_y, one_minus_y);
var x = gf([1]);
A(x, x, AY);
M(x, x, one_minus_y);
var o = new Uint8Array(32);
pack25519(o, x);
return o;
}
from oasis-sdk.
Thanks for your report and interest in confidential contracts! I see that you are using the sapphire-dev
image which is currently using Sapphire 0.4.0 (the version also deployed on Mainnet). The CURVE25519_PUBLIC_KEY
operation has only been added in 0.5.0-testnet (which is currently deployed on Sapphire Testnet).
Can you test the operation out on Sapphire Testnet (parameters, faucet) and report back?
from oasis-sdk.
Ah.
Modifying the following parameters similar to https://github.com/oasisprotocol/oasis-web3-gateway/pull/375/files so I can run 0.5.0 locally has fixed the problem. Existing tests work and the CURVE25519_PUBLIC_KEY
builtin works as expected.
ENV OASIS_CORE_VERSION=22.2.7
ENV PARATIME_VERSION=0.5.0-testnet
from oasis-sdk.
Thanks for confirming!
from oasis-sdk.
Related Issues (20)
- Problem with oasis cli comands HOT 2
- Implement IBC
- ts-web: crashes in the latest npm published version @oasisprotocol/client 0.1.0-alpha9 HOT 7
- Rewards & Commissions HOT 4
- Hello World testnet Cipher contract is returning an insufficient balance to pay fees error HOT 4
- Random failures with contracts on sapphire-dev HOT 1
- hdkey: save seed for use in multiple derivations HOT 2
- ts-web: crypto libraries review
- EVM: Gas Evaporation Opcode - raise gas usage to constant value HOT 1
- EVM: add ECADD, ECMUL & ECPAIRING opcodes for Ethereum ZK compatibility
- EVM: add SEC P256 R1 family to generation, signing & verification HOT 2
- Not compatible with pre-EIP155 transactions HOT 1
- what does OASIS SDK have to do with Parcel? HOT 1
- TPS benchmark
- EVM: revert data is not handled uniformly
- Add support for consensus pool:common and pool:fee-accumulator HOT 1
- Can I run test on Apple M1 chip?
- When I deploy a contract, Oasis reports " Execution failed with error: module: contracts code: 30 message: module uses floating point data or operations"" HOT 2
- how to find the exact reason for "unreachable executed" error. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oasis-sdk.