Skip to content

Instantly share code, notes, and snippets.

View devlongs's full-sized avatar

devlongs devlongs

View GitHub Profile
export const fromHexString = (inp: Buffer | string): Buffer => {
if (typeof inp === 'string') {
if (inp.startsWith('0x')) {
return Buffer.from(inp.slice(2), 'hex')
}
return Buffer.from(inp, 'hex')
}
// If inp is already a Buffer, just return it
return inp
@devlongs
devlongs / public_key_cryptography.go
Created September 18, 2024 11:28
This code generates private keys, public keys, public addresses, signing messages and verifyinig signatures
package crypto
import (
"crypto/ed25519"
"crypto/rand"
"encoding/hex"
"errors"
"io"
)
package main
import (
"crypto/ecdsa"
"fmt"
"log"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
)
@devlongs
devlongs / keccak256_hashing.go
Last active September 14, 2024 17:54
Keccahk256 hashing in Go using the golang.org/x/crypto/sha3 library
package main
import (
"fmt"
"golang.org/x/crypto/sha3"
)
func main() {
data := "Hello, Ethereum!"
@devlongs
devlongs / hashing.go
Created September 14, 2024 17:28
Hashing in Go using the crypto/sha256 library
package main
import (
"crypto/sha256"
"fmt"
)
func main() {
hash := sha256.New()
hash.Write([]byte("Hello, World!"))
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.4;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Erc20Token is ERC20("fire on", "FIO") {
constructor() {
_mint(address(this), 10000e18);
}
//SPDX-License-Identifier: GPL-3.0;
pragma solidity 0.8.7;
contract Energy {
//have total supply
//transferrable
//name
//symbol
//decimal
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Vault {
// a contract where the owner create grant for a beneficiary;
//allows beneficiary to withdraw only when time elapse
//allows owner to withdraw before time elapse
//get information of a beneficiary
//amount of ethers in the smart contract
@devlongs
devlongs / Tuple.sol
Last active August 4, 2022 13:02
A snippet showing how tuple works in solidity.
// SPDX-License-Identifier:MIT
pragma solidity 0.8.0;
contract Tuple {
function getValues() public pure returns (int, bool) {
return (49, true);
}
function get() public pure returns (int) {
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.0;
contract Bank {
address public owner;
mapping(address => uint256) depositor;
address[] public depositors;
constructor() {