Skip to main content

Module iota::group_ops

Generic Move and native functions for group operations.

use iota::address; use iota::bcs; use iota::hex; use std::ascii; use std::bcs; use std::option; use std::string; use std::vector;

Module Functions

pub(pkg) add

public(package) fun add<G>(type_: u8, e1: &iota::group_ops::Element<G>, e2: &iota::group_ops::Element<G>): iota::group_ops::Element<G>

Implementation

public(package) fun add<G>(type_: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {     Element<G> { bytes: internal_add(type_, &e1.bytes, &e2.bytes) } }

pub(pkg) convert

public(package) fun convert<From, To>(from_type_: u8, to_type_: u8, e: &iota::group_ops::Element<From>): iota::group_ops::Element<To>

Implementation

public(package) fun convert<From, To>(     from_type_: u8,     to_type_: u8,     e: &Element<From>, ): Element<To> {     Element<To> { bytes: internal_convert(from_type_, to_type_, &e.bytes) } }

pub(pkg) div

Fails if scalar = 0. Else returns 1/scalar * e.

public(package) fun div<S, G>(type_: u8, scalar: &iota::group_ops::Element<S>, e: &iota::group_ops::Element<G>): iota::group_ops::Element<G>

Implementation

public(package) fun div<S, G>(type_: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {     Element<G> { bytes: internal_div(type_, &scalar.bytes, &e.bytes) } }

pub(pkg) from_bytes

public(package) fun from_bytes<G>(type_: u8, bytes: &vector, is_trusted: bool): iota::group_ops::Element<G>

Implementation

public(package) fun from_bytes<G>(type_: u8, bytes: &vector, is_trusted: bool): Element<G> {     assert!(is_trusted || internal_validate(type_, bytes), EInvalidInput);     Element<G> { bytes: *bytes } }

pub(pkg) hash_to

public(package) fun hash_to<G>(type_: u8, m: &vector): iota::group_ops::Element<G>

Implementation

public(package) fun hash_to<G>(type_: u8, m: &vector): Element<G> {     Element<G> { bytes: internal_hash_to(type_, m) } }

pub(pkg) mul

public(package) fun mul<S, G>(type_: u8, scalar: &iota::group_ops::Element<S>, e: &iota::group_ops::Element<G>): iota::group_ops::Element<G>

Implementation

public(package) fun mul<S, G>(type_: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {     Element<G> { bytes: internal_mul(type_, &scalar.bytes, &e.bytes) } }

pub(pkg) multi_scalar_multiplication

Aborts with EInputTooLong if the vectors are too long.

public(package) fun multi_scalar_multiplication<S, G>(type_: u8, scalars: &vector<iota::group_ops::Element<S>>, elements: &vector<iota::group_ops::Element<G>>): iota::group_ops::Element<G>

Implementation

public(package) fun multi_scalar_multiplication<S, G>(     type_: u8,     scalars: &vector<Element<S>>,     elements: &vector<Element<G>>, ): Element<G> {     assert!(scalars.length() > 0, EInvalidInput);     assert!(scalars.length() == elements.length(), EInvalidInput);     let mut scalars_bytes: vector<u8> = vector[];     let mut elements_bytes: vector<u8> = vector[];     let mut i = 0;     while (i < scalars.length()) {         let scalar_vec = scalars[i];         scalars_bytes.append(scalar_vec.bytes);         let element_vec = elements[i];         elements_bytes.append(element_vec.bytes);         i = i + 1;     };     Element<G> { bytes: internal_multi_scalar_mul(type_, &scalars_bytes, &elements_bytes) } }

pub(pkg) pairing

public(package) fun pairing<G1, G2, G3>(type_: u8, e1: &iota::group_ops::Element<G1>, e2: &iota::group_ops::Element<G2>): iota::group_ops::Element<G3>

Implementation

public(package) fun pairing<G1, G2, G3>(     type_: u8,     e1: &Element<G1>,     e2: &Element<G2>, ): Element<G3> {     Element<G3> { bytes: internal_pairing(type_, &e1.bytes, &e2.bytes) } }

pub(pkg) set_as_prefix

public(package) fun set_as_prefix(x: u64, big_endian: bool, buffer: &mut vector<u8>)

Implementation

public(package) fun set_as_prefix(x: u64, big_endian: bool, buffer: &mut vector<u8>) {     let buffer_len = buffer.length();     assert!(buffer_len > 7, EInvalidBufferLength);     let x_as_bytes = bcs::to_bytes(&x); // little endian     let mut i = 0;     while (i < 8) {         let position = if (big_endian) { buffer_len - i - 1 } else { i };         *(&mut buffer[position]) = x_as_bytes[i];         i = i + 1;     }; }

pub(pkg) sub

public(package) fun sub<G>(type_: u8, e1: &iota::group_ops::Element<G>, e2: &iota::group_ops::Element<G>): iota::group_ops::Element<G>

Implementation

public(package) fun sub<G>(type_: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {     Element<G> { bytes: internal_sub(type_, &e1.bytes, &e2.bytes) } }

pub(pkg) sum

public(package) fun sum<G>(type_: u8, terms: &vector<iota::group_ops::Element<G>>): iota::group_ops::Element<G>

Implementation

public(package) fun sum<G>(type_: u8, terms: &vector<Element<G>>): Element<G> {     Element<G> { bytes: internal_sum(type_, &(*terms).map!(|x| x.bytes)) } }

prv internal_add

fun internal_add(type_: u8, e1: &vector, e2: &vector): vector<u8>

Implementation

native fun internal_add(type_: u8, e1: &vector, e2: &vector): vector<u8>;

prv internal_convert

fun internal_convert(from_type_: u8, to_type_: u8, e: &vector): vector<u8>

Implementation

native fun internal_convert(from_type_: u8, to_type_: u8, e: &vector): vector<u8>;

prv internal_div

fun internal_div(type_: u8, e1: &vector, e2: &vector): vector<u8>

Implementation

native fun internal_div(type_: u8, e1: &vector, e2: &vector): vector<u8>;

prv internal_hash_to

fun internal_hash_to(type_: u8, m: &vector): vector<u8>

Implementation

native fun internal_hash_to(type_: u8, m: &vector): vector<u8>;

prv internal_mul

fun internal_mul(type_: u8, e1: &vector, e2: &vector): vector<u8>

Implementation

native fun internal_mul(type_: u8, e1: &vector, e2: &vector): vector<u8>;

prv internal_multi_scalar_mul

fun internal_multi_scalar_mul(type_: u8, scalars: &vector, elements: &vector): vector<u8>

Implementation

native fun internal_multi_scalar_mul(     type_: u8,     scalars: &vector,     elements: &vector, ): vector<u8>;

prv internal_pairing

fun internal_pairing(type_: u8, e1: &vector, e2: &vector): vector<u8>

Implementation

native fun internal_pairing(type_: u8, e1: &vector, e2: &vector): vector<u8>;

prv internal_sub

fun internal_sub(type_: u8, e1: &vector, e2: &vector): vector<u8>

Implementation

native fun internal_sub(type_: u8, e1: &vector, e2: &vector): vector<u8>;

prv internal_sum

fun internal_sum(type_: u8, e: &vector>): vector<u8>

Implementation

native fun internal_sum(type_: u8, e: &vector>): vector<u8>;

prv internal_validate

fun internal_validate(type_: u8, bytes: &vector): bool

Implementation

native fun internal_validate(type_: u8, bytes: &vector): bool;

Structs

struct Element

public struct Element<phantom T> has copy, drop, store

Fields
bytes: vector<u8>

pub bytes

public fun bytes<G>(e: &iota::group_ops::Element<G>): &vector

Implementation

public fun bytes<G>(e: &Element<G>): &vector {     &e.bytes }

pub equal

public fun equal<G>(e1: &iota::group_ops::Element<G>, e2: &iota::group_ops::Element<G>): bool

Implementation

public fun equal<G>(e1: &Element<G>, e2: &Element<G>): bool {     &e1.bytes == &e2.bytes }

Constants

err ENotSupported

const ENotSupported: u64 = 0;

err EInvalidInput

const EInvalidInput: u64 = 1;

err EInputTooLong

const EInputTooLong: u64 = 2;

err EInvalidBufferLength

const EInvalidBufferLength: u64 = 3;