Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted to the asset-cid changes of planetmint protobuf #28

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions lib/default/rddl/src/planetmintgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,43 +204,14 @@ int generateAnyAttestMachineMsg(Google__Protobuf__Any* anyMsg, Planetmintgo__Mac
return 0;
}


int generateAnyCIDAttestMsg( Google__Protobuf__Any* anyMsg, char *public_address )
{
Planetmintgo__Asset__MsgNotarizeAsset msg = PLANETMINTGO__ASSET__MSG_NOTARIZE_ASSET__INIT;
msg.creator = public_address;
msg.hash = "cid";
msg.signature = "313d60b37ca2f168d33b7d6234f6d8725d910d0a74872350874bb0a98f8cc8584204010720b9d1dfe3800fdbf067d07bba13d2954d2e98943e18b8fe1fadf77b";
msg.pubkey = "02328de87896b9cbb5101c335f40029e4be898988b470abbf683f1a0b318d73470";

anyMsg->type_url = "/planetmintgo.asset.MsgNotarizeAsset";
anyMsg->value.len = planetmintgo__asset__msg_notarize_asset__get_packed_size(&msg);
anyMsg->value.data = getStack(anyMsg->value.len);
if( !anyMsg->value.data )
return -1;
planetmintgo__asset__msg_notarize_asset__pack(&msg, anyMsg->value.data);
return 0;
}

int generateAnyCIDAttestMsgGeneric( Google__Protobuf__Any* anyMsg, const char* cid, uint8_t* priv_key, uint8_t* pub_key, char* public_address, const char* ext_pub_key)
int generateAnyCIDAttestMsg( Google__Protobuf__Any* anyMsg, const char* cid, uint8_t* priv_key, uint8_t* pub_key, char* public_address, const char* ext_pub_key)
{

Planetmintgo__Asset__MsgNotarizeAsset msg = PLANETMINTGO__ASSET__MSG_NOTARIZE_ASSET__INIT;

uint8_t digest[SHA256_DIGEST_LENGTH] = {0};
sha256(cid, strlen(cid), digest);

const ecdsa_curve *curve = &secp256k1;

uint8_t signature[64]= {0};
char signature_hex[64*2+1] = {0};
int res = ecdsa_sign_digest(curve, (const unsigned char *)priv_key, (const unsigned char *)digest, signature, NULL, NULL);
toHexString(signature_hex, signature, 128);

msg.creator = public_address;
msg.hash = (char*)cid;
msg.signature = signature_hex;
msg.pubkey = ext_pub_key;
msg.cid = (char*)cid;


anyMsg->type_url = "/planetmintgo.asset.MsgNotarizeAsset";
anyMsg->value.len = planetmintgo__asset__msg_notarize_asset__get_packed_size(&msg);
Expand Down
6 changes: 3 additions & 3 deletions lib/default/rddl/src/planetmintgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ bool get_address_info_from_accounts( const char* json_obj, const char* address,
void pubkey2address( const uint8_t* pubkey, size_t key_length, uint8_t* address);
int getAddressString( const uint8_t* address, char* stringbuffer);

int generateAnyCIDAttestMsg( Google__Protobuf__Any* anyMsg, char *public_address );
int generateAnyCIDAttestMsgGeneric( Google__Protobuf__Any* anyMsg, const char* cid,
int generateAnyCIDAttestMsg( Google__Protobuf__Any* anyMsg, const char* cid,
uint8_t* priv_key, uint8_t* pub_key,
char *public_address, const char* ext_pub_key);

int generateAnyAttestMachineMsg(Google__Protobuf__Any* anyMsg, Planetmintgo__Machine__MsgAttestMachine* machineMsg);
int generateAnyAttestMachineMsg(Google__Protobuf__Any* anyMsg,
Planetmintgo__Machine__MsgAttestMachine* machineMsg);

int prepareTx( Google__Protobuf__Any* anyMsg,
Cosmos__Base__V1beta1__Coin* coin,
Expand Down
38 changes: 6 additions & 32 deletions lib/default/rddl/src/planetmintgo/asset/asset.pb-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,54 +52,28 @@ void planetmintgo__asset__asset__free_unpacked
assert(message->base.descriptor == &planetmintgo__asset__asset__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
static const ProtobufCFieldDescriptor planetmintgo__asset__asset__field_descriptors[3] =
static const ProtobufCFieldDescriptor planetmintgo__asset__asset__field_descriptors[1] =
{
{
"hash",
"cid",
1,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(Planetmintgo__Asset__Asset, hash),
NULL,
&protobuf_c_empty_string,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"signature",
2,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(Planetmintgo__Asset__Asset, signature),
NULL,
&protobuf_c_empty_string,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"pubkey",
3,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(Planetmintgo__Asset__Asset, pubkey),
offsetof(Planetmintgo__Asset__Asset, cid),
NULL,
&protobuf_c_empty_string,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned planetmintgo__asset__asset__field_indices_by_name[] = {
0, /* field[0] = hash */
2, /* field[2] = pubkey */
1, /* field[1] = signature */
0, /* field[0] = cid */
};
static const ProtobufCIntRange planetmintgo__asset__asset__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 3 }
{ 0, 1 }
};
const ProtobufCMessageDescriptor planetmintgo__asset__asset__descriptor =
{
Expand All @@ -109,7 +83,7 @@ const ProtobufCMessageDescriptor planetmintgo__asset__asset__descriptor =
"Planetmintgo__Asset__Asset",
"planetmintgo.asset",
sizeof(Planetmintgo__Asset__Asset),
3,
1,
planetmintgo__asset__asset__field_descriptors,
planetmintgo__asset__asset__field_indices_by_name,
1, planetmintgo__asset__asset__number_ranges,
Expand Down
6 changes: 2 additions & 4 deletions lib/default/rddl/src/planetmintgo/asset/asset.pb-c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading