Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
ref: add domain argument to user & verifier data functions
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Sep 29, 2023
1 parent 9254e37 commit 9753121
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions src/IStarknetID.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ namespace IStarknetid {
func tokenURI(tokenId: Uint256) -> (tokenURI_len: felt, tokenURI: felt*) {
}

func get_user_data(starknet_id: felt, field: felt) -> (data: felt) {
func get_user_data(starknet_id: felt, field: felt, domain: felt) -> (data: felt) {
}

func get_extended_user_data(starknet_id: felt, field: felt, length: felt) {
func get_extended_user_data(starknet_id: felt, field: felt, length: felt, domain: felt) {
}

func get_unbounded_user_data(starknet_id: felt, field: felt) -> (data_len: felt, data: felt*) {
func get_unbounded_user_data(starknet_id: felt, field: felt, domain: felt) -> (data_len: felt, data: felt*) {
}

func get_verifier_data(starknet_id: felt, field: felt, address: felt) -> (data: felt) {
func get_verifier_data(starknet_id: felt, field: felt, address: felt, domain: felt) -> (data: felt) {
}

func get_extended_verifier_data(
starknet_id: felt, field: felt, length: felt, address: felt
starknet_id: felt, field: felt, length: felt, address: felt, domain: felt
) -> (data_len: felt, data: felt*) {
}

func get_unbounded_verifier_data(starknet_id: felt, field: felt, address: felt) -> (
func get_unbounded_verifier_data(starknet_id: felt, field: felt, address: felt, domain: felt) -> (
data_len: felt, data: felt*
) {
}
Expand All @@ -70,16 +70,16 @@ namespace IStarknetid {
func mint(starknet_id: felt) {
}

func set_user_data(starknet_id: felt, field: felt, data: felt) {
func set_user_data(starknet_id: felt, field: felt, data: felt, domain: felt) {
}

func set_extended_user_data(starknet_id: felt, field: felt, data_len: felt, data: felt*) {
func set_extended_user_data(starknet_id: felt, field: felt, data_len: felt, data: felt*, domain: felt) {
}

func set_verifier_data(starknet_id: felt, field: felt, data: felt) {
func set_verifier_data(starknet_id: felt, field: felt, data: felt, domain: felt) {
}

func set_extended_verifier_data(starknet_id: felt, field: felt, data_len: felt, data: felt*) {
func set_extended_verifier_data(starknet_id: felt, field: felt, data_len: felt, data: felt*, domain: felt) {
}

func equip(inft_contract: felt, inft_id: felt) {
Expand Down
20 changes: 10 additions & 10 deletions src/StarknetId.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ func supportsInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_che
//
@view
func get_user_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt
starknet_id: felt, field: felt, domain: felt,
) -> (data: felt) {
let (data: felt) = user_data.read(starknet_id, field);
return (data,);
}

@view
func get_extended_user_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt, length: felt
starknet_id: felt, field: felt, length: felt, domain: felt,
) -> (data_len: felt, data: felt*) {
let (addr: felt) = user_data.addr(starknet_id, field);
return read_extended_data(addr, length);
}

@view
func get_unbounded_user_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt
starknet_id: felt, field: felt, domain: felt,
) -> (data_len: felt, data: felt*) {
alloc_locals;
let (arr) = alloc();
Expand All @@ -179,23 +179,23 @@ func get_unbounded_user_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, ran

@view
func get_verifier_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt, address: felt
starknet_id: felt, field: felt, address: felt, domain: felt,
) -> (data: felt) {
let (data: felt) = verifier_data.read(starknet_id, field, address);
return (data,);
}

@view
func get_extended_verifier_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt, length: felt, address: felt
starknet_id: felt, field: felt, length: felt, address: felt, domain: felt,
) -> (data_len: felt, data: felt*) {
let (addr: felt) = verifier_data.addr(starknet_id, field, address);
return read_extended_data(addr, length);
}

@view
func get_unbounded_verifier_data{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
starknet_id: felt, field: felt, address: felt
starknet_id: felt, field: felt, address: felt, domain: felt,
) -> (data_len: felt, data: felt*) {
alloc_locals;
let (arr) = alloc();
Expand Down Expand Up @@ -269,7 +269,7 @@ func mint{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(stark
//
@external
func set_user_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
starknet_id: felt, field: felt, data: felt
starknet_id: felt, field: felt, data: felt, domain: felt,
) {
let (owner) = ERC721.owner_of(Uint256(starknet_id, 0));
let (caller) = get_caller_address();
Expand All @@ -282,7 +282,7 @@ func set_user_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_p
// note: when working with multiple sizes, make sure to write data_len+1 with last_value = 0
@external
func set_extended_user_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
starknet_id: felt, field: felt, data_len: felt, data: felt*
starknet_id: felt, field: felt, data_len: felt, data: felt*, domain: felt,
) {
alloc_locals;
let (owner) = ERC721.owner_of(Uint256(starknet_id, 0));
Expand All @@ -296,7 +296,7 @@ func set_extended_user_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, rang

@external
func set_verifier_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
starknet_id: felt, field: felt, data: felt
starknet_id: felt, field: felt, data: felt, domain: felt,
) {
let (address) = get_caller_address();
VerifierDataUpdate.emit(starknet_id, field, data, address);
Expand All @@ -307,7 +307,7 @@ func set_verifier_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_che
// note: when working with multiple sizes, make sure to write data_len+1 with last_value = 0
@external
func set_extended_verifier_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
starknet_id: felt, field: felt, data_len: felt, data: felt*
starknet_id: felt, field: felt, data_len: felt, data: felt*, domain: felt,
) {
alloc_locals;
let (author) = get_caller_address();
Expand Down
24 changes: 12 additions & 12 deletions tests/test_extended_data.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ func test_verifier_extended_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*,
let token_id = 1;
mint(token_id);
// should set the avatar of specified token_id to [ 12345, 6789 ]
set_extended_verifier_data(token_id, 'avatar', 2, new (12345, 6789));
set_extended_verifier_data(token_id, 'avatar', 2, new (12345, 6789), 0);
// should retrieve it by specifying the array length
let (len, values) = get_extended_verifier_data(token_id, 'avatar', 2, 123);
let (len, values) = get_extended_verifier_data(token_id, 'avatar', 2, 123, 0);
assert len = 2;
assert 12345 = values[0];
assert 6789 = values[1];

// should retrieve it without specifying the length (stops at 0)
let (len, values) = get_unbounded_verifier_data(token_id, 'avatar', 123);
let (len, values) = get_unbounded_verifier_data(token_id, 'avatar', 123, 0);
assert len = 2;
assert 12345 = values[0];
assert 6789 = values[1];

// should retrieve nothing
let (len, values) = get_unbounded_verifier_data(token_id, 'yolo', 123);
let (len, values) = get_unbounded_verifier_data(token_id, 'yolo', 123, 0);
assert len = 0;

// should retrieve an array of specified size full of 0
let (len, values) = get_extended_verifier_data(token_id, 'yolo', 3, 123);
let (len, values) = get_extended_verifier_data(token_id, 'yolo', 3, 123, 0);
assert len = 3;
assert values[0] = 0;
assert values[1] = 0;
assert values[2] = 0;

// should not return any user data
let (len, values) = get_unbounded_user_data(token_id, 'avatar');
let (len, values) = get_unbounded_user_data(token_id, 'avatar', 0);
assert len = 0;

%{ stop_prank_callable() %}
Expand All @@ -63,32 +63,32 @@ func test_user_extended_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, ran
let token_id = 1;
mint(token_id);
// should set the avatar of specified token_id to [ 12345, 6789 ]
set_extended_user_data(token_id, 'avatar', 2, new (12345, 6789));
set_extended_user_data(token_id, 'avatar', 2, new (12345, 6789), 0);
// should retrieve it by specifying the array length
let (len, values) = get_extended_user_data(token_id, 'avatar', 2);
let (len, values) = get_extended_user_data(token_id, 'avatar', 2, 0);
assert len = 2;
assert 12345 = values[0];
assert 6789 = values[1];

// should retrieve it without specifying the length (stops at 0)
let (len, values) = get_unbounded_user_data(token_id, 'avatar');
let (len, values) = get_unbounded_user_data(token_id, 'avatar', 0);
assert len = 2;
assert 12345 = values[0];
assert 6789 = values[1];

// should retrieve nothing
let (len, values) = get_unbounded_user_data(token_id, 'yolo');
let (len, values) = get_unbounded_user_data(token_id, 'yolo', 0);
assert len = 0;

// should retrieve an array of specified size full of 0
let (len, values) = get_extended_user_data(token_id, 'yolo', 3);
let (len, values) = get_extended_user_data(token_id, 'yolo', 3, 0);
assert len = 3;
assert values[0] = 0;
assert values[1] = 0;
assert values[2] = 0;

// should not return any verifier data
let (len, values) = get_unbounded_verifier_data(token_id, 'avatar', 123);
let (len, values) = get_unbounded_verifier_data(token_id, 'avatar', 123, 0);
assert len = 0;

%{ stop_prank_callable() %}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_starknetId.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func test_set_verifier_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, rang
let type = 19256242726728292; // # Discord
let data = 58596348113441803209962597; // # 0xBenaparte

set_verifier_data(token_id, type, data);
set_verifier_data(token_id, type, data, 0);

// # valid case
let (isValidData) = verifier_data.read(token_id, type, 123);
Expand Down Expand Up @@ -71,7 +71,7 @@ func test_set_user_data{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_ch
let type = 19256242726728292; // # Discord
let data = 58596348113441803209962597; // # 0xBenaparte

set_user_data(token_id, type, data);
set_user_data(token_id, type, data, 0);

// valid case
let (identityData) = user_data.read(token_id, type);
Expand Down

0 comments on commit 9753121

Please sign in to comment.