@d9-network/spec 1.2.5 → 1.3.0
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/dist/index.cjs +46 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.mts +34 -1
- package/dist/index.mjs +46 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -7983,9 +7983,9 @@ var compactEnc = (input) => {
|
|
|
7983
7983
|
return result;
|
|
7984
7984
|
};
|
|
7985
7985
|
var compact = createCodec(compactEnc, compactDec);
|
|
7986
|
-
var textEncoder = new TextEncoder();
|
|
7986
|
+
var textEncoder$1 = new TextEncoder();
|
|
7987
7987
|
var strEnc = (str2) => {
|
|
7988
|
-
const val = textEncoder.encode(str2);
|
|
7988
|
+
const val = textEncoder$1.encode(str2);
|
|
7989
7989
|
return mergeUint8([compact.enc(val.length), val]);
|
|
7990
7990
|
};
|
|
7991
7991
|
var textDecoder = new TextDecoder();
|
|
@@ -10396,6 +10396,48 @@ function toD9Address(address) {
|
|
|
10396
10396
|
return toNetworkAddress(address, D9_SS58_PREFIX);
|
|
10397
10397
|
}
|
|
10398
10398
|
|
|
10399
|
+
//#endregion
|
|
10400
|
+
//#region src/wallet/verify.ts
|
|
10401
|
+
const textEncoder = new TextEncoder();
|
|
10402
|
+
/**
|
|
10403
|
+
* Verify an SR25519 signature
|
|
10404
|
+
*
|
|
10405
|
+
* @param signature - The signature as a hex string or Uint8Array (64 bytes)
|
|
10406
|
+
* @param message - The message that was signed (string or Uint8Array)
|
|
10407
|
+
* @param publicKey - The public key to verify against (32 bytes)
|
|
10408
|
+
* @returns True if the signature is valid
|
|
10409
|
+
*
|
|
10410
|
+
* @example
|
|
10411
|
+
* ```typescript
|
|
10412
|
+
* const publicKey = ss58DecodePublicKey(address);
|
|
10413
|
+
* const isValid = sr25519Verify(signature, message, publicKey);
|
|
10414
|
+
* ```
|
|
10415
|
+
*/
|
|
10416
|
+
function sr25519Verify(signature, message, publicKey) {
|
|
10417
|
+
const sigBytes = typeof signature === "string" ? isHexString(signature) ? hexToBytes(signature) : hexToBytes(`0x${signature}`) : signature;
|
|
10418
|
+
const msgBytes = typeof message === "string" ? textEncoder.encode(message) : message;
|
|
10419
|
+
return _polkadot_labs_hdkd_helpers.sr25519.verify(sigBytes, msgBytes, publicKey);
|
|
10420
|
+
}
|
|
10421
|
+
/**
|
|
10422
|
+
* Verify an SR25519 signature against a wallet address
|
|
10423
|
+
*
|
|
10424
|
+
* Convenience function that decodes the SS58 address and verifies in one step.
|
|
10425
|
+
*
|
|
10426
|
+
* @param walletAddress - The SS58 wallet address
|
|
10427
|
+
* @param signature - The signature as a hex string or Uint8Array
|
|
10428
|
+
* @param message - The message that was signed
|
|
10429
|
+
* @returns True if the signature is valid
|
|
10430
|
+
*
|
|
10431
|
+
* @example
|
|
10432
|
+
* ```typescript
|
|
10433
|
+
* const isValid = verifyWalletSignature(address, signature, message);
|
|
10434
|
+
* ```
|
|
10435
|
+
*/
|
|
10436
|
+
function verifyWalletSignature(walletAddress, signature, message) {
|
|
10437
|
+
const [publicKey] = (0, _polkadot_labs_hdkd_helpers.ss58Decode)(walletAddress);
|
|
10438
|
+
return sr25519Verify(signature, message, publicKey);
|
|
10439
|
+
}
|
|
10440
|
+
|
|
10399
10441
|
//#endregion
|
|
10400
10442
|
//#region src/utils/balance.ts
|
|
10401
10443
|
/**
|
|
@@ -10811,9 +10853,11 @@ exports.sr25519AddressFromKeypair = sr25519AddressFromKeypair;
|
|
|
10811
10853
|
exports.sr25519AddressFromSecretKeyHex = sr25519AddressFromSecretKeyHex;
|
|
10812
10854
|
exports.sr25519DeriveFromMiniSecret = sr25519DeriveFromMiniSecret;
|
|
10813
10855
|
exports.sr25519KeypairFromMiniSecret = sr25519KeypairFromMiniSecret;
|
|
10856
|
+
exports.sr25519Verify = sr25519Verify;
|
|
10814
10857
|
exports.ss58DecodePublicKey = ss58DecodePublicKey;
|
|
10815
10858
|
exports.ss58Reencode = ss58Reencode;
|
|
10816
10859
|
exports.toD9Address = toD9Address;
|
|
10817
10860
|
exports.toNetworkAddress = toNetworkAddress;
|
|
10818
10861
|
exports.validateMnemonic = validateMnemonic;
|
|
10862
|
+
exports.verifyWalletSignature = verifyWalletSignature;
|
|
10819
10863
|
//# sourceMappingURL=index.cjs.map
|