Skip to content

Commit

Permalink
Add missing auth id(0x02~0x05)
Browse files Browse the repository at this point in the history
migrate PR from: nervosnetwork/ckb-production-scripts#75

including
* eos
* tron
* bitcoin(Support UniSat and OKX wallet)
* dogecoin

Special feature for btc/etc, now they can display meaningful messages.

* BTC(UniSat/OKX)
You're signing:
CKB (Bitcoin Layer-2) transaction: 0x{sighash_all in hex}

* ETH(Metamask)
You're signing:
CKB transaction: 0x{sighash_all in hex}
XuJiandong committed Jan 12, 2024
1 parent 54541e5 commit bcd9b58
Showing 12 changed files with 1,611 additions and 52 deletions.
388 changes: 355 additions & 33 deletions c/ckb_identity.h

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions c/conversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2014-2018 The Bitcoin Core developers
* Distributed under the MIT software license, see the accompanying
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
*
* only used on little endian
*/

#ifndef CONVERSION_H
#define CONVERSION_H

#include <stdint.h>
#include <string.h>

uint32_t static inline bswap_32(uint32_t x) {
return (((uint32_t)(x)&0xff000000) >> 24) |
(((uint32_t)(x)&0x00ff0000) >> 8) | (((uint32_t)(x)&0x0000ff00) << 8) |
(((uint32_t)(x)&0x000000ff) << 24);
}

uint64_t static inline bswap_64(uint64_t x) {
return (((uint64_t)(x)&0xff00000000000000ull) >> 56) |
(((uint64_t)(x)&0x00ff000000000000ull) >> 40) |
(((uint64_t)(x)&0x0000ff0000000000ull) >> 24) |
(((uint64_t)(x)&0x000000ff00000000ull) >> 8) |
(((uint64_t)(x)&0x00000000ff000000ull) << 8) |
(((uint64_t)(x)&0x0000000000ff0000ull) << 24) |
(((uint64_t)(x)&0x000000000000ff00ull) << 40) |
(((uint64_t)(x)&0x00000000000000ffull) << 56);
}

uint32_t static inline le32toh_(uint32_t x) { return x; }

uint32_t static inline htole32_(uint32_t x) { return x; }

uint32_t static inline be32toh_(uint32_t x) { return bswap_32(x); }

uint32_t static inline htobe32_(uint32_t x) { return bswap_32(x); }

uint64_t static inline le64toh_(uint64_t x) { return x; }

uint64_t static inline htole64_(uint64_t x) { return x; }

uint32_t static inline be64toh_(uint64_t x) { return bswap_64(x); }

uint64_t static inline htobe64_(uint64_t x) { return bswap_64(x); }

uint32_t static inline ReadLE32(const unsigned char* ptr) {
uint32_t x;
memcpy((char*)&x, ptr, 4);
return le32toh_(x);
}

void static inline WriteLE32(unsigned char* ptr, uint32_t x) {
uint32_t v = htole32_(x);
memcpy(ptr, (char*)&v, 4);
}

uint32_t static inline ReadBE32(const unsigned char* ptr) {
uint32_t x;
memcpy((char*)&x, ptr, 4);
return be32toh_(x);
}

void static inline WriteBE32(unsigned char* ptr, uint32_t x) {
uint32_t v = htobe32_(x);
memcpy(ptr, (char*)&v, 4);
}

void static inline WriteLE64(unsigned char* ptr, uint64_t x) {
uint64_t v = htole64_(x);
memcpy(ptr, (char*)&v, 8);
}

uint64_t static inline ReadLE64(const unsigned char* ptr) {
uint64_t x;
memcpy((char*)&x, ptr, 8);
return le64toh_(x);
}

void static inline WriteBE64(unsigned char* ptr, uint64_t x) {
uint64_t v = htobe64_(x);
memcpy(ptr, (char*)&v, 8);
}

uint64_t static inline ReadBE64(const unsigned char* ptr) {
uint64_t x;
memcpy((char*)&x, ptr, 8);
return be64toh_(x);
}

#endif
4 changes: 2 additions & 2 deletions c/omni_lock.c
Original file line number Diff line number Diff line change
@@ -136,8 +136,8 @@ bool is_memory_enough(mol_seg_t seg, const uint8_t *cur, uint32_t len) {

// memory layout of args:
// <identity, 21 bytes> <omni_lock args>
// <omni_lock flags, 1 byte> <OMNI cell type id, 32 bytes, optional> <ckb/udt min,
// 2 bytes, optional> <since, 8 bytes, optional>
// <omni_lock flags, 1 byte> <OMNI cell type id, 32 bytes, optional> <ckb/udt
// min, 2 bytes, optional> <since, 8 bytes, optional>
int parse_args(ArgsType *args) {
int err = 0;
uint8_t script[SCRIPT_SIZE];
Loading

0 comments on commit bcd9b58

Please sign in to comment.