@optimystic/quereus-plugin-crypto 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -279
- package/dist/index.js +27 -59
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +20 -12
- package/dist/plugin.js +32 -30
- package/dist/plugin.js.map +1 -1
- package/package.json +82 -70
- package/src/crypto.ts +15 -20
- package/src/digest.ts +4 -4
- package/src/plugin.ts +93 -87
- package/src/sign.ts +16 -26
- package/src/signature-valid.ts +15 -32
package/src/signature-valid.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Compatible with React Native and all JS environments.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
10
|
-
import { p256 } from '@noble/curves/nist';
|
|
11
|
-
import { ed25519 } from '@noble/curves/ed25519';
|
|
12
|
-
import { hexToBytes } from '@noble/curves/
|
|
9
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
10
|
+
import { p256 } from '@noble/curves/nist.js';
|
|
11
|
+
import { ed25519 } from '@noble/curves/ed25519.js';
|
|
12
|
+
import { hexToBytes } from '@noble/curves/utils.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Supported elliptic curve types
|
|
@@ -72,40 +72,23 @@ function detectSignatureFormat(signature: Uint8Array, curve: CurveType): 'compac
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Parse signature based on format and curve
|
|
75
|
+
* Parse signature based on format and curve.
|
|
76
|
+
* In @noble/curves v2.0.1, uses Signature.fromBytes(bytes, format).
|
|
76
77
|
*/
|
|
77
|
-
function parseSignature(signature: Uint8Array, format: 'compact' | 'der' | 'raw', curve: CurveType):
|
|
78
|
+
function parseSignature(signature: Uint8Array, format: 'compact' | 'der' | 'raw', curve: CurveType): Uint8Array {
|
|
78
79
|
if (curve === 'ed25519') {
|
|
79
80
|
// Ed25519 signatures are always raw 64-byte format
|
|
80
81
|
return signature;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
// For ECDSA curves
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
break;
|
|
92
|
-
|
|
93
|
-
case 'der':
|
|
94
|
-
if (curve === 'secp256k1') {
|
|
95
|
-
return secp256k1.Signature.fromDER(signature);
|
|
96
|
-
} else if (curve === 'p256') {
|
|
97
|
-
return p256.Signature.fromDER(signature);
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
|
|
101
|
-
case 'raw':
|
|
102
|
-
// Treat as compact for ECDSA
|
|
103
|
-
if (curve === 'secp256k1') {
|
|
104
|
-
return secp256k1.Signature.fromCompact(signature);
|
|
105
|
-
} else if (curve === 'p256') {
|
|
106
|
-
return p256.Signature.fromCompact(signature);
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
84
|
+
// For ECDSA curves in v2.0.1, verify() accepts raw bytes directly
|
|
85
|
+
// The format parameter is used to parse signature bytes into the expected format
|
|
86
|
+
const sigFormat = format === 'raw' ? 'compact' : format;
|
|
87
|
+
|
|
88
|
+
if (curve === 'secp256k1') {
|
|
89
|
+
return secp256k1.Signature.fromBytes(signature, sigFormat).toBytes();
|
|
90
|
+
} else if (curve === 'p256') {
|
|
91
|
+
return p256.Signature.fromBytes(signature, sigFormat).toBytes();
|
|
109
92
|
}
|
|
110
93
|
|
|
111
94
|
throw new Error(`Failed to parse signature for curve ${curve} with format ${format}`);
|