Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Feb 9, 2025
1 parent 78dd62a commit b4ef204
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bytes = "d86bb152b638bf63db6d44aee0c3ff1818e13949cc4130ad5d459d57"
encoding = "hex"

[config.preview.new_user_tx_hash]
bytes = "0c06c51ff693f9f80c66978db009ff5f1e33030130a91c687af9f177b5b6bf26"
bytes = "0788cbca89f1a7442f0ed538d5d30ffee1014d367c1bbba4b13305b7bd8a36b7"
encoding = "hex"

[config.preview.one_shot_tx_hash]
Expand Down
10 changes: 6 additions & 4 deletions lib/utils.ak
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ pub fn check_all_valid_vk_sigs(
) && check_all_valid_vk_sigs(rest, others, message)
} else {
expect Secp(vk) = vk
(
vk
|> verify_ecdsa_signature(message, sig |> builtin.un_b_data)
) && check_all_valid_vk_sigs(rest, others, message)
(vk
|> verify_ecdsa_signature(message, sig |> builtin.un_b_data))? && check_all_valid_vk_sigs(
rest,
others,
message,
)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions plutus.json

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions src/bulletSecp256k1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import {
CML,
credentialToAddress,
Data,
datumToHash,
Emulator,
EmulatorAccount,
fromText,
generateEmulatorAccount,
getAddressDetails,
Lucid,
LucidEvolution,
paymentCredentialOf,
toHex,
toPublicKey,
utxoToTransactionInput,
utxoToTransactionOutput,
} from "@lucid-evolution/lucid";
import {
bulletAddress,
Expand Down Expand Up @@ -54,6 +58,8 @@ import {
StakeBulletRedeemerType,
} from "./bulletTypes";
import { IntentionRedeemerType, IntentType } from "./intentTypes";
import { OutputRefType } from "./otherTypes";
import { CBORArray } from "@emurgo/cardano-message-signing-nodejs";

export async function setupBulletSecp() {
// Initialize Lucid with Koios provider
Expand Down Expand Up @@ -110,6 +116,13 @@ export async function setupBulletSecp() {
// Needed to parameterize the aiken.toml file
console.log("Parameterize aiken.toml file with: ", globalSetupTxHash);

const message: OutputRefType = { txId: globalSetupTxHash, outputIndex: 1n };

console.log(
"Message to sign is ",
fromText("Bullet") + Data.to(message, OutputRefType),
);

const registerTx = await lucid
.newTx()
.collectFrom([(await lucid.utxosAt(initAccount.address))[1]])
Expand Down Expand Up @@ -147,7 +160,7 @@ export async function setupBulletSecp() {
other_keys: [
{
Secp: [
"027356a58fec88dcbcc1225406c0065cac4c58a255b84485a6e03c14ee7bc222f4",
"021e060aa4a76b65c6508d79e6d67770ff5126d733a34e00405b11b70d0783c875",
],
},
],
Expand All @@ -165,7 +178,12 @@ export async function setupBulletSecp() {
},
};

const sigDatum: SigsDatumType = [[], []];
const sigDatum: SigsDatumType = [
[
"94638f274a462d413e45ba550d21dfc7b1a3d745c5a2975f09e6985c24d3287112df3630356ce559b4aa4cb09bbe912b24add6496428eb1d911613e99042692c",
],
[],
];

const newUserTx = await lucid
.newTx()
Expand Down
2 changes: 1 addition & 1 deletion src/bulletTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const SchnorrSchema = Data.Object({
Schnorr: Data.Tuple([Data.Bytes({ minLength: 32, maxLength: 32 })]),
});

export const VkSchema = Data.Enum([SecpSchema, SchnorrSchema]);
export const VkSchema = Data.Enum([SchnorrSchema, SecpSchema]);

export const VerificationSchema = Data.Object({
Verification: Data.Object({
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
walletSpend,
} from "./bulletEdd25519";

import { setupBulletSecp } from "./bulletSecp256k1";

setupBullet()
.then((l) => hotSpend(l))
.catch(console.error);
Expand All @@ -26,3 +28,5 @@ setupBullet()
setupBullet()
.then((l) => intentSpend(l))
.catch(console.error);

setupBulletSecp().catch(console.error);
3 changes: 3 additions & 0 deletions src/otherTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const OutputRefSchema = Data.Object({
outputIndex: Data.Integer({ minimum: 0 }),
});

export type OutputRefType = Data.Static<typeof OutputRefSchema>;
export const OutputRefType = OutputRefSchema as unknown as OutputRefType;

// pub type ScriptPurpose {
// /// For scripts executed as minting/burning policies, to insert
// /// or remove assets from circulation. It's parameterized by the identifier
Expand Down
8 changes: 4 additions & 4 deletions validators/bullet.ak
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ validator stake_bullet {
]

expect (hot_sigs, cold_sigs): (
List<Data<Signature>>,
List<Data<Signature>>,
Data<List<Signature>>,
Data<List<Signature>>,
) = sig_datum

expect AccountState { hot_cred, cold_cred } = datum
Expand All @@ -142,7 +142,7 @@ validator stake_bullet {
and {
check_all_valid_vk_sigs(
other_keys |> builtin.un_list_data,
hot_sigs,
hot_sigs |> builtin.un_list_data,
one_shot_message,
)?,
check_all_tx_observed_and_hashes(
Expand All @@ -164,7 +164,7 @@ validator stake_bullet {
and {
check_all_valid_vk_sigs(
other_keys |> builtin.un_list_data,
cold_sigs,
cold_sigs |> builtin.un_list_data,
one_shot_message,
)?,
check_all_tx_observed_and_hashes(
Expand Down

0 comments on commit b4ef204

Please sign in to comment.