Skip to content

Latest commit

 

History

History
90 lines (55 loc) · 2.28 KB

File metadata and controls

90 lines (55 loc) · 2.28 KB

5.2 Simple Electronic Signature with a Self Signed Certificate in your DDO

Use cases

Takes the given data, converts it to an alphabetically sorted JSON object and signs its content using the given wallet.

Tools

The Commercio SDK, our own open source tool to format transactions to Commercio.network

Functions and APIs

  • SignHelper signSorted.
  • CertificateHelper getPem (only for Kotlin).

Background

From Wikipedia:

In cryptography and computer security, a self-signed certificate is a certificate that is not signed by a certificate authority (CA). Privacy-Enhanced Mail (PEM) is a de facto file format for storing and sending cryptographic keys, certificates, and other data, based on a set of 1993 IETF standards defining "privacy-enhanced mail.

Step by step sequence

Dart

  1. Execute the SignHelper signSorted to sign your data.

Kotlin

signSorted

  1. Generate the wallet;
  2. Execute the SignHelper signSorted to sign your data. The resulting byte array represents the signature in ASN.1 DER format.

getPEM

  1. Generate the wallet;
  2. Generate rsaKeyPair using KeysHelper generateRsaKeyPair;
  3. Create an X509 certificate using the given keyPair and walletAddress;
  4. Execute CertificateHelper getPem to get PEM representation of the given certificate.

Code Examples

Here's an example of the implemetation in all the available languages.

Dart

final data = {
  "name": "John",
  "surname": "Smith",
  "email": "[email protected]"
};

await SignHelper.signSorted(data, wallet);

Kotlin

signSorted

val data ="\"name\": \"John\", \"surname\": \"Smith\",\"email\": \"[email protected]\""

val wallet = Wallet.derive(mnemonic, networkInfo)

val signedData = SignHelper.signSorted(data, wallet)

getPEM

val wallet = Wallet.derive(mnemonic, networkInfo)

val rsaKeyPair = KeysHelper.generateRsaKeyPair()

val certificate = CertificateHelper.x509certificateFromWallet(wallet.bech32Address, rsaKeyPair)

val pemCertificate = CertificateHelper.getPem(certificate)

C#

var wallet = commercio.sacco.lib.Wallet.derive(mnemonic, networkInfo);

var data = "{'name': 'John', 'surname': 'Smith', 'email': '[email protected]'}";

var res = commercio.sdk.SignHelper.signSorted(data, wallet);