sonr/crypto/internal/point.go
Prad Nukala 807b2e86ec
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>
2025-01-06 17:06:10 +00:00

45 lines
957 B
Go
Executable File

//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package internal
import (
"crypto/elliptic"
"math/big"
"filippo.io/edwards25519"
)
func CalcFieldSize(curve elliptic.Curve) int {
bits := curve.Params().BitSize
return (bits + 7) / 8
}
func ReverseScalarBytes(inBytes []byte) []byte {
outBytes := make([]byte, len(inBytes))
for i, j := 0, len(inBytes)-1; j >= 0; i, j = i+1, j-1 {
outBytes[i] = inBytes[j]
}
return outBytes
}
func BigInt2Ed25519Point(y *big.Int) (*edwards25519.Point, error) {
b := y.Bytes()
var arr [32]byte
copy(arr[32-len(b):], b)
return edwards25519.NewIdentityPoint().SetBytes(arr[:])
}
func BigInt2Ed25519Scalar(x *big.Int) (*edwards25519.Scalar, error) {
// big.Int is big endian; ed25519 assumes little endian encoding
kBytes := ReverseScalarBytes(x.Bytes())
var arr [32]byte
copy(arr[:], kBytes)
return edwards25519.NewScalar().SetCanonicalBytes(arr[:])
}