@meshsdk/core-cst 1.6.0-alpha.11

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.
@@ -0,0 +1,243 @@
1
+ import type { OpaqueString } from "@cardano-sdk/util";
2
+ import { Cardano, Serialization } from "@cardano-sdk/core";
3
+ import * as Crypto from "@cardano-sdk/crypto";
4
+ import { typedHex } from "@cardano-sdk/util";
5
+
6
+ export const Slot = Cardano.Slot;
7
+ export type Slot = Cardano.Slot;
8
+
9
+ export const Value = Serialization.Value;
10
+ export type Value = Serialization.Value;
11
+
12
+ export type TokenMap = Cardano.TokenMap;
13
+
14
+ export const Transaction = Serialization.Transaction;
15
+ export type Transaction = Serialization.Transaction;
16
+
17
+ export const TransactionId = Cardano.TransactionId;
18
+ export type TransactionId = Cardano.TransactionId;
19
+
20
+ export const TransactionBody = Serialization.TransactionBody;
21
+ export type TransactionBody = Serialization.TransactionBody;
22
+
23
+ export const TransactionWitnessSet = Serialization.TransactionWitnessSet;
24
+ export type TransactionWitnessSet = Serialization.TransactionWitnessSet;
25
+
26
+ export const TransactionUnspentOutput = Serialization.TransactionUnspentOutput;
27
+ export type TransactionUnspentOutput = Serialization.TransactionUnspentOutput;
28
+
29
+ export const TransactionInput = Serialization.TransactionInput;
30
+ export type TransactionInput = Serialization.TransactionInput;
31
+
32
+ export const TransactionOutput = Serialization.TransactionOutput;
33
+ export type TransactionOutput = Serialization.TransactionOutput;
34
+
35
+ export type TransactionInputSet = Serialization.CborSet<
36
+ ReturnType<TransactionInput["toCore"]>,
37
+ TransactionInput
38
+ >;
39
+
40
+ export type TransactionWitnessPlutusData = Set<PlutusData>;
41
+
42
+ export const PlutusData = Serialization.PlutusData;
43
+ export type PlutusData = Serialization.PlutusData;
44
+
45
+ export const PlutusList = Serialization.PlutusList;
46
+ export type PlutusList = Serialization.PlutusList;
47
+
48
+ export const PlutusMap = Serialization.PlutusMap;
49
+ export type PlutusMap = Serialization.PlutusMap;
50
+
51
+ export const Redeemers = Serialization.Redeemers;
52
+ export type Redeemers = Serialization.Redeemers;
53
+
54
+ export const Redeemer = Serialization.Redeemer;
55
+ export type Redeemer = Serialization.Redeemer;
56
+
57
+ export const RedeemerPurpose = Cardano.RedeemerPurpose;
58
+ export type RedeemerPurpose = Cardano.RedeemerPurpose;
59
+
60
+ export const RedeemerTag = Serialization.RedeemerTag;
61
+ export type RedeemerTag = Serialization.RedeemerTag;
62
+
63
+ export const Script = Serialization.Script;
64
+ export type Script = Serialization.Script;
65
+
66
+ export const PolicyId = Cardano.PolicyId;
67
+ export type PolicyId = Cardano.PolicyId;
68
+
69
+ export const AssetName = Cardano.AssetName;
70
+ export type AssetName = Cardano.AssetName;
71
+
72
+ export const AssetId = Cardano.AssetId;
73
+ export type AssetId = Cardano.AssetId;
74
+
75
+ export const ScriptHash = Crypto.Hash28ByteBase16;
76
+ export type ScriptHash = Crypto.Hash28ByteBase16;
77
+
78
+ export const Address = Cardano.Address;
79
+ export type Address = Cardano.Address;
80
+
81
+ export const RewardAddress = Cardano.RewardAddress;
82
+ export type RewardAddress = Cardano.RewardAddress;
83
+
84
+ export const AddressType = Cardano.AddressType;
85
+ export type AddressType = Cardano.AddressType;
86
+
87
+ export const BaseAddress = Cardano.BaseAddress;
88
+ export type BaseAddress = Cardano.BaseAddress;
89
+
90
+ export const EnterpriseAddress = Cardano.EnterpriseAddress;
91
+ export type EnterpriseAddress = Cardano.EnterpriseAddress;
92
+
93
+ export const PaymentAddress = Cardano.PaymentAddress;
94
+ export type PaymentAddress = Cardano.PaymentAddress;
95
+
96
+ export const AssetFingerprint = Cardano.AssetFingerprint;
97
+ export type AssetFingerprint = Cardano.AssetFingerprint;
98
+
99
+ export const Credential = Serialization.Credential;
100
+ export type Credential = Serialization.Credential;
101
+
102
+ export type CredentialCore = Cardano.Credential;
103
+
104
+ export const Ed25519PublicKeyHex = Crypto.Ed25519PublicKeyHex;
105
+ export type Ed25519PublicKeyHex = Crypto.Ed25519PublicKeyHex;
106
+
107
+ export type Ed25519PrivateNormalKeyHex = OpaqueString<"Ed25519PrivateKeyHex">;
108
+ export const Ed25519PrivateNormalKeyHex = (
109
+ value: string,
110
+ ): Ed25519PrivateNormalKeyHex => typedHex(value, 64);
111
+
112
+ export type Ed25519PrivateExtendedKeyHex = OpaqueString<"Ed25519PrivateKeyHex">;
113
+ export const Ed25519PrivateExtendedKeyHex = (
114
+ value: string,
115
+ ): Ed25519PrivateExtendedKeyHex => typedHex(value, 128);
116
+
117
+ export const Ed25519KeyHash = Crypto.Ed25519KeyHash;
118
+ export type Ed25519KeyHash = Crypto.Ed25519KeyHash;
119
+
120
+ export const Ed25519KeyHashHex = Crypto.Ed25519KeyHashHex;
121
+ export type Ed25519KeyHashHex = Crypto.Ed25519KeyHashHex;
122
+
123
+ export const Hash28ByteBase16 = Crypto.Hash28ByteBase16;
124
+ export type Hash28ByteBase16 = Crypto.Hash28ByteBase16;
125
+
126
+ export const Hash32ByteBase16 = Crypto.Hash32ByteBase16;
127
+ export type Hash32ByteBase16 = Crypto.Hash32ByteBase16;
128
+
129
+ export const CredentialType = Cardano.CredentialType;
130
+ export type CredentialType = Cardano.CredentialType;
131
+
132
+ export const Certificate = Serialization.Certificate;
133
+ export type Certificate = Serialization.Certificate;
134
+
135
+ export const PoolId = Cardano.PoolId;
136
+ export type PoolId = Cardano.PoolId;
137
+
138
+ export const StakeRegistration = Serialization.StakeRegistration;
139
+ export type StakeRegistration = Serialization.StakeRegistration;
140
+
141
+ export const StakeDelegation = Serialization.StakeDelegation;
142
+ export type StakeDelegation = Serialization.StakeDelegation;
143
+
144
+ export type StakeDelegationCertificate = Cardano.StakeDelegationCertificate;
145
+
146
+ export const CertificateType = Cardano.CertificateType;
147
+ export type CertificateType = Cardano.CertificateType;
148
+
149
+ export const VkeyWitness = Serialization.VkeyWitness;
150
+ export type VkeyWitness = Serialization.VkeyWitness;
151
+
152
+ export const Ed25519SignatureHex = Crypto.Ed25519SignatureHex;
153
+ export type Ed25519SignatureHex = Crypto.Ed25519SignatureHex;
154
+
155
+ export const Ed25519PublicKey = Crypto.Ed25519PublicKey;
156
+ export type Ed25519PublicKey = Crypto.Ed25519PublicKey;
157
+
158
+ export const Ed25519Signature = Crypto.Ed25519Signature;
159
+ export type Ed25519Signature = Crypto.Ed25519Signature;
160
+
161
+ export const Bip32PrivateKey = Crypto.Bip32PrivateKey;
162
+ export type Bip32PrivateKey = Crypto.Bip32PrivateKey;
163
+
164
+ export const Bip32PrivateKeyHex = Crypto.Bip32PrivateKeyHex;
165
+ export type Bip32PrivateKeyHex = Crypto.Bip32PrivateKeyHex;
166
+
167
+ export const PlutusLanguageVersion = Cardano.PlutusLanguageVersion;
168
+ export type PlutusLanguageVersion = Cardano.PlutusLanguageVersion;
169
+
170
+ export const NativeScript = Serialization.NativeScript;
171
+ export type NativeScript = Serialization.NativeScript;
172
+
173
+ export const PlutusV1Script = Serialization.PlutusV1Script;
174
+ export type PlutusV1Script = Serialization.PlutusV1Script;
175
+
176
+ export const PlutusV2Script = Serialization.PlutusV2Script;
177
+ export type PlutusV2Script = Serialization.PlutusV2Script;
178
+
179
+ export const PlutusV3Script = Serialization.PlutusV3Script;
180
+ export type PlutusV3Script = Serialization.PlutusV3Script;
181
+
182
+ export const Costmdls = Serialization.Costmdls;
183
+ export type Costmdls = Serialization.Costmdls;
184
+
185
+ export const CostModel = Serialization.CostModel;
186
+ export type CostModel = Serialization.CostModel;
187
+
188
+ export const CborWriter = Serialization.CborWriter;
189
+ export type CborWriter = Serialization.CborWriter;
190
+
191
+ export const ConstrPlutusData = Serialization.ConstrPlutusData;
192
+ export type ConstrPlutusData = Serialization.ConstrPlutusData;
193
+
194
+ export const RewardAccount = Cardano.RewardAccount;
195
+ export type RewardAccount = Cardano.RewardAccount;
196
+
197
+ export const Hash = Serialization.Hash;
198
+ export type Hash<T extends string> = Serialization.Hash<T>;
199
+
200
+ export const DatumHash = Crypto.Hash32ByteBase16;
201
+ export type DatumHash = Crypto.Hash32ByteBase16;
202
+
203
+ export const Datum = Serialization.Datum;
204
+ export type Datum = PlutusData | DatumHash;
205
+
206
+ export type CostModels = Cardano.CostModels;
207
+
208
+ export type ExUnits = Serialization.ExUnits;
209
+ export const ExUnits = Serialization.ExUnits;
210
+
211
+ export const NetworkId = Cardano.NetworkId;
212
+ export type NetworkId = Cardano.ChainId["networkId"];
213
+
214
+ export const DatumKind = Serialization.DatumKind;
215
+
216
+ export const CborSet = Serialization.CborSet;
217
+
218
+ export type Witness = Cardano.Witness;
219
+ export type Signatures = Cardano.Signatures;
220
+
221
+ export type RequireAllOf = Cardano.NativeScriptKind.RequireAllOf;
222
+ export const RequireAllOf = Cardano.NativeScriptKind.RequireAllOf;
223
+
224
+ export type RequireAnyOf = Cardano.NativeScriptKind.RequireAnyOf;
225
+ export const RequireAnyOf = Cardano.NativeScriptKind.RequireAnyOf;
226
+
227
+ export type RequireNOf = Cardano.NativeScriptKind.RequireNOf;
228
+ export const RequireNOf = Cardano.NativeScriptKind.RequireNOf;
229
+
230
+ export type RequireSignature = Cardano.NativeScriptKind.RequireSignature;
231
+ export const RequireSignature = Cardano.NativeScriptKind.RequireSignature;
232
+
233
+ export type RequireTimeAfter = Cardano.NativeScriptKind.RequireTimeAfter;
234
+ export const RequireTimeAfter = Cardano.NativeScriptKind.RequireTimeAfter;
235
+
236
+ export type RequireTimeBefore = Cardano.NativeScriptKind.RequireTimeBefore;
237
+ export const RequireTimeBefore = Cardano.NativeScriptKind.RequireTimeBefore;
238
+
239
+ export type VrfVkBech32 = Cardano.VrfVkBech32;
240
+ export const VrfVkBech32 = Cardano.VrfVkBech32;
241
+
242
+ export type ScriptPubkey = Serialization.ScriptPubkey;
243
+ export const ScriptPubkey = Serialization.ScriptPubkey;
@@ -0,0 +1,2 @@
1
+ export * from "./cardano-sdk";
2
+ export * from "./signer";
@@ -0,0 +1,7 @@
1
+ import { Address } from ".";
2
+ import { PrivateKey } from "../stricahq";
3
+
4
+ export type Signer = {
5
+ address: Address;
6
+ key: PrivateKey;
7
+ };
@@ -0,0 +1,130 @@
1
+ import { pbkdf2Sync } from "pbkdf2";
2
+
3
+ import { HARDENED_KEY_START } from "@meshsdk/common";
4
+
5
+ import {
6
+ PrivateKey,
7
+ Bip32PrivateKey as StricahqBip32PrivateKey,
8
+ } from "../stricahq";
9
+ import {
10
+ BaseAddress,
11
+ Bip32PrivateKey,
12
+ CredentialType,
13
+ Ed25519KeyHash,
14
+ Ed25519KeyHashHex,
15
+ EnterpriseAddress,
16
+ Hash28ByteBase16,
17
+ NativeScript,
18
+ RewardAddress,
19
+ ScriptPubkey,
20
+ } from "../types";
21
+
22
+ export const buildBaseAddress = (
23
+ networkId: number,
24
+ paymentKeyHash: Hash28ByteBase16,
25
+ stakeKeyHash: Hash28ByteBase16,
26
+ ): BaseAddress => {
27
+ return BaseAddress.fromCredentials(
28
+ networkId,
29
+ {
30
+ hash: paymentKeyHash,
31
+ type: CredentialType.KeyHash,
32
+ },
33
+ {
34
+ hash: stakeKeyHash,
35
+ type: CredentialType.KeyHash,
36
+ },
37
+ );
38
+ };
39
+
40
+ export const buildEnterpriseAddress = (
41
+ networkId: number,
42
+ paymentKeyHash: Hash28ByteBase16,
43
+ ): EnterpriseAddress => {
44
+ return EnterpriseAddress.fromCredentials(networkId, {
45
+ hash: paymentKeyHash,
46
+ type: CredentialType.KeyHash,
47
+ });
48
+ };
49
+
50
+ export const buildBip32PrivateKey = (
51
+ entropy: string,
52
+ password = "",
53
+ ): Bip32PrivateKey => {
54
+ const PBKDF2_ITERATIONS = 4096;
55
+ const PBKDF2_KEY_SIZE = 96;
56
+ const PBKDF2_DIGEST_ALGORITHM = "sha512";
57
+
58
+ const clampScalar = (scalar: Buffer): Buffer => {
59
+ if (scalar[0] !== undefined) {
60
+ scalar[0] &= 0b1111_1000;
61
+ }
62
+ if (scalar[31] !== undefined) {
63
+ scalar[31] &= 0b0001_1111;
64
+ scalar[31] |= 0b0100_0000;
65
+ }
66
+ return scalar;
67
+ };
68
+
69
+ const _entropy = Buffer.from(entropy, "hex");
70
+
71
+ const xprv = pbkdf2Sync(
72
+ password,
73
+ _entropy,
74
+ PBKDF2_ITERATIONS,
75
+ PBKDF2_KEY_SIZE,
76
+ PBKDF2_DIGEST_ALGORITHM,
77
+ );
78
+ return Bip32PrivateKey.fromBytes(clampScalar(xprv));
79
+ };
80
+
81
+ export const buildRewardAddress = (
82
+ networkId: number,
83
+ stakeKeyHash: Hash28ByteBase16,
84
+ ): RewardAddress => {
85
+ const cred = {
86
+ type: CredentialType.KeyHash,
87
+ hash: stakeKeyHash,
88
+ };
89
+ return RewardAddress.fromCredentials(networkId, cred);
90
+ };
91
+
92
+ export const buildKeys = (
93
+ entropy: string | [string, string],
94
+ accountIndex: number,
95
+ keyIndex = 0,
96
+ ): {
97
+ paymentKey: PrivateKey;
98
+ stakeKey: PrivateKey;
99
+ } => {
100
+ if (typeof entropy === "string") {
101
+ const rootKey = new StricahqBip32PrivateKey(Buffer.from(entropy, "hex"));
102
+
103
+ // hardened derivation
104
+ const accountKey = rootKey
105
+ .derive(HARDENED_KEY_START + 1852) // purpose
106
+ .derive(HARDENED_KEY_START + 1815) // coin type
107
+ .derive(HARDENED_KEY_START + accountIndex); // account index
108
+
109
+ const paymentKey = accountKey
110
+ .derive(0) // external chain
111
+ .derive(keyIndex) // payment key index
112
+ .toPrivateKey();
113
+ const stakeKey = accountKey
114
+ .derive(2) // staking key
115
+ .derive(0)
116
+ .toPrivateKey();
117
+
118
+ return { paymentKey, stakeKey };
119
+ } else {
120
+ const paymentKey = new PrivateKey(Buffer.from(entropy[0], "hex"), false);
121
+ const stakeKey = new PrivateKey(Buffer.from(entropy[1], "hex"), false);
122
+
123
+ return { paymentKey, stakeKey };
124
+ }
125
+ };
126
+
127
+ export const buildScriptPubkey = (keyHash: Ed25519KeyHash): NativeScript => {
128
+ const scriptPubkey = new ScriptPubkey(Ed25519KeyHashHex(keyHash.hex()));
129
+ return NativeScript.newScriptPubkey(scriptPubkey);
130
+ };