Skip to content

Commit

Permalink
Merge branch 'main' into ayush/patch-package-gestyure-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark authored May 22, 2024
2 parents 4ffd753 + 7d5bc6a commit 3ba8a41
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 14 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/starknet-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: 'nightly'
- name: Scarb version
run: scarb --version
working-directory: onchain
- name: Check cairo format
run: scarb fmt --check
working-directory: onchain
Expand All @@ -23,8 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: 'nightly'
- name: Run cairo tests
run: scarb test
working-directory: onchain
53 changes: 53 additions & 0 deletions onchain/Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "alexandria_bytes"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_data_structures",
"alexandria_math",
]

[[package]]
name = "alexandria_data_structures"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_encoding",
]

[[package]]
name = "alexandria_encoding"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_bytes",
"alexandria_math",
"alexandria_numeric",
]

[[package]]
name = "alexandria_math"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_data_structures",
]

[[package]]
name = "alexandria_numeric"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_math",
"alexandria_searching",
]

[[package]]
name = "alexandria_searching"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#78b0d5114e7dbd71e79c4504e8ecb56d9b5c6995"
dependencies = [
"alexandria_data_structures",
]

[[package]]
name = "joyboy"
version = "0.1.0"
dependencies = [
"alexandria_math",
"snforge_std",
]

Expand Down
1 change: 1 addition & 0 deletions onchain/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2023_11"

[dependencies]
starknet = "2.6.3"
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }
Expand Down
60 changes: 58 additions & 2 deletions onchain/src/bip340.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,74 @@
use core::byte_array::ByteArrayTrait;
use core::option::OptionTrait;
use core::result::ResultTrait;
use core::sha256::compute_sha256_byte_array;
// TODO: uncomment once Cairo 2.7 is available
// use core::sha256::compute_sha256_byte_array;
use core::starknet::SyscallResultTrait;
use core::to_byte_array::AppendFormattedToByteArray;
use core::to_byte_array::{AppendFormattedToByteArray, FormatAsByteArray};
use core::traits::Into;
use starknet::{secp256k1::{Secp256k1Point}, secp256_trait::{Secp256Trait, Secp256PointTrait}};

use alexandria_math::sha256::sha256;
use joyboy::utils::{shl, shr};

const TWO_POW_32: u128 = 0x100000000;
const TWO_POW_64: u128 = 0x10000000000000000;
const TWO_POW_96: u128 = 0x1000000000000000000000000;

const p: u256 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;

fn compute_sha256_byte_array(m: @ByteArray) -> [u32; 8] {
let mut ba = ArrayTrait::new();
let len = m.len();
let mut i = 0;
loop {
if i == len {
break ();
}
ba.append(m.at(i).unwrap());
i += 1;
};

let sha = sha256(ba);

let r = [
shl((*sha.at(0)).into(), 24_u32)
+ shl((*sha.at(1)).into(), 16_u32)
+ shl((*sha.at(2)).into(), 8_u32)
+ (*sha.at(3)).into(),
shl((*sha.at(4)).into(), 24_u32)
+ shl((*sha.at(5)).into(), 16_u32)
+ shl((*sha.at(6)).into(), 8_u32)
+ (*sha.at(7)).into(),
shl((*sha.at(8)).into(), 24_u32)
+ shl((*sha.at(9)).into(), 16_u32)
+ shl((*sha.at(10)).into(), 8_u32)
+ (*sha.at(11)).into(),
shl((*sha.at(12)).into(), 24_u32)
+ shl((*sha.at(13)).into(), 16_u32)
+ shl((*sha.at(14)).into(), 8_u32)
+ (*sha.at(15)).into(),
shl((*sha.at(16)).into(), 24_u32)
+ shl((*sha.at(17)).into(), 16_u32)
+ shl((*sha.at(18)).into(), 8_u32)
+ (*sha.at(19)).into(),
shl((*sha.at(20)).into(), 24_u32)
+ shl((*sha.at(21)).into(), 16_u32)
+ shl((*sha.at(22)).into(), 8_u32)
+ (*sha.at(23)).into(),
shl((*sha.at(24)).into(), 24_u32)
+ shl((*sha.at(25)).into(), 16_u32)
+ shl((*sha.at(26)).into(), 8_u32)
+ (*sha.at(27)).into(),
shl((*sha.at(28)).into(), 24_u32)
+ shl((*sha.at(29)).into(), 16_u32)
+ shl((*sha.at(30)).into(), 8_u32)
+ (*sha.at(31)).into(),
];

r
}

