@meshsdk/core-cst 1.7.14 → 1.7.16
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 +134 -2
- package/dist/index.d.cts +45 -2
- package/dist/index.d.ts +45 -2
- package/dist/index.js +133 -2
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1021,6 +1021,7 @@ __export(src_exports, {
|
|
|
1021
1021
|
mergeValue: () => mergeValue,
|
|
1022
1022
|
negateValue: () => negateValue,
|
|
1023
1023
|
negatives: () => negatives,
|
|
1024
|
+
normalizePlutusScript: () => normalizePlutusScript,
|
|
1024
1025
|
resolveDataHash: () => resolveDataHash,
|
|
1025
1026
|
resolveNativeScriptAddress: () => resolveNativeScriptAddress,
|
|
1026
1027
|
resolveNativeScriptHash: () => resolveNativeScriptHash,
|
|
@@ -1129,6 +1130,9 @@ var DRepID = import_core.Cardano.DRepID;
|
|
|
1129
1130
|
var DRep = import_core.Serialization.DRep;
|
|
1130
1131
|
var StakeCredentialStatus = import_core.Cardano.StakeCredentialStatus;
|
|
1131
1132
|
|
|
1133
|
+
// src/message-signing/check-signature.ts
|
|
1134
|
+
var import_bip32ed25519 = require("@stricahq/bip32ed25519");
|
|
1135
|
+
|
|
1132
1136
|
// src/message-signing/cose-sign1.ts
|
|
1133
1137
|
var import_buffer = require("buffer");
|
|
1134
1138
|
var import_blakejs = __toESM(require_blakejs(), 1);
|
|
@@ -1273,8 +1277,66 @@ var getCoseKeyFromPublicKey = (cbor) => {
|
|
|
1273
1277
|
};
|
|
1274
1278
|
|
|
1275
1279
|
// src/message-signing/check-signature.ts
|
|
1276
|
-
var checkSignature = (data, { key, signature }) => {
|
|
1280
|
+
var checkSignature = (data, { key, signature }, address) => {
|
|
1277
1281
|
const builder = CoseSign1.fromCbor(signature);
|
|
1282
|
+
const publicKeyBuffer = getPublicKeyFromCoseKey(key);
|
|
1283
|
+
if (address) {
|
|
1284
|
+
let network = NetworkId.Mainnet;
|
|
1285
|
+
const paymentAddress = BaseAddress.fromAddress(Address.fromBech32(address));
|
|
1286
|
+
const coseSign1PublicKey = new import_bip32ed25519.Bip32PublicKey(publicKeyBuffer);
|
|
1287
|
+
const credential = {
|
|
1288
|
+
hash: Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1289
|
+
Ed25519KeyHashHex2(
|
|
1290
|
+
coseSign1PublicKey.toPublicKey().hash().toString("hex")
|
|
1291
|
+
)
|
|
1292
|
+
),
|
|
1293
|
+
type: 0
|
|
1294
|
+
};
|
|
1295
|
+
if (address.startsWith("addr")) {
|
|
1296
|
+
if (address.startsWith("addr_test1")) {
|
|
1297
|
+
network = NetworkId.Testnet;
|
|
1298
|
+
}
|
|
1299
|
+
const stakeCredential = paymentAddress?.getStakeCredential();
|
|
1300
|
+
if (stakeCredential) {
|
|
1301
|
+
const paymentAddressBech32 = BaseAddress.fromCredentials(
|
|
1302
|
+
network,
|
|
1303
|
+
credential,
|
|
1304
|
+
stakeCredential
|
|
1305
|
+
).toAddress().toBech32();
|
|
1306
|
+
if (address !== paymentAddressBech32) {
|
|
1307
|
+
const extractedRewardAddress = RewardAddress.fromCredentials(
|
|
1308
|
+
network,
|
|
1309
|
+
stakeCredential
|
|
1310
|
+
).toAddress().toBech32();
|
|
1311
|
+
const rewardAddress = RewardAddress.fromCredentials(
|
|
1312
|
+
network,
|
|
1313
|
+
credential
|
|
1314
|
+
).toAddress().toBech32();
|
|
1315
|
+
if (rewardAddress !== extractedRewardAddress) {
|
|
1316
|
+
return false;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
} else {
|
|
1320
|
+
const enterpriseAddress = EnterpriseAddress.fromCredentials(
|
|
1321
|
+
network,
|
|
1322
|
+
credential
|
|
1323
|
+
).toAddress().toBech32();
|
|
1324
|
+
if (enterpriseAddress !== address) {
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
} else if (address.startsWith("stake")) {
|
|
1329
|
+
if (address.startsWith("stake_test1")) {
|
|
1330
|
+
network = NetworkId.Testnet;
|
|
1331
|
+
}
|
|
1332
|
+
const rewardAddress = RewardAddress.fromCredentials(network, credential).toAddress().toBech32();
|
|
1333
|
+
if (rewardAddress !== address) {
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1278
1340
|
if (builder.getPayload() === null) {
|
|
1279
1341
|
return false;
|
|
1280
1342
|
}
|
|
@@ -1282,7 +1344,7 @@ var checkSignature = (data, { key, signature }) => {
|
|
|
1282
1344
|
return false;
|
|
1283
1345
|
}
|
|
1284
1346
|
return builder.verifySignature({
|
|
1285
|
-
publicKeyBuffer
|
|
1347
|
+
publicKeyBuffer
|
|
1286
1348
|
});
|
|
1287
1349
|
};
|
|
1288
1350
|
|
|
@@ -2681,6 +2743,75 @@ var CardanoSDKSerializer = class {
|
|
|
2681
2743
|
};
|
|
2682
2744
|
};
|
|
2683
2745
|
|
|
2746
|
+
// src/plutus-tools/index.ts
|
|
2747
|
+
var import_plutus_data = require("@harmoniclabs/plutus-data");
|
|
2748
|
+
var import_uplc = require("@harmoniclabs/uplc");
|
|
2749
|
+
var import_cbor = require("@harmoniclabs/cbor");
|
|
2750
|
+
var supportedPlutusCoreVersions = [
|
|
2751
|
+
{
|
|
2752
|
+
version: [1, 0, 0],
|
|
2753
|
+
language: "Plutus V1"
|
|
2754
|
+
},
|
|
2755
|
+
{
|
|
2756
|
+
version: [1, 1, 0],
|
|
2757
|
+
language: "Plutus V3"
|
|
2758
|
+
}
|
|
2759
|
+
];
|
|
2760
|
+
var normalizePlutusScript = (plutusScript, encoding) => {
|
|
2761
|
+
const bytes = Buffer.from(plutusScript, "hex");
|
|
2762
|
+
const purePlutusBytes = getPurePlutusBytes(bytes);
|
|
2763
|
+
const normalizedBytes = applyEncoding(purePlutusBytes, encoding);
|
|
2764
|
+
return Buffer.from(normalizedBytes).toString("hex");
|
|
2765
|
+
};
|
|
2766
|
+
var hasSupportedPlutusVersion = (plutusScript) => {
|
|
2767
|
+
if (plutusScript.length < 3) {
|
|
2768
|
+
return false;
|
|
2769
|
+
}
|
|
2770
|
+
const version = [plutusScript[0], plutusScript[1], plutusScript[2]];
|
|
2771
|
+
return supportedPlutusCoreVersions.some((supportedVersion) => {
|
|
2772
|
+
return supportedVersion.version[0] === version[0] && supportedVersion.version[1] === version[1] && supportedVersion.version[2] === version[2];
|
|
2773
|
+
});
|
|
2774
|
+
};
|
|
2775
|
+
var getPurePlutusBytes = (plutusScript) => {
|
|
2776
|
+
let unwrappedScript = plutusScript;
|
|
2777
|
+
let length = 0;
|
|
2778
|
+
try {
|
|
2779
|
+
while (unwrappedScript.length >= 3 && length != unwrappedScript.length) {
|
|
2780
|
+
length = unwrappedScript.length;
|
|
2781
|
+
if (hasSupportedPlutusVersion(unwrappedScript)) {
|
|
2782
|
+
return unwrappedScript;
|
|
2783
|
+
}
|
|
2784
|
+
const cbor = import_cbor.Cbor.parse(unwrappedScript);
|
|
2785
|
+
if (cbor instanceof import_cbor.CborBytes) {
|
|
2786
|
+
unwrappedScript = cbor.bytes;
|
|
2787
|
+
} else {
|
|
2788
|
+
break;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
console.error("Error parsing Plutus script:", error);
|
|
2793
|
+
}
|
|
2794
|
+
if (hasSupportedPlutusVersion(unwrappedScript)) {
|
|
2795
|
+
return unwrappedScript;
|
|
2796
|
+
}
|
|
2797
|
+
throw new Error("Unsupported Plutus version or invalid Plutus script bytes");
|
|
2798
|
+
};
|
|
2799
|
+
var applyCborEncoding = (plutusScript) => {
|
|
2800
|
+
return import_cbor.Cbor.encode(new import_cbor.CborBytes(plutusScript)).toBuffer();
|
|
2801
|
+
};
|
|
2802
|
+
var applyEncoding = (plutusScript, outputEncoding) => {
|
|
2803
|
+
switch (outputEncoding) {
|
|
2804
|
+
case "SingleCBOR":
|
|
2805
|
+
return applyCborEncoding(plutusScript);
|
|
2806
|
+
case "DoubleCBOR":
|
|
2807
|
+
return applyCborEncoding(applyCborEncoding(plutusScript));
|
|
2808
|
+
case "PurePlutusScriptBytes":
|
|
2809
|
+
return plutusScript;
|
|
2810
|
+
default:
|
|
2811
|
+
return applyCborEncoding(plutusScript);
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
|
|
2684
2815
|
// src/index.ts
|
|
2685
2816
|
var CardanoSDKUtil = __toESM(require("@cardano-sdk/util"), 1);
|
|
2686
2817
|
var Crypto3 = __toESM(require("@cardano-sdk/crypto"), 1);
|
|
@@ -2813,6 +2944,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
|
|
|
2813
2944
|
mergeValue,
|
|
2814
2945
|
negateValue,
|
|
2815
2946
|
negatives,
|
|
2947
|
+
normalizePlutusScript,
|
|
2816
2948
|
resolveDataHash,
|
|
2817
2949
|
resolveNativeScriptAddress,
|
|
2818
2950
|
resolveNativeScriptHash,
|
package/dist/index.d.cts
CHANGED
|
@@ -220,7 +220,8 @@ type Signer = {
|
|
|
220
220
|
key: StricaPrivateKey;
|
|
221
221
|
};
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
/** @param address - Optional Bech32 string of a stake, stake_test1, addr, or addr_test1 address. If provided, this function will validate the signer's address against this value. */
|
|
224
|
+
declare const checkSignature: (data: string, { key, signature }: DataSignature, address?: string) => boolean;
|
|
224
225
|
|
|
225
226
|
declare class CoseSign1 {
|
|
226
227
|
private protectedMap;
|
|
@@ -366,4 +367,46 @@ declare function negatives(v: Value): Value;
|
|
|
366
367
|
declare function assetTypes(v: Value): number;
|
|
367
368
|
declare function empty(v: Value): boolean;
|
|
368
369
|
|
|
369
|
-
|
|
370
|
+
/**
|
|
371
|
+
* MIT License
|
|
372
|
+
*
|
|
373
|
+
* Copyright (c) 2024 Evgenii Lisitskii
|
|
374
|
+
*
|
|
375
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
376
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
377
|
+
* in the Software without restriction, including without limitation the rights
|
|
378
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
379
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
380
|
+
* furnished to do so, subject to the following conditions:
|
|
381
|
+
*
|
|
382
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
383
|
+
* copies or substantial portions of the Software.
|
|
384
|
+
*
|
|
385
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
386
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
387
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
388
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
389
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
390
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
391
|
+
* SOFTWARE.
|
|
392
|
+
*/
|
|
393
|
+
type OutputEncoding = "SingleCBOR" | "DoubleCBOR" | "PurePlutusScriptBytes";
|
|
394
|
+
/**
|
|
395
|
+
* Normalizes a Plutus script by extracting its pure Plutus bytes and applying a specified encoding.
|
|
396
|
+
*
|
|
397
|
+
* @param {Uint8Array} plutusScript - The Plutus script to be normalized as a Uint8Array.
|
|
398
|
+
* @param {OutputEncoding} encoding - The desired encoding for the output.
|
|
399
|
+
* @returns {Uint8Array} The normalized Plutus script.
|
|
400
|
+
*
|
|
401
|
+
* @description
|
|
402
|
+
* This function performs the following steps:
|
|
403
|
+
* 1. Extracts the pure Plutus bytes in hex from the input script.
|
|
404
|
+
* 2. Applies the specified encoding to the pure Plutus bytes.
|
|
405
|
+
*
|
|
406
|
+
* @note
|
|
407
|
+
* - This function is useful for standardizing the format of Plutus scripts, ensuring they are in a consistent state for further processing or comparison.
|
|
408
|
+
* - The normalization process does not modify the logical content of the script, only its representation.
|
|
409
|
+
*/
|
|
410
|
+
declare const normalizePlutusScript: (plutusScript: string, encoding: OutputEncoding) => string;
|
|
411
|
+
|
|
412
|
+
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, CardanoSDKSerializer, CborSet, CborWriter, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, StricaBip32PrivateKey, StricaBip32PrivateKey as StricaBip32PrivateKeyType, StricaBip32PublicKey, StricaBip32PublicKey as StricaBip32PublicKeyType, StricaDecoder, StricaEncoder, StricaPrivateKey, StricaPrivateKey as StricaPrivateKeyType, StricaPublicKey, StricaPublicKey as StricaPublicKeyType, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, Value, VkeyWitness, VrfVkBech32, type Witness, addressToBech32, assetTypes, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, checkSignature, deserializeAddress, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromNativeScript, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getPublicKeyFromCoseKey, mergeValue, negateValue, negatives, normalizePlutusScript, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, signData, subValue, toAddress, toBaseAddress, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -220,7 +220,8 @@ type Signer = {
|
|
|
220
220
|
key: StricaPrivateKey;
|
|
221
221
|
};
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
/** @param address - Optional Bech32 string of a stake, stake_test1, addr, or addr_test1 address. If provided, this function will validate the signer's address against this value. */
|
|
224
|
+
declare const checkSignature: (data: string, { key, signature }: DataSignature, address?: string) => boolean;
|
|
224
225
|
|
|
225
226
|
declare class CoseSign1 {
|
|
226
227
|
private protectedMap;
|
|
@@ -366,4 +367,46 @@ declare function negatives(v: Value): Value;
|
|
|
366
367
|
declare function assetTypes(v: Value): number;
|
|
367
368
|
declare function empty(v: Value): boolean;
|
|
368
369
|
|
|
369
|
-
|
|
370
|
+
/**
|
|
371
|
+
* MIT License
|
|
372
|
+
*
|
|
373
|
+
* Copyright (c) 2024 Evgenii Lisitskii
|
|
374
|
+
*
|
|
375
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
376
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
377
|
+
* in the Software without restriction, including without limitation the rights
|
|
378
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
379
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
380
|
+
* furnished to do so, subject to the following conditions:
|
|
381
|
+
*
|
|
382
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
383
|
+
* copies or substantial portions of the Software.
|
|
384
|
+
*
|
|
385
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
386
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
387
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
388
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
389
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
390
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
391
|
+
* SOFTWARE.
|
|
392
|
+
*/
|
|
393
|
+
type OutputEncoding = "SingleCBOR" | "DoubleCBOR" | "PurePlutusScriptBytes";
|
|
394
|
+
/**
|
|
395
|
+
* Normalizes a Plutus script by extracting its pure Plutus bytes and applying a specified encoding.
|
|
396
|
+
*
|
|
397
|
+
* @param {Uint8Array} plutusScript - The Plutus script to be normalized as a Uint8Array.
|
|
398
|
+
* @param {OutputEncoding} encoding - The desired encoding for the output.
|
|
399
|
+
* @returns {Uint8Array} The normalized Plutus script.
|
|
400
|
+
*
|
|
401
|
+
* @description
|
|
402
|
+
* This function performs the following steps:
|
|
403
|
+
* 1. Extracts the pure Plutus bytes in hex from the input script.
|
|
404
|
+
* 2. Applies the specified encoding to the pure Plutus bytes.
|
|
405
|
+
*
|
|
406
|
+
* @note
|
|
407
|
+
* - This function is useful for standardizing the format of Plutus scripts, ensuring they are in a consistent state for further processing or comparison.
|
|
408
|
+
* - The normalization process does not modify the logical content of the script, only its representation.
|
|
409
|
+
*/
|
|
410
|
+
declare const normalizePlutusScript: (plutusScript: string, encoding: OutputEncoding) => string;
|
|
411
|
+
|
|
412
|
+
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, CardanoSDKSerializer, CborSet, CborWriter, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, StricaBip32PrivateKey, StricaBip32PrivateKey as StricaBip32PrivateKeyType, StricaBip32PublicKey, StricaBip32PublicKey as StricaBip32PublicKeyType, StricaDecoder, StricaEncoder, StricaPrivateKey, StricaPrivateKey as StricaPrivateKeyType, StricaPublicKey, StricaPublicKey as StricaPublicKeyType, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, Value, VkeyWitness, VrfVkBech32, type Witness, addressToBech32, assetTypes, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, checkSignature, deserializeAddress, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromNativeScript, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getPublicKeyFromCoseKey, mergeValue, negateValue, negatives, normalizePlutusScript, resolveDataHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, signData, subValue, toAddress, toBaseAddress, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue };
|
package/dist/index.js
CHANGED
|
@@ -970,6 +970,9 @@ var DRepID = Cardano.DRepID;
|
|
|
970
970
|
var DRep = Serialization.DRep;
|
|
971
971
|
var StakeCredentialStatus = Cardano.StakeCredentialStatus;
|
|
972
972
|
|
|
973
|
+
// src/message-signing/check-signature.ts
|
|
974
|
+
import { Bip32PublicKey } from "@stricahq/bip32ed25519";
|
|
975
|
+
|
|
973
976
|
// src/message-signing/cose-sign1.ts
|
|
974
977
|
var import_blakejs = __toESM(require_blakejs(), 1);
|
|
975
978
|
import { Buffer as Buffer2 } from "buffer";
|
|
@@ -1114,8 +1117,66 @@ var getCoseKeyFromPublicKey = (cbor) => {
|
|
|
1114
1117
|
};
|
|
1115
1118
|
|
|
1116
1119
|
// src/message-signing/check-signature.ts
|
|
1117
|
-
var checkSignature = (data, { key, signature }) => {
|
|
1120
|
+
var checkSignature = (data, { key, signature }, address) => {
|
|
1118
1121
|
const builder = CoseSign1.fromCbor(signature);
|
|
1122
|
+
const publicKeyBuffer = getPublicKeyFromCoseKey(key);
|
|
1123
|
+
if (address) {
|
|
1124
|
+
let network = NetworkId.Mainnet;
|
|
1125
|
+
const paymentAddress = BaseAddress.fromAddress(Address.fromBech32(address));
|
|
1126
|
+
const coseSign1PublicKey = new Bip32PublicKey(publicKeyBuffer);
|
|
1127
|
+
const credential = {
|
|
1128
|
+
hash: Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1129
|
+
Ed25519KeyHashHex2(
|
|
1130
|
+
coseSign1PublicKey.toPublicKey().hash().toString("hex")
|
|
1131
|
+
)
|
|
1132
|
+
),
|
|
1133
|
+
type: 0
|
|
1134
|
+
};
|
|
1135
|
+
if (address.startsWith("addr")) {
|
|
1136
|
+
if (address.startsWith("addr_test1")) {
|
|
1137
|
+
network = NetworkId.Testnet;
|
|
1138
|
+
}
|
|
1139
|
+
const stakeCredential = paymentAddress?.getStakeCredential();
|
|
1140
|
+
if (stakeCredential) {
|
|
1141
|
+
const paymentAddressBech32 = BaseAddress.fromCredentials(
|
|
1142
|
+
network,
|
|
1143
|
+
credential,
|
|
1144
|
+
stakeCredential
|
|
1145
|
+
).toAddress().toBech32();
|
|
1146
|
+
if (address !== paymentAddressBech32) {
|
|
1147
|
+
const extractedRewardAddress = RewardAddress.fromCredentials(
|
|
1148
|
+
network,
|
|
1149
|
+
stakeCredential
|
|
1150
|
+
).toAddress().toBech32();
|
|
1151
|
+
const rewardAddress = RewardAddress.fromCredentials(
|
|
1152
|
+
network,
|
|
1153
|
+
credential
|
|
1154
|
+
).toAddress().toBech32();
|
|
1155
|
+
if (rewardAddress !== extractedRewardAddress) {
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
} else {
|
|
1160
|
+
const enterpriseAddress = EnterpriseAddress.fromCredentials(
|
|
1161
|
+
network,
|
|
1162
|
+
credential
|
|
1163
|
+
).toAddress().toBech32();
|
|
1164
|
+
if (enterpriseAddress !== address) {
|
|
1165
|
+
return false;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
} else if (address.startsWith("stake")) {
|
|
1169
|
+
if (address.startsWith("stake_test1")) {
|
|
1170
|
+
network = NetworkId.Testnet;
|
|
1171
|
+
}
|
|
1172
|
+
const rewardAddress = RewardAddress.fromCredentials(network, credential).toAddress().toBech32();
|
|
1173
|
+
if (rewardAddress !== address) {
|
|
1174
|
+
return false;
|
|
1175
|
+
}
|
|
1176
|
+
} else {
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1119
1180
|
if (builder.getPayload() === null) {
|
|
1120
1181
|
return false;
|
|
1121
1182
|
}
|
|
@@ -1123,7 +1184,7 @@ var checkSignature = (data, { key, signature }) => {
|
|
|
1123
1184
|
return false;
|
|
1124
1185
|
}
|
|
1125
1186
|
return builder.verifySignature({
|
|
1126
|
-
publicKeyBuffer
|
|
1187
|
+
publicKeyBuffer
|
|
1127
1188
|
});
|
|
1128
1189
|
};
|
|
1129
1190
|
|
|
@@ -2527,6 +2588,75 @@ var CardanoSDKSerializer = class {
|
|
|
2527
2588
|
};
|
|
2528
2589
|
};
|
|
2529
2590
|
|
|
2591
|
+
// src/plutus-tools/index.ts
|
|
2592
|
+
import { dataFromCbor } from "@harmoniclabs/plutus-data";
|
|
2593
|
+
import { parseUPLC, Application, UPLCProgram, UPLCConst, encodeUPLC } from "@harmoniclabs/uplc";
|
|
2594
|
+
import { Cbor, CborBytes } from "@harmoniclabs/cbor";
|
|
2595
|
+
var supportedPlutusCoreVersions = [
|
|
2596
|
+
{
|
|
2597
|
+
version: [1, 0, 0],
|
|
2598
|
+
language: "Plutus V1"
|
|
2599
|
+
},
|
|
2600
|
+
{
|
|
2601
|
+
version: [1, 1, 0],
|
|
2602
|
+
language: "Plutus V3"
|
|
2603
|
+
}
|
|
2604
|
+
];
|
|
2605
|
+
var normalizePlutusScript = (plutusScript, encoding) => {
|
|
2606
|
+
const bytes = Buffer.from(plutusScript, "hex");
|
|
2607
|
+
const purePlutusBytes = getPurePlutusBytes(bytes);
|
|
2608
|
+
const normalizedBytes = applyEncoding(purePlutusBytes, encoding);
|
|
2609
|
+
return Buffer.from(normalizedBytes).toString("hex");
|
|
2610
|
+
};
|
|
2611
|
+
var hasSupportedPlutusVersion = (plutusScript) => {
|
|
2612
|
+
if (plutusScript.length < 3) {
|
|
2613
|
+
return false;
|
|
2614
|
+
}
|
|
2615
|
+
const version = [plutusScript[0], plutusScript[1], plutusScript[2]];
|
|
2616
|
+
return supportedPlutusCoreVersions.some((supportedVersion) => {
|
|
2617
|
+
return supportedVersion.version[0] === version[0] && supportedVersion.version[1] === version[1] && supportedVersion.version[2] === version[2];
|
|
2618
|
+
});
|
|
2619
|
+
};
|
|
2620
|
+
var getPurePlutusBytes = (plutusScript) => {
|
|
2621
|
+
let unwrappedScript = plutusScript;
|
|
2622
|
+
let length = 0;
|
|
2623
|
+
try {
|
|
2624
|
+
while (unwrappedScript.length >= 3 && length != unwrappedScript.length) {
|
|
2625
|
+
length = unwrappedScript.length;
|
|
2626
|
+
if (hasSupportedPlutusVersion(unwrappedScript)) {
|
|
2627
|
+
return unwrappedScript;
|
|
2628
|
+
}
|
|
2629
|
+
const cbor = Cbor.parse(unwrappedScript);
|
|
2630
|
+
if (cbor instanceof CborBytes) {
|
|
2631
|
+
unwrappedScript = cbor.bytes;
|
|
2632
|
+
} else {
|
|
2633
|
+
break;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
} catch (error) {
|
|
2637
|
+
console.error("Error parsing Plutus script:", error);
|
|
2638
|
+
}
|
|
2639
|
+
if (hasSupportedPlutusVersion(unwrappedScript)) {
|
|
2640
|
+
return unwrappedScript;
|
|
2641
|
+
}
|
|
2642
|
+
throw new Error("Unsupported Plutus version or invalid Plutus script bytes");
|
|
2643
|
+
};
|
|
2644
|
+
var applyCborEncoding = (plutusScript) => {
|
|
2645
|
+
return Cbor.encode(new CborBytes(plutusScript)).toBuffer();
|
|
2646
|
+
};
|
|
2647
|
+
var applyEncoding = (plutusScript, outputEncoding) => {
|
|
2648
|
+
switch (outputEncoding) {
|
|
2649
|
+
case "SingleCBOR":
|
|
2650
|
+
return applyCborEncoding(plutusScript);
|
|
2651
|
+
case "DoubleCBOR":
|
|
2652
|
+
return applyCborEncoding(applyCborEncoding(plutusScript));
|
|
2653
|
+
case "PurePlutusScriptBytes":
|
|
2654
|
+
return plutusScript;
|
|
2655
|
+
default:
|
|
2656
|
+
return applyCborEncoding(plutusScript);
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
|
|
2530
2660
|
// src/index.ts
|
|
2531
2661
|
import * as CardanoSDKUtil from "@cardano-sdk/util";
|
|
2532
2662
|
import * as Crypto3 from "@cardano-sdk/crypto";
|
|
@@ -2658,6 +2788,7 @@ export {
|
|
|
2658
2788
|
mergeValue,
|
|
2659
2789
|
negateValue,
|
|
2660
2790
|
negatives,
|
|
2791
|
+
normalizePlutusScript,
|
|
2661
2792
|
resolveDataHash,
|
|
2662
2793
|
resolveNativeScriptAddress,
|
|
2663
2794
|
resolveNativeScriptHash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/core-cst",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"@harmoniclabs/cbor": "1.3.0",
|
|
43
43
|
"@harmoniclabs/plutus-data": "1.2.4",
|
|
44
44
|
"@harmoniclabs/uplc": "1.2.4",
|
|
45
|
-
"@meshsdk/common": "1.7.
|
|
45
|
+
"@meshsdk/common": "1.7.16",
|
|
46
46
|
"@stricahq/bip32ed25519": "^1.1.0",
|
|
47
|
-
"@stricahq/cbors": "^1.0.
|
|
47
|
+
"@stricahq/cbors": "^1.0.3",
|
|
48
48
|
"pbkdf2": "^3.1.2"
|
|
49
49
|
},
|
|
50
50
|
"prettier": "@meshsdk/configs/prettier",
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"blockchain",
|
|
60
60
|
"sdk"
|
|
61
61
|
]
|
|
62
|
-
}
|
|
62
|
+
}
|