Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
<100 subscribers
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
AWS의 KMS로 이더리움 트랜잭션 사인이 가능하다는 것을 얼마전에 알았다.
마침 조사를 해보니 좋은 예시들이 몇 개 있어서 공유하고자 한다.
첫 번째로 KMS에서 ECDSA 키를 생성해주어야 한다.
다음과 같은 형태로 만들어주면 된다.

이제부터 코드로 보면 된다. 다음과 같이 kms 서비스를 생성한다.
func main() {
accessKey := "<access-key>"
secretKey := "<secret-key>"
sess, err := session.NewSession(&aws.Config{
Region: aws.String("<region>"),
Credentials: credentials.NewStaticCredentialsFromCreds(credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
}),
})
if err != nil {
panic(err)
}
svc := kms.New(sess)
}
바로 KMS에 생성한 리소스에 접근해보자.
key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}
잘 안된다면 변수 값을 확인해보거나, 리소스 권한 등을 의심해보자.
다음으로 encoding/asn1 라이브러리를 사용해서 퍼블릭 키를 추출해오자.
import "encoding/asn1"
type asn1EcPublicKey struct {
EcPublicKeyInfo asn1EcPublicKeyInfo
PublicKey asn1.BitString
}
type asn1EcPublicKeyInfo struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.ObjectIdentifier
}
func main() {
// ...
key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
}
로그를 찍어보면 알겠지만 우리가 아는 퍼블릭 키와 많이 다르다.
go-ethereum의 crypto 라이브러리를 사용해보자.
이제 이 public key를 통해 지갑 주소를 얻어낼 수 있다.
import "github.com/ethereum/go-ethereum/crypto"
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
log.Println(string(asn1Key.PublicKey.Bytes))
pubKey, err := crypto.UnmarshalPubkey(asn1Key.PublicKey.Bytes)
if err != nil {
panic(err)
}
log.Println(pubKey)
keyAddr := crypto.PubkeyToAddress(*pubKey)
log.Println(keyAddr.Hex())
https://aws.amazon.com/ko/blogs/database/how-to-sign-ethereum-eip-1559-transactions-using-aws-kms/
https://github.com/welthee/go-ethereum-aws-kms-tx-signer/tree/main
AWS의 KMS로 이더리움 트랜잭션 사인이 가능하다는 것을 얼마전에 알았다.
마침 조사를 해보니 좋은 예시들이 몇 개 있어서 공유하고자 한다.
첫 번째로 KMS에서 ECDSA 키를 생성해주어야 한다.
다음과 같은 형태로 만들어주면 된다.

이제부터 코드로 보면 된다. 다음과 같이 kms 서비스를 생성한다.
func main() {
accessKey := "<access-key>"
secretKey := "<secret-key>"
sess, err := session.NewSession(&aws.Config{
Region: aws.String("<region>"),
Credentials: credentials.NewStaticCredentialsFromCreds(credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
}),
})
if err != nil {
panic(err)
}
svc := kms.New(sess)
}
바로 KMS에 생성한 리소스에 접근해보자.
key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}
잘 안된다면 변수 값을 확인해보거나, 리소스 권한 등을 의심해보자.
다음으로 encoding/asn1 라이브러리를 사용해서 퍼블릭 키를 추출해오자.
import "encoding/asn1"
type asn1EcPublicKey struct {
EcPublicKeyInfo asn1EcPublicKeyInfo
PublicKey asn1.BitString
}
type asn1EcPublicKeyInfo struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.ObjectIdentifier
}
func main() {
// ...
key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
}
로그를 찍어보면 알겠지만 우리가 아는 퍼블릭 키와 많이 다르다.
go-ethereum의 crypto 라이브러리를 사용해보자.
이제 이 public key를 통해 지갑 주소를 얻어낼 수 있다.
import "github.com/ethereum/go-ethereum/crypto"
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
log.Println(string(asn1Key.PublicKey.Bytes))
pubKey, err := crypto.UnmarshalPubkey(asn1Key.PublicKey.Bytes)
if err != nil {
panic(err)
}
log.Println(pubKey)
keyAddr := crypto.PubkeyToAddress(*pubKey)
log.Println(keyAddr.Hex())
https://aws.amazon.com/ko/blogs/database/how-to-sign-ethereum-eip-1559-transactions-using-aws-kms/
https://github.com/welthee/go-ethereum-aws-kms-tx-signer/tree/main
No comments yet