This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# references: | |
# https://ethereum.stackexchange.com/questions/114680/is-it-possible-to-use-non-deterministic-ecdsa-signatures-schemes-for-signing-eth | |
# https://eth-account.readthedocs.io/en/stable/eth_account.html#eth_account.account.Account.recover_message | |
from ecdsa import SigningKey, SECP256k1 | |
from eth_account import Account | |
from eth_account.messages import encode_defunct, defunct_hash_message | |
message = encode_defunct(text="I♥SF") | |
mh = defunct_hash_message(text="I♥SF") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// go to https://near.github.io/seed-recovery/ and click the random button at the bottom | |
// copy publicKey AND seed phrase somewhere SAFE | |
// use the same tool to find the public key of an existing seed phrase OR call | |
near keys [accountId] | |
// once you have both public keys AND the new seed phrase SAFELY STORED | |
near add-key [accountId] [newPublicKey] | |
near delete-key [accountId] [oldPublicKey] | |
// Reference: https://www.npmjs.com/package/near-cli#near-add-key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const META_KEY: string = '_M' | |
export class Object { | |
state: DurableObjectState | |
meta: any | |
data: any | |
timeouts: any | |
constructor(state: DurableObjectState, env: Env) { | |
this.state = state; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new near instance (for NodeJS use InMemoryKeyStore) | |
// do this once somewhere when app "mounts" or loads | |
const near = new Near({ | |
networkId, | |
nodeUrl, | |
walletUrl, | |
deps: { | |
keyStore: new keyStores.BrowserLocalStorageKeyStore() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JS (node - for browser you need to use btoa(String.fromCharCode(...new Uint8Array(...))) | |
const hash = sha256.create(); | |
const hashesBase64 = [ | |
'some string' | |
].map((src) => { | |
return Buffer.from(hash.update(src).array()).toString('base64') | |
}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as nearAPI from 'near-api-js'; | |
const { | |
Account, | |
KeyPair, | |
} = nearAPI; | |
// near is your current near connection instance (somewhere in your app init) | |
export const getAccessKeyAccount = (near, accountId, secretKey) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set the network (if you want mainnet) | |
export NEAR_ENV=mainnet | |
// choose 1 or 2 | |
// 1. NEAR wallet login | |
near login | |
// 2. LEDGER replace ACCOUNT_ID | |
// change useLedgerKey value if you are using custom ledger path | |
near repl --accountId="ACCOUNT_ID" --useLedgerKey="44'/397'/0'/0'/1'" | |
// REPL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use square image or 1200x628 | |
<head> | |
<meta property="og:title" content=""> | |
<meta property="og:image" content=""> | |
<meta property="og:type" content="website"> | |
<meta name="twitter:card" content="summary_large_image"> | |
<meta name="twitter:site" content="@mattdlockyer"> | |
<meta name="twitter:creator" content="@mattdlockyer"> | |
<meta property="twitter:image:alt" content=""> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// anywhere in your contract | |
fn random_u128() -> u128 { | |
let random_seed = env::random_seed(); // len 32 | |
// using first 16 bytes (doesn't affect randomness) | |
as_u128(random_seed.get(..16).unwrap()) | |
} | |
fn as_u128(arr: &[u8]) -> u128 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modal = document.createElement('div') | |
modal.innerHTML = '<span id="close-modal">x</span>' | |
style = modal.style | |
modal.style.zIndex = 1000 | |
modal.style.width = modal.style.height = '90%' | |
modal.style.background = 'white' | |
modal.style.position = 'absolute' | |
modal.style.top = modal.style.left = '5%' | |
modal.style.padding = '16px' | |
document.body.appendChild(modal) |
NewerOlder