tag inplace of iou
This commit is contained in:
parent
9d0bded0a5
commit
d2194e99e3
51
src/main.rs
51
src/main.rs
|
@ -21,8 +21,8 @@ enum Command {
|
||||||
Sign {
|
Sign {
|
||||||
/// Signing key (hex encoded)
|
/// Signing key (hex encoded)
|
||||||
skey: String,
|
skey: String,
|
||||||
/// Subbit id (hex encoded)
|
/// Tag (hex encoded)
|
||||||
id: String,
|
tag: String,
|
||||||
/// Amount (unsigned integer u64. Seems to be largest permitted)
|
/// Amount (unsigned integer u64. Seems to be largest permitted)
|
||||||
amt: u64,
|
amt: u64,
|
||||||
},
|
},
|
||||||
|
@ -30,8 +30,8 @@ enum Command {
|
||||||
Verify {
|
Verify {
|
||||||
/// Verifying key (hex encoded)
|
/// Verifying key (hex encoded)
|
||||||
vkey: String,
|
vkey: String,
|
||||||
/// Subbit id (hex encoded)
|
/// Tag (hex encoded)
|
||||||
id: String,
|
tag: String,
|
||||||
/// Amount (unsigned integer u64. Seems to be largest permitted)
|
/// Amount (unsigned integer u64. Seems to be largest permitted)
|
||||||
amt: u64,
|
amt: u64,
|
||||||
/// Signature (hex encoded)
|
/// Signature (hex encoded)
|
||||||
|
@ -49,17 +49,22 @@ fn main() -> anyhow::Result<()> {
|
||||||
let skey = skey_from_seed(seed)?;
|
let skey = skey_from_seed(seed)?;
|
||||||
println!("{}", serde_json::to_string(&KeyPairHex::from_skey(&skey))?);
|
println!("{}", serde_json::to_string(&KeyPairHex::from_skey(&skey))?);
|
||||||
}
|
}
|
||||||
Some(Command::Sign { skey, id, amt }) => {
|
Some(Command::Sign { skey, tag, amt }) => {
|
||||||
let skey = skey_from_hex(&skey)?;
|
let skey = skey_from_hex(&skey)?;
|
||||||
let iou = Iou::from_cli(id, amt)?;
|
let iou = Iou::from_cli(tag, amt)?;
|
||||||
let msg = iou.to_vec()?;
|
let msg = iou.to_vec()?;
|
||||||
let sig = sign(&mut skey.clone(), msg.clone());
|
let sig = sign(&mut skey.clone(), msg.clone());
|
||||||
let _ver = verify(&skey.verifying_key(), &msg, &sig);
|
let _ver = verify(&skey.verifying_key(), &msg, &sig);
|
||||||
println!("{}", sig_to_hex(&sig));
|
println!("{}", sig_to_hex(&sig));
|
||||||
}
|
}
|
||||||
Some(Command::Verify { vkey, id, amt, sig }) => {
|
Some(Command::Verify {
|
||||||
|
vkey,
|
||||||
|
tag,
|
||||||
|
amt,
|
||||||
|
sig,
|
||||||
|
}) => {
|
||||||
let vkey = vkey_from_hex(&vkey)?;
|
let vkey = vkey_from_hex(&vkey)?;
|
||||||
let iou = Iou::from_cli(id, amt)?;
|
let iou = Iou::from_cli(tag, amt)?;
|
||||||
let msg = iou.to_vec()?;
|
let msg = iou.to_vec()?;
|
||||||
let sig = sig_from_hex(&sig)?;
|
let sig = sig_from_hex(&sig)?;
|
||||||
let res = verify(&vkey, &msg, &sig)?;
|
let res = verify(&vkey, &msg, &sig)?;
|
||||||
|
@ -176,21 +181,21 @@ impl KeyPairHex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id_from_hex(s: &str) -> Result<Vec<u8>, anyhow::Error> {
|
pub fn tag_from_hex(s: &str) -> Result<Vec<u8>, anyhow::Error> {
|
||||||
let id = hex::decode(s)?;
|
let tag = hex::decode(s)?;
|
||||||
Ok(id)
|
Ok(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Iou {
|
struct Iou {
|
||||||
subbit_id: Vec<u8>,
|
tag: Vec<u8>,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iou {
|
impl Iou {
|
||||||
fn from_cli(id: String, amt: u64) -> Result<Self, anyhow::Error> {
|
fn from_cli(tag: String, amt: u64) -> Result<Self, anyhow::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
subbit_id: id_from_hex(&id)?,
|
tag: tag_from_hex(&tag)?,
|
||||||
amount: amt,
|
amount: amt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -200,9 +205,7 @@ impl Iou {
|
||||||
tag: 121,
|
tag: 121,
|
||||||
any_constructor: None,
|
any_constructor: None,
|
||||||
fields: pallas_primitives::MaybeIndefArray::Indef(vec![
|
fields: pallas_primitives::MaybeIndefArray::Indef(vec![
|
||||||
PlutusData::BoundedBytes(pallas_primitives::BoundedBytes::from(
|
PlutusData::BoundedBytes(pallas_primitives::BoundedBytes::from(self.tag.clone())),
|
||||||
self.subbit_id.clone(),
|
|
||||||
)),
|
|
||||||
PlutusData::BigInt(pallas_primitives::BigInt::Int(
|
PlutusData::BigInt(pallas_primitives::BigInt::Int(
|
||||||
pallas_primitives::Int::try_from(self.amount as i128)?,
|
pallas_primitives::Int::try_from(self.amount as i128)?,
|
||||||
)),
|
)),
|
||||||
|
@ -218,16 +221,16 @@ impl Iou {
|
||||||
|
|
||||||
fn gen(seed: Option<u64>) -> Self {
|
fn gen(seed: Option<u64>) -> Self {
|
||||||
let mut rng: rand_chacha::ChaCha8Rng = SeedableRng::seed_from_u64(seed.unwrap_or(0));
|
let mut rng: rand_chacha::ChaCha8Rng = SeedableRng::seed_from_u64(seed.unwrap_or(0));
|
||||||
let subbit_id: Vec<u8> = rng.next_u64().to_le_bytes().into();
|
let tag: Vec<u8> = rng.next_u64().to_le_bytes().into();
|
||||||
let amount = rng.next_u64();
|
let amount = rng.next_u64();
|
||||||
Iou { subbit_id, amount }
|
Iou { tag, amount }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct SignedIou {
|
struct SignedIou {
|
||||||
vkey: String,
|
vkey: String,
|
||||||
subbit_id: String,
|
tag: String,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
msg: String,
|
msg: String,
|
||||||
sig: String,
|
sig: String,
|
||||||
|
@ -242,7 +245,7 @@ impl SignedIou {
|
||||||
let sig = sign(&mut skey.clone(), msg.clone());
|
let sig = sign(&mut skey.clone(), msg.clone());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
vkey: vkey_to_hex(&vkey),
|
vkey: vkey_to_hex(&vkey),
|
||||||
subbit_id: hex::encode(iou.subbit_id),
|
tag: hex::encode(iou.tag),
|
||||||
amount: iou.amount,
|
amount: iou.amount,
|
||||||
msg: hex::encode(&msg),
|
msg: hex::encode(&msg),
|
||||||
sig: sig_to_hex(&sig),
|
sig: sig_to_hex(&sig),
|
||||||
|
@ -252,14 +255,14 @@ impl SignedIou {
|
||||||
fn aiken_fmt(self: Self, seed: Option<u64>) {
|
fn aiken_fmt(self: Self, seed: Option<u64>) {
|
||||||
let Self {
|
let Self {
|
||||||
vkey,
|
vkey,
|
||||||
subbit_id,
|
tag,
|
||||||
amount,
|
amount,
|
||||||
msg,
|
msg,
|
||||||
sig,
|
sig,
|
||||||
} = self;
|
} = self;
|
||||||
println!("const i{} = IouTest {{", seed.unwrap_or(0),);
|
println!("const i{} = IouTest {{", seed.unwrap_or(0),);
|
||||||
println!(" vkey: {}", aiken_hex(&vkey));
|
println!(" vkey: {}", aiken_hex(&vkey));
|
||||||
println!(" subbit_id: {}", aiken_hex(&subbit_id));
|
println!(" tag: {}", aiken_hex(&tag));
|
||||||
println!(" amount: {},", amount);
|
println!(" amount: {},", amount);
|
||||||
println!(" msg: {}", aiken_hex(&msg));
|
println!(" msg: {}", aiken_hex(&msg));
|
||||||
println!(" sig: {}", aiken_hex(&sig));
|
println!(" sig: {}", aiken_hex(&sig));
|
||||||
|
@ -270,7 +273,7 @@ impl SignedIou {
|
||||||
fn aiken_test(seed: Option<u64>) {
|
fn aiken_test(seed: Option<u64>) {
|
||||||
println!("test test_i{} () {{", seed.unwrap_or(0));
|
println!("test test_i{} () {{", seed.unwrap_or(0));
|
||||||
println!(" let i = i{}", seed.unwrap_or(0));
|
println!(" let i = i{}", seed.unwrap_or(0));
|
||||||
println!(" verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))");
|
println!(" verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))");
|
||||||
println!("}}");
|
println!("}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
test.ak
20
test.ak
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
const i0 = IouTest {
|
const i0 = IouTest {
|
||||||
vkey: #"3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29",
|
vkey: #"3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29",
|
||||||
subbit_id: #"6c3b9aa767f785b5",
|
tag: #"6c3b9aa767f785b5",
|
||||||
amount: 8594738769458413623,
|
amount: 8594738769458413623,
|
||||||
msg: #"d8799f486c3b9aa767f785b51b7746a55fbad8c037ff",
|
msg: #"d8799f486c3b9aa767f785b51b7746a55fbad8c037ff",
|
||||||
sig: #"8bb7cb5fc82b23fac9114e9a4913f3b01c4db608e6189f01eeb431c7cd0c8c6e28484cdcc25aa895a715622598110754ede40f390797179a70e373856450ce03"
|
sig: #"8bb7cb5fc82b23fac9114e9a4913f3b01c4db608e6189f01eeb431c7cd0c8c6e28484cdcc25aa895a715622598110754ede40f390797179a70e373856450ce03"
|
||||||
|
@ -9,13 +9,13 @@ const i0 = IouTest {
|
||||||
|
|
||||||
test test_i0 () {
|
test test_i0 () {
|
||||||
let i = i0
|
let i = i0
|
||||||
verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))
|
verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const i1 = IouTest {
|
const i1 = IouTest {
|
||||||
vkey: #"cecc1507dc1ddd7295951c290888f095adb9044d1b73d696e6df065d683bd4fc",
|
vkey: #"cecc1507dc1ddd7295951c290888f095adb9044d1b73d696e6df065d683bd4fc",
|
||||||
subbit_id: #"b10da48cea4c0967",
|
tag: #"b10da48cea4c0967",
|
||||||
amount: 1482817706323250795,
|
amount: 1482817706323250795,
|
||||||
msg: #"d8799f48b10da48cea4c09671b149406d8fc0e8e6bff",
|
msg: #"d8799f48b10da48cea4c09671b149406d8fc0e8e6bff",
|
||||||
sig: #"7f96d963c32e225ae0a1fe1491466f277cd4cde77cd4f8335578fd888b61942af64972e02efc3a603241f2d84bb5df95b18f57e2f88e4d63c249716b068d8d01"
|
sig: #"7f96d963c32e225ae0a1fe1491466f277cd4cde77cd4f8335578fd888b61942af64972e02efc3a603241f2d84bb5df95b18f57e2f88e4d63c249716b068d8d01"
|
||||||
|
@ -23,13 +23,13 @@ const i1 = IouTest {
|
||||||
|
|
||||||
test test_i1 () {
|
test test_i1 () {
|
||||||
let i = i1
|
let i = i1
|
||||||
verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))
|
verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const i2 = IouTest {
|
const i2 = IouTest {
|
||||||
vkey: #"6b79c57e6a095239282c04818e96112f3f03a4001ba97a564c23852a3f1ea5fc",
|
vkey: #"6b79c57e6a095239282c04818e96112f3f03a4001ba97a564c23852a3f1ea5fc",
|
||||||
subbit_id: #"c51b8a31c98b9fe1",
|
tag: #"c51b8a31c98b9fe1",
|
||||||
amount: 10116765682372994352,
|
amount: 10116765682372994352,
|
||||||
msg: #"d8799f48c51b8a31c98b9fe11b8c65f8c985b46530ff",
|
msg: #"d8799f48c51b8a31c98b9fe11b8c65f8c985b46530ff",
|
||||||
sig: #"7e6161aab7aff7d73afe83b176d0f3549dc81a5c69ff35aaa7576417e69d7eb81b070d8aa4ae115a6beff99851be1b6266b66d4b2a3d56b4ae499bbc66d8f306"
|
sig: #"7e6161aab7aff7d73afe83b176d0f3549dc81a5c69ff35aaa7576417e69d7eb81b070d8aa4ae115a6beff99851be1b6266b66d4b2a3d56b4ae499bbc66d8f306"
|
||||||
|
@ -37,13 +37,13 @@ const i2 = IouTest {
|
||||||
|
|
||||||
test test_i2 () {
|
test test_i2 () {
|
||||||
let i = i2
|
let i = i2
|
||||||
verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))
|
verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const i3 = IouTest {
|
const i3 = IouTest {
|
||||||
vkey: #"dadbd184a2d526f1ebdd5c06fdad9359b228759b4d7f79d66689fa254aad8546",
|
vkey: #"dadbd184a2d526f1ebdd5c06fdad9359b228759b4d7f79d66689fa254aad8546",
|
||||||
subbit_id: #"5de9bc1bb4cb7a9f",
|
tag: #"5de9bc1bb4cb7a9f",
|
||||||
amount: 1499751601245649308,
|
amount: 1499751601245649308,
|
||||||
msg: #"d8799f485de9bc1bb4cb7a9f1b14d03022a391f99cff",
|
msg: #"d8799f485de9bc1bb4cb7a9f1b14d03022a391f99cff",
|
||||||
sig: #"c6ca9a4e75691b030d416bb8316d4cf43601b8764d88f8cdbd36207136334abbd819cd00ac77962f7a8dbc494d253f147b5c9d78bf3a77fb6435d0f318d32d09"
|
sig: #"c6ca9a4e75691b030d416bb8316d4cf43601b8764d88f8cdbd36207136334abbd819cd00ac77962f7a8dbc494d253f147b5c9d78bf3a77fb6435d0f318d32d09"
|
||||||
|
@ -51,13 +51,13 @@ const i3 = IouTest {
|
||||||
|
|
||||||
test test_i3 () {
|
test test_i3 () {
|
||||||
let i = i3
|
let i = i3
|
||||||
verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))
|
verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const i4 = IouTest {
|
const i4 = IouTest {
|
||||||
vkey: #"9be3287795907809407e14439ff198d5bfc7dce6f9bc743cb369146f610b4801",
|
vkey: #"9be3287795907809407e14439ff198d5bfc7dce6f9bc743cb369146f610b4801",
|
||||||
subbit_id: #"22cfaefc92e4edb9",
|
tag: #"22cfaefc92e4edb9",
|
||||||
amount: 1287912097577021104,
|
amount: 1287912097577021104,
|
||||||
msg: #"d8799f4822cfaefc92e4edb91b11df953aa601aeb0ff",
|
msg: #"d8799f4822cfaefc92e4edb91b11df953aa601aeb0ff",
|
||||||
sig: #"8775af7f57f681bddb8ad3682f662dcfd0fbb09b0a0fe652d880fc3d96f60f66225f4d5bc31e7a1acb729ffebec5ed0666b93e4acbc26392103a1e7878638f0e"
|
sig: #"8775af7f57f681bddb8ad3682f662dcfd0fbb09b0a0fe652d880fc3d96f60f66225f4d5bc31e7a1acb729ffebec5ed0666b93e4acbc26392103a1e7878638f0e"
|
||||||
|
@ -65,6 +65,6 @@ const i4 = IouTest {
|
||||||
|
|
||||||
test test_i4 () {
|
test test_i4 () {
|
||||||
let i = i4
|
let i = i4
|
||||||
verify_iou(i.vkey, i.subbit_id, t.Iou (i.amount, i.sig))
|
verify_iou(i.vkey, i.tag, t.Iou (i.amount, i.sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue