Skip to content

Commit c1e5420

Browse files
committed
Updated deps, added initial index.d.ts
1 parent f8f6947 commit c1e5420

File tree

5 files changed

+4392
-9758
lines changed

5 files changed

+4392
-9758
lines changed

Diff for: ellipticcurve/ecdsa.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const sha256 = require("js-sha256");
21
const BigInt = require("big-integer");
32

43
const EcdsaMath = require("./math");
@@ -7,13 +6,16 @@ const BinaryAscii = require("./utils/binary");
76
const Integer = require("./utils/integer");
87
const randomInteger = Integer.between;
98
const modulo = Integer.modulo;
9+
import * as Crypto from 'expo-crypto';
1010

1111

1212
exports.sign = async function (message, privateKey, hashfunc = null, randNum = null) {
1313
if (hashfunc == null) {
14-
hashfunc = sha256;
14+
hashfunc = async (message) => {
15+
return await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, message);
16+
};
1517
}
16-
let hashMessage = hashfunc(message);
18+
let hashMessage = await hashfunc(message);
1719
let numberMessage = BinaryAscii.numberFromHex(hashMessage);
1820
let curve = privateKey.curve;
1921
if (randNum == null) {
@@ -26,8 +28,13 @@ exports.sign = async function (message, privateKey, hashfunc = null, randNum = n
2628
};
2729

2830

29-
exports.verify = function (message, signature, publicKey, hashfunc=sha256) {
30-
let hashMessage = hashfunc(message);
31+
exports.verify = async function (message, signature, publicKey, hashfunc = null) {
32+
if (hashfunc == null) {
33+
hashfunc = async (message) => {
34+
return await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, message);
35+
};
36+
}
37+
let hashMessage = await hashfunc(message);
3138
let numberMessage = BinaryAscii.numberFromHex(hashMessage);
3239
let curve = publicKey.curve;
3340
let sigR = signature.r;

Diff for: ellipticcurve/utils/integer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// based on random-number-csprng: https://www.npmjs.com/package/random-number-csprng
22

33
const BigInt = require("big-integer");
4-
import * as Random from 'expo-random';
4+
import * as Crypto from 'expo-crypto';
55

66

77

@@ -49,7 +49,7 @@ function calculateParameters(range) {
4949

5050

5151
async function secureRandomNumber(minimum, maximum) { // bigint, bigint
52-
52+
5353
if (maximum.lesserOrEquals(minimum)) {
5454
throw new Error("The maximum value must be higher than the minimum value.")
5555
};
@@ -66,7 +66,7 @@ async function secureRandomNumber(minimum, maximum) { // bigint, bigint
6666

6767
let {bitsNeeded, bytesNeeded, mask} = calculateParameters(range);
6868

69-
let randomBytes = await Random.getRandomBytesAsync(bytesNeeded);
69+
let randomBytes = await Crypto.getRandomBytesAsync(bytesNeeded);
7070

7171
var randomValue = BigInt(0);
7272

Diff for: index.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
declare module 'starkbank-ecdsa' {
2+
export module Ecdsa {
3+
export async function sign(message: string, privateKey: PrivateKey, hashfunc: (s: string) => string = null, randNum: string = null): Signature;
4+
export async function verify(message: string, signature: Signature, publicKey: PublicKey, hashfunc: (s: string) => string = null): bool;
5+
}
6+
export class PublicKey {
7+
static fromPem(publicKeyPem: string);
8+
}
9+
export class PrivateKey {
10+
static fromPem(publicKeyPem: string);
11+
}
12+
export class Signature {
13+
toDer();
14+
toBase64();
15+
static fromBase64(s: string);
16+
}
17+
}

0 commit comments

Comments
 (0)