/// Computes BIP0340/challenge tagged hash.
///
/// References:
Expand Down
1 change: 1 addition & 0 deletions onchain/src/social.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod account;
pub mod bech32;
pub mod profile;
pub mod request;
pub mod transfer_request;
36 changes: 35 additions & 1 deletion onchain/src/social/account.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
use starknet::{ContractAddress, get_caller_address, get_contract_address, contract_address_const};
use super::profile::NostrProfile;

// request types added temporarily for the OD Hack
#[derive(Copy, Drop, Debug, Serde)]
pub struct Signature {
r: u256,
s: u256
}

#[derive(Drop, Serde)]
pub struct TransferRequest {
amount: u256,
token: felt252,
joyboy: NostrProfile,
recipient: NostrProfile
}

#[derive(Drop, Serde)]
pub struct SocialRequest {
pubkey: u256,
created_at: u64,
kind: u16,
tags: ByteArray, // we don't need to look inside the tags(at least for now)
content: TransferRequest,
sig: Signature
}


#[starknet::interface]
pub trait ISocialAccount<TContractState> {
fn get_public_key(self: @TContractState) -> u256;
fn handle_transfer_request(ref self: TContractState, request: SocialRequest);
}


#[starknet::contract]
pub mod SocialAccount {
use super::SocialRequest;
use super::TransferRequest;

#[storage]
struct Storage {
#[key]
Expand Down Expand Up @@ -37,6 +68,10 @@ pub mod SocialAccount {
fn get_public_key(self: @ContractState) -> u256 {
self.public_key.read()
}
fn handle_transfer_request(
ref self: ContractState, request: SocialRequest
) { // TODO: implement handle transfer logic
}
}
}

Expand Down Expand Up @@ -99,4 +134,3 @@ mod tests {
assert!(get_public_key == 45, "Public key is not the same");
}
}

3 changes: 2 additions & 1 deletion onchain/src/social/bech32.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! bech32 encoding implementation

use core::traits::{Into, TryInto};
use core::array::ToSpanTrait;
// TODO: uncomment once Cairo 2.7 is available
// use core::array::ToSpanTrait;
use core::option::OptionTrait;
use core::array::ArrayTrait;
use core::byte_array::ByteArrayTrait;
Expand Down
5 changes: 3 additions & 2 deletions onchain/src/social/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use core::option::OptionTrait;
use core::traits::TryInto;
use core::byte_array::ByteArrayTrait;
use core::array::SpanTrait;
use core::array::ToSpanTrait;
// TODO: uncomment once Cairo 2.7 is available
// use core::array::ToSpanTrait;

//! Representation of Nostr profiles

use super::bech32;

#[derive(Drop, Debug)]
#[derive(Drop, Debug, Serde)]
pub struct NostrProfile {
pub public_key: u256,
pub relays: Array<ByteArray> //UTF-8 encoded
Expand Down
2 changes: 1 addition & 1 deletion onchain/src/social/transfer_request.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl DisplayTransferRequest of Display<TransferRequest> {
mod tests {
use core::option::OptionTrait;
use super::{TransferRequest};
use super::nostr_profile::NostrProfile;
use super::super::profile::NostrProfile;

#[test]
fn test_fmt() {
Expand Down
4 changes: 2 additions & 2 deletions onchain/src/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Pow2u8u8 of Pow2<u8, u8> {
5 => 0b100000,
6 => 0b1000000,
7 => 0b10000000,
_ => core::panic_with_felt252('n = {n} ouf of range'),
_ => core::panic_with_felt252('n ouf of range'),
}
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Pow2u32u32 of Pow2<u32, u32> {
29 => 0b100000000000000000000000000000,
30 => 0b1000000000000000000000000000000,
31 => 0b10000000000000000000000000000000,
_ => core::panic_with_felt252('n = {n} ouf of range'),
_ => core::panic_with_felt252('n ouf of range'),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/DownloadSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DownloadSection: React.FC = () => {
Download Joyboy
</h2>
<p className="text-[24px] leading-7 mb-[47px] w-[623px]">
Joyboy is available on Andriod, iOS, iPadOS and macOS. It's free and
Joyboy is available on Android, iOS, iPadOS and macOS. It's free and
open source.
</p>
<div className="flex items-center gap-x-5">
Expand Down

0 comments on commit 3ba8a41

Please sign in to comment.