bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 10쪽
ic key
#### Returns
The 20-byte Ethereum address derived from the public key
## Examples
```rust theme={null}
use starknet::eth_signature::public_key_point_to_eth_address;
use starknet::secp256k1::Secp256k1Point;
use starknet::secp256_trait::Secp256Trait;
let public_key: Secp256k1Point = Secp256Trait::secp256_ec_get_point_from_x_syscall(
0xa9a02d48081294b9bb0d8740d70d3607feb20876964d432846d9b9100b91eefd, false,
)
.unwrap()
.unwrap();
let eth_address = public_key_point_to_eth_address(public_key);
assert!(eth_address == 0x767410c1bb448978bd42b984d7de5970bcaf5c43.try_into().unwrap());
```
# core::starknet::eth_signature::verify_eth_signature
Source: https://docs.starknet.io/build/corelib/core-starknet-eth_signature-verify_eth_signature
Asserts that an Ethereum signature is valid for a given message hash and Ethereum address.
Also verifies that the `r` and `s` components of the signature are in the range `[1, N)`,
where N is the size of the curve.
## Signature
```rust theme={null}
pub fn verify_eth_signature(msg_hash: u256, signature: Signature, eth_address: EthAddress)
```
#### Arguments
* `msg_hash` - The 32-byte hash of the message that was signed
* `signature` - The Ethereum signature containing `r`, `s` components and `y_parity`
* `eth_address` - The expected Ethereum address of the signer
#### Panics
Panics if:
* The signature components are out of range (not in \[1, N) where N is the curve order)
* The recovered address doesn't match the provided address
## Examples
```rust theme={null}
use starknet::eth_address::EthAddress;
use starknet::eth_signature::verify_eth_signature;
use starknet::secp256_trait::Signature;
let msg_hash = 0xe888fbb4cf9ae6254f19ba12e6d9af54788f195a6f509ca3e934f78d7a71dd85;
let r = 0x4c8e4fbc1fbb1dece52185e532812c4f7a5f81cf3ee10044320a0d03b62d3e9a;
let s = 0x4ac5e5c0c0e8a4871583cc131f35fb49c2b7f60e6a8b84965830658f08f7410c;
let y_parity = true;
let eth_address: EthAddress = 0x767410c1bb448978bd42b984d7de5970bcaf5c43_u256
.try_into()
.unwrap();
verify_eth_signature(msg_hash, Signature { r, s, y_parity }, eth_address);
```
# core::starknet::event::Event
Source: https://docs.starknet.io/build/corelib/core-starknet-event-Event
A trait for handling serialization and deserialization of events.
Events in Starknet are stored in transaction receipts as a combination of keys and data fields.
This trait provides the methods needed to serialize event data into these fields and deserialize
them back into their original form.
This trait can easily be derived using the `#[derive(starknet::Event)]` attribute.
Fields can be marked as keys using the `#[key]` attribute to serialize them as event keys.
## Signature
```rust theme={null}
pub trait Event
```
## Examples
```rust theme={null}
#[derive(Drop, starknet::Event)]
pub struct Transfer {
#[key]
pub from: ContractAddress,
#[key]
pub to: ContractAddress,
pub amount: u256,
}
```
## Trait functions
### append\_keys\_and\_data
Serializes the keys and data for event emission.
The keys array will contain:
* The event name selector as the first key
* Any fields marked with #key as subsequent keys
The data array will contain all non-key fields.
#### Signature
```rust theme={null}
fn append_keys_and_data(self: @T, ref keys: Array, ref data: Array)
```
### deserialize
Deserializes events keys and data back into the original event structure.
Returns `None` if deserialization fails.
#### Signature
```rust theme={null}
fn deserialize(ref keys: Span, ref data: Span) -> Option
```
# core::starknet::event::EventEmitter
Source: https://docs.starknet.io/build/corelib/core-starknet-event-EventEmitter
A trait for emitting Starknet events.
## Signature
```rust theme={null}
pub trait EventEmitter
```
## Examples
```rust theme={null}
#[derive(Drop, starknet::Event)]
pub struct NewOwner {
pub new_owner: ContractAddress,
}
fn emit_event(ref self: ContractState, new_owner: ContractAddress) {
self.emit(NewOwner { new_owner });
}
```
## Trait functions
### emit
Emits an event.
#### Signature
```rust theme={null}
fn emit>(ref self: T, event: S)
```
# core::starknet::info::BlockInfo
Source: https://docs.starknet.io/build/corelib/core-starknet-info-BlockInfo
Information about the current block.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug, Serde)]
pub struct BlockInfo {
pub block_number: u64,
pub block_timestamp: u64,
pub sequencer_address: ContractAddress,
}
```
## Members
### block\_number
The number, that is, the height, of this block.
#### Signature
```rust theme={null}
pub block_number: u64
```
### block\_timestamp
The time at which the sequencer began building the block, in seconds since the Unix epoch.
#### Signature
```rust theme={null}
pub block_timestamp: u64
```
### sequencer\_address
The Starknet address of the sequencer that created the block.
#### Signature
```rust theme={null}
pub sequencer_address: ContractAddress
```
# core::starknet::info::get_block_info
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_block_info
Returns the block information for the current block.
## Signature
```rust theme={null}
pub fn get_block_info() -> Box
```
## Examples
```rust theme={null}
use starknet::get_block_info;
let block_info = get_block_info().unbox();
let block_number = block_info.block_number;
let block_timestamp = block_info.block_timestamp;
let sequencer = block_info.sequencer_address;
```
# core::starknet::info::get_block_number
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_block_number
Returns the number of the current block.
## Signature
```rust theme={null}
pub fn get_block_number() -> u64
```
## Examples
```rust theme={null}
use starknet::get_block_number;
let block_number = get_block_number();
```
# core::starknet::info::get_block_timestamp
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_block_timestamp
Returns the timestamp of the current block.
## Signature
```rust theme={null}
pub fn get_block_timestamp() -> u64
```
## Examples
```rust theme={null}
use starknet::get_block_timestamp;
let block_timestamp = get_block_timestamp();
```
# core::starknet::info::get_caller_address
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_caller_address
Returns the address of the caller contract.
Returns `0` if there is no caller—for example, when a transaction begins execution inside an
account contract.
Note: This function returns the direct caller. If you're interested in the account that
initiated the transaction, use `get_execution_info().tx_info.unbox().account_contract_address`
instead.
## Signature
```rust theme={null}
pub fn get_caller_address() -> ContractAddress
```
## Examples
```rust theme={null}
use starknet::get_caller_address;
let caller = get_caller_address();
```
# core::starknet::info::get_contract_address
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_contract_address
Returns the address of the contract being executed.
## Signature
```rust theme={null}
pub fn get_contract_address() -> ContractAddress
```
## Examples
```rust theme={null}
use starknet::get_contract_address;
let contract_address = get_contract_address();
```
# core::starknet::info::get_execution_info
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_execution_info
Returns the execution info for the current execution.
## Signature
```rust theme={null}
pub fn get_execution_info() -> Box
```
## Examples
```rust theme={null}
use starknet::get_execution_info;
let execution_info = get_execution_info().unbox();
// Access various execution context information
let caller = execution_info.caller_address;
let contract = execution_info.contract_address;
let selector = execution_info.entry_point_selector;
```
# core::starknet::info::get_tx_info
Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_tx_info
Returns the transaction information for the current transaction.
## Signature
```rust theme={null}
pub fn get_tx_info() -> Box
```
## Examples
```rust theme={null}
use starknet::get_tx_info;
let tx_info = get_tx_info().unbox();
let account_contract_address = tx_info.account_contract_address;
let chain_id = tx_info.chain_id;
let nonce = tx_info.nonce;
let max_fee = tx_info.max_fee;
let tx_hash = tx_info.transaction_hash;
let signature = tx_info.signature;
let version = tx_info.version;
```
# core::starknet::info::v2::ExecutionInfo
Source: https://docs.starknet.io/build/corelib/core-starknet-info-v2-ExecutionInfo
The same as `ExecutionInfo`, but with the `TxInfo` field replaced with `v2::TxInfo`.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug)]
pub struct ExecutionInfo {
pub block_info: Box,
pub tx_info: Box,
pub caller_address: ContractAddress,
pub contract_address: ContractAddress,
pub entry_point_selector: felt252,
}
```
## Members
### block\_info
#### Signature
```rust theme={null}
pub block_info: Box
```
### tx\_info
#### Signature
```rust theme={null}
pub tx_info: Box
```
### caller\_address
#### Signature
```rust theme={null}
pub caller_address: ContractAddress
```
### contract\_address
#### Signature
```rust theme={null}
pub contract_address: ContractAddress
```
### entry\_point\_selector
#### Signature
```rust theme={null}
pub entry_point_selector: felt252
```
# core::starknet::info::v2::ResourceBounds
Source: https://docs.starknet.io/build/corelib/core-starknet-info-v2-ResourceBounds
V3 transactions resources used for enabling the fee market.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug, Serde)]
pub struct ResourceBounds {
pub resource: felt252,
pub max_amount: u64,
pub max_price_per_unit: u128,
}
```
## Members
### resource
The name of the resource.
#### Signature
```rust theme={null}
pub resource: felt252
```
### max\_amount
The maximum amount of the resource allowed for usage during the execution.
#### Signature
```rust theme={null}
pub max_amount: u64
```
### max\_price\_per\_unit
The maximum price the user is willing to pay for the resource unit.
#### Signature
```rust theme={null}
pub max_price_per_unit: u128
```
# core::starknet::info::v2::TxInfo
Source: https://docs.starknet.io/build/corelib/core-starknet-info-v2-TxInfo
Extended information about the current transaction.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug, Serde)]
pub struct TxInfo {
pub version: felt252,
pub account_contract_address: ContractAddress,
pub max_fee: u128,
pub signature: Span,
pub transaction_hash: felt252,
pub chain_id: felt252,
pub nonce: felt252,
pub resource_bounds: Span,
pub tip: u128,
pub paymaster_data: Span,
pub nonce_data_availability_mode: u32,
pub fee_data_availability_mode: u32,
pub account_deployment_data: Span,
}
```
## Members
### version
The version of the transaction. It is fixed (currently, 1) in the OS, and should be
signed by the account contract.
This field allows invalidating old transactions, whenever the meaning of the other
transaction fields is changed (in the OS).
#### Signature
```rust theme={null}
pub version: felt252
```
### account\_contract\_address
The account contract from which this transaction originates.
#### Signature
```rust theme={null}
pub account_contract_address: ContractAddress
```
### max\_fee
The `max_fee` field of the transaction.
#### Signature
```rust theme={null}
pub max_fee: u128
```
### signature
The signature of the transaction.
#### Signature
```rust theme={null}
pub signature: Span
```
### transaction\_hash
The hash of the transaction.
#### Signature
```rust theme={null}
pub transaction_hash: felt252
```
### chain\_id
The identifier of the chain.
This field can be used to prevent replay of testnet transactions on mainnet.
#### Signature
```rust theme={null}
pub chain_id: felt252
```
### nonce
The transaction's nonce.
#### Signature
```rust theme={null}
pub nonce: felt252
```
### resource\_bounds
A span of `ResourceBounds` structs used for V3 transactions.
#### Signature
```rust theme={null}
pub resource_bounds: Span
```
### tip
The tip of the transaction.
#### Signature
```rust theme={null}
pub tip: u128
```
### paymaster\_data
If specified, the paymaster should pay for the execution of the transaction.
The data includes the address of the paymaster sponsoring the transaction, followed by
extra data to send to the paymaster.
Used for V3 transactions.
#### Signature
```rust theme={null}
pub paymaster_data: Span
```
### nonce\_data\_availability\_mode
The data availability mode for the nonce.
Used for V3 transactions.
#### Signature
```rust theme={null}
pub nonce_data_availability_mode: u32
```
### fee\_data\_availability\_mode
The data availability mode for the account balance from which fee will be taken.
Used for V3 transactions.
#### Signature
```rust theme={null}
pub fee_data_availability_mode: u32
```
### account\_deployment\_data
If nonempty, will contain the required data for deploying and initializing an account
contract: its class hash, address salt and constructor calldata.
Used for V3 transactions.
#### Signature
```rust theme={null}
pub account_deployment_data: Span
```
# core::starknet::secp256_trait::Secp256PointTrait
Source: https://docs.starknet.io/build/corelib/core-starknet-secp256_trait-Secp256PointTrait
A trait for performing operations on Secp2561 curve points.
Provides operations needed for elliptic curve cryptography, including point addition
and scalar multiplication.
## Signature
```rust theme={null}
pub trait Secp256PointTrait
```
## Examples
```rust theme={null}
use starknet::SyscallResultTrait;
use starknet::secp256k1::Secp256k1Point;
use starknet::secp256_trait::Secp256PointTrait;
use starknet::secp256_trait::Secp256Trait;
let generator = Secp256Trait::::get_generator_point();
assert!(
Secp256PointTrait::get_coordinates(generator)
.unwrap_syscall() == (
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8,
),
);
let point = Secp256PointTrait::add(generator, generator);
let other_point = Secp256PointTrait::mul(generator, 2);
```
## Trait functions
### get\_coordinates
Returns the x and y coordinates of the curve point.
#### Signature
```rust theme={null}
fn get_coordinates(
self: Secp256Point,
) -> Result>
```
### add
Performs elliptic curve point addition.
Adds `self` and `other` following the curve's addition law and returns
the resulting point.
#### Signature
```rust theme={null}
fn add(
self: Secp256Point, other: Secp256Point,
) -> Result>
```
### mul
Performs scalar multiplication of a curve point.
Multiplies `self` by the given scalar value.
#### Signature
```rust theme={null}
fn mul(
self: Secp256Point, scalar: u256,
) -> Result>
```
# core::starknet::secp256_trait::Secp256Trait
Source: https://docs.starknet.io/build/corelib/core-starknet-secp256_trait-Secp256Trait
A trait for interacting with Secp2561 curves.
Provides operations needed to work with Secp256k1 and Secp256r1 elliptic curves.
It includes methods for accessing curve parameters and creating curve points.
## Signature
```rust theme={null}
pub trait Secp256Trait
```
## Examples
```rust theme={null}
use starknet::secp256k1::Secp256k1Point;
use starknet::secp256_trait::Secp256Trait;
use starknet::SyscallResultTrait;
assert!(
Secp256Trait::::get_curve_size() == 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141,
);
let generator = Secp256Trait::::get_generator_point();
let generator = Secp256Trait::::secp256_ec_new_syscall(
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8,
)
.unwrap_syscall();
let random_point = Secp256Trait::::secp256_ec_get_point_from_x_syscall(
0x4aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff3, true,
);
```
## Trait functions
### get\_curve\_size
Returns the order (size) of the curve's underlying field.
This is the number of points on the curve, also known as the curve order.
#### Signature
```rust theme={null}
fn get_curve_size() -> u256
```
### get\_generator\_point
Returns the generator point (G) for the curve.
The generator point is a standard base point on the curve from which other points
can be generated through scalar multiplication.
#### Signature
```rust theme={null}
fn get_generator_point() -> Secp256Point
```
### secp256\_ec\_new\_syscall
Creates a new curve point from its x and y coordinates.
Returns `None` if the provided coordinates don't represent a valid point on the curve.
#### Signature
```rust theme={null}
fn secp256_ec_new_syscall(
x: u256, y: u256,
) -> Result, Array>
```
### secp256\_ec\_get\_point\_from\_x\_syscall
Creates a curve point on the curve given its x-coordinate and y-parity.
#### Arguments
* `x` - The x coordinate of the point
* `y_parity` - If true, choose the odd y value; if false, choose the even y value
#### Returns
Returns `Some(point)` if a point exists with the given x coordinate,
`None` otherwise.
#### Signature
```rust theme={null}
fn secp256_ec_get_point_from_x_syscall(
x: u256, y_parity: bool,
) -> Result, Array>
```
# core::starknet::secp256_trait::Signature
Source: https://docs.starknet.io/build/corelib/core-starknet-secp256_trait-Signature
Represents a Secp2561 ECDSA signature.
This struct holds the components of an ECDSA signature: `r`, `s`, and `y_parity`.
## Signature
```rust theme={null}
#[derive(Copy, Drop, Debug, PartialEq, Serde, Hash)]
pub struct Signature {
pub r: u256,
pub s: u256,
pub y_parity: bool,
}
```
## Members
### r
#### Signature
```rust theme={null}
pub r: u256
```
### s
#### Signature
```rust theme={null}
pub s: u256
```
### y\_parity
The parity of the y coordinate of the elliptic curve point whose x coordinate is `r`.
`y_parity == true` means that the y coordinate is odd.
Some places use non boolean `v` instead of `y_parity`.
In that case, `signature_from_vrs` should be used.
#### Signature
```rust theme={null}
pub y_parity: bool
```
# core::starknet::secp256k1::Secp256k1Point
Source: https://docs.starknet.io/build/corelib/core-starknet-secp256k1-Secp256k1Point
A point on the secp256k1 curve.
## Signature
```rust theme={null}
pub extern type Secp256k1Point;
```
# core::starknet::secp256r1::Secp256r1Point
Source: https://docs.starknet.io/build/corelib/core-starknet-secp256r1-Secp256r1Point
Represents a point on the secp256r1 elliptic curve.
## Signature
```rust theme={null}
pub extern type Secp256r1Point;
```
# core::starknet::storage::IntoIterRange
Source: https://docs.starknet.io/build/corelib/core-starknet-storage-IntoIterRange
Trait for turning collection of values into an iterator over a specific range.
## Signature
```rust theme={null}
pub trait IntoIterRange
```
## Trait functions
### into\_iter\_range
Creates an iterator over a range from a collection.
#### Signature
```rust theme={null}
fn into_iter_range(self: T, range: Range) -> IntoIterRangeIntoIter
```
### into\_iter\_full\_range
Creates an iterator over the full range of a collection.
#### Signature
```rust theme={null}
fn into_iter_full_range(self: T) -> IntoIterRangeIntoIter
```
## Trait types
### IntoIter
#### Signature
```rust theme={null}
type IntoIter;
```
# core::starknet::storage::Mutable
Source: https://docs.starknet.io/build/corelib/core-starknet-storage-Mutable
A wrapper around different storage related types, indicating that the instance is mutable,
i.e. originally created from a `ref` contract state.
## Signature
```rust theme={null}
#[phantom]
pub struct Mutable {}
```
# core::starknet::storage::PendingStoragePath
Source: https://docs.starknet.io/build/corelib/core-starknet-storage-PendingStoragePath
A struct for delaying the creation of a storage path, used for lazy evaluation in storage nodes.
## Signature
```rust theme={null}
pub struct PendingStoragePath프로젝트로 돌아가기