Browse Source

started with signatures in nft-collection

dev/signature-instant-buy
Lev 2 years ago
parent
commit
c369fe54f8
  1. 29
      contracts/imports/dns-utils.fc
  2. 14
      contracts/nft-collection.fc
  3. 1
      test/creation.spec.ts

29
contracts/imports/dns-utils.fc

@ -31,7 +31,8 @@ int get_top_domain_bits(slice domain) {
return i;
}
slice read_domain_from_comment(slice in_msg_body) {
;; Parse a human-readable TON comment into one slice
slice read_comment(slice in_msg_body) {
int need_break = 0;
builder result = begin_cell();
do {
@ -46,6 +47,10 @@ slice read_domain_from_comment(slice in_msg_body) {
return result.end_cell().begin_parse();
}
slice read_domain_from_comment(slice in_msg_body) {
return read_comment(in_msg_body);
}
int check_domain_string(slice domain) {
int i = 0;
int len = slice_bits(domain);
@ -67,6 +72,28 @@ int check_domain_string(slice domain) {
return i == len;
}
(slice, slice) split_by_semicolon(slice str) {
int i = 0;
int len = slice_bits(str);
int need_break = 0;
builder result1 = begin_cell();
do {
need_break = i == len;
if (~ need_break) {
int char = str~load_uint(8);
need_break = char == 59; ;; ';'
if (~ need_break) {
i += 8;
}
result1~store_uint(char, 8);
if (~ need_break & (i >= len)) {
throw(259); ;; no ';' found
}
}
} until (need_break);
return (result1.end_cell().begin_parse(), str~load_bits(len - i));
}
(int, int) get_min_price_config(int domain_char_count) {
if (domain_char_count == 4) {
return (1000, 100);

14
contracts/nft-collection.fc

@ -3,6 +3,9 @@
#include "imports/op-codes.fc";
#include "imports/params.fc";
;; -1 if needed, 0 if not
const signature_needed = -1;
;; storage scheme
;; cell collection_content
;; cell nft_item_code
@ -68,6 +71,11 @@ slice calculate_nft_item_address(int wc, cell state_init) {
send_raw_message(msg.end_cell(), 64); ;; carry all the remaining value of the inbound message, fee deducted from amount
}
int verify_signature(cell signature, slice sender_address, slice domain, int owner_key) {
cell option_data = begin_cell().store_slice(domain).store_slice(sender_address).end_cell();
return check_signature(slice_hash(option_data.begin_parse()), signature.begin_parse(), owner_key);
}
() recv_internal(int msg_value, cell in_msg_full, slice in_msg_body) impure {
if (in_msg_body.slice_empty?()) { ;; bounce back empty messages
throw(0xffff);
@ -93,6 +101,12 @@ slice calculate_nft_item_address(int wc, cell state_init) {
int item_index = slice_hash(domain);
slice sender_address = cs~load_msg_addr();
if (signature_needed) {
;; todo: do stuff here
;; cell signature = in_msg_body~load_ref();
;; throw_unless(205, verify_signature(signature, sender_address, domain, key));
}
cell nft_content = begin_cell()
.store_slice(sender_address)
.store_ref(begin_cell().store_slice(domain).end_cell())

1
test/creation.spec.ts

@ -9,6 +9,7 @@ import * as main from "../contracts/main";
import { internalMessage, randomAddress } from "./helpers";
import { hex } from "../build/nft-collection.compiled.json";
import {makeSnakeCell} from "../contracts/utils";
describe("Creating items tests", () => {
let contract: SmartContract;

Loading…
Cancel
Save