mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 10:21:40 +00:00
feature/1220 origin handle exists method (#1241)
* feat: add docs and CI workflow for publishing to onsonr.dev * (refactor): Move hway,motr executables to their own repos * feat: simplify devnet and testnet configurations * refactor: update import path for didcrypto package * docs(networks): Add README with project overview, architecture, and community links * refactor: Move network configurations to deploy directory * build: update golang version to 1.23 * refactor: move logger interface to appropriate package * refactor: Move devnet configuration to networks/devnet * chore: improve release process with date variable * (chore): Move Crypto Library * refactor: improve code structure and readability in DID module * feat: integrate Trunk CI checks * ci: optimize CI workflow by removing redundant build jobs --------- Co-authored-by: Darp Alakun <i@prad.nu>
This commit is contained in:
Executable
+77
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright Coinbase, Inc. All Rights Reserved.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package bbs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/onsonr/sonr/crypto/core/curves"
|
||||
)
|
||||
|
||||
// MessageGenerators are used to sign a vector of commitments for
|
||||
// a BBS+ signature. These must be the same generators used by
|
||||
// sign, verify, prove, and open
|
||||
//
|
||||
// These are generated in a deterministic manner. By using
|
||||
// MessageGenerators in this way, the generators do not need to be
|
||||
// stored alongside the public key and the same key can be used to sign
|
||||
// an arbitrary number of messages
|
||||
// Generators are created by computing
|
||||
// H_i = H_G1(W || I2OSP(0, 4) || I2OSP(0, 1) || I2OSP(length, 4))
|
||||
// where I2OSP means Integer to Octet Stream Primitive and
|
||||
// I2OSP represents an integer in a statically sized byte array.
|
||||
// `W` is the BBS+ public key.
|
||||
// Internally we store the 201 byte state since the only value that changes
|
||||
// is the index
|
||||
type MessageGenerators struct {
|
||||
// Blinding factor generator, stored, so we know what points to return in `Get`
|
||||
h0 curves.PairingPoint
|
||||
length int
|
||||
state [201]byte
|
||||
}
|
||||
|
||||
// Init set the message generators to the default state
|
||||
func (msgg *MessageGenerators) Init(w *PublicKey, length int) (*MessageGenerators, error) {
|
||||
if length < 0 {
|
||||
return nil, errors.New("length should be nonnegative")
|
||||
}
|
||||
msgg.length = length
|
||||
for i := range msgg.state {
|
||||
msgg.state[i] = 0
|
||||
}
|
||||
copy(msgg.state[:192], w.value.ToAffineUncompressed())
|
||||
msgg.state[197] = byte(length >> 24)
|
||||
msgg.state[198] = byte(length >> 16)
|
||||
msgg.state[199] = byte(length >> 8)
|
||||
msgg.state[200] = byte(length)
|
||||
var ok bool
|
||||
msgg.h0, ok = w.value.OtherGroup().Hash(msgg.state[:]).(curves.PairingPoint)
|
||||
if !ok {
|
||||
return nil, errors.New("incorrect type conversion")
|
||||
}
|
||||
|
||||
return msgg, nil
|
||||
}
|
||||
|
||||
func (msgg MessageGenerators) Get(i int) curves.PairingPoint {
|
||||
if i <= 0 {
|
||||
return msgg.h0
|
||||
}
|
||||
if i > msgg.length {
|
||||
return nil
|
||||
}
|
||||
state := msgg.state
|
||||
state[193] = byte(i >> 24)
|
||||
state[194] = byte(i >> 16)
|
||||
state[195] = byte(i >> 8)
|
||||
state[196] = byte(i)
|
||||
point, ok := msgg.h0.Hash(msgg.state[:]).(curves.PairingPoint)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return point
|
||||
}
|
||||
Reference in New Issue
Block a user