@meshsdk/core-cst 1.7.15 → 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 +63 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +63 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1130,6 +1130,9 @@ var DRepID = import_core.Cardano.DRepID;
|
|
|
1130
1130
|
var DRep = import_core.Serialization.DRep;
|
|
1131
1131
|
var StakeCredentialStatus = import_core.Cardano.StakeCredentialStatus;
|
|
1132
1132
|
|
|
1133
|
+
// src/message-signing/check-signature.ts
|
|
1134
|
+
var import_bip32ed25519 = require("@stricahq/bip32ed25519");
|
|
1135
|
+
|
|
1133
1136
|
// src/message-signing/cose-sign1.ts
|
|
1134
1137
|
var import_buffer = require("buffer");
|
|
1135
1138
|
var import_blakejs = __toESM(require_blakejs(), 1);
|
|
@@ -1274,8 +1277,66 @@ var getCoseKeyFromPublicKey = (cbor) => {
|
|
|
1274
1277
|
};
|
|
1275
1278
|
|
|
1276
1279
|
// src/message-signing/check-signature.ts
|
|
1277
|
-
var checkSignature = (data, { key, signature }) => {
|
|
1280
|
+
var checkSignature = (data, { key, signature }, address) => {
|
|
1278
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
|
+
}
|
|
1279
1340
|
if (builder.getPayload() === null) {
|
|
1280
1341
|
return false;
|
|
1281
1342
|
}
|
|
@@ -1283,7 +1344,7 @@ var checkSignature = (data, { key, signature }) => {
|
|
|
1283
1344
|
return false;
|
|
1284
1345
|
}
|
|
1285
1346
|
return builder.verifySignature({
|
|
1286
|
-
publicKeyBuffer
|
|
1347
|
+
publicKeyBuffer
|
|
1287
1348
|
});
|
|
1288
1349
|
};
|
|
1289
1350
|
|
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;
|
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;
|
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
|
|
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,7 +42,7 @@
|
|
|
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
47
|
"@stricahq/cbors": "^1.0.3",
|
|
48
48
|
"pbkdf2": "^3.1.2"
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"blockchain",
|
|
60
60
|
"sdk"
|
|
61
61
|
]
|
|
62
|
-
}
|
|
62
|
+
}
|