Skip to content

Instantly share code, notes, and snippets.

  1. In the AWS console, go to Key Management Service (KMS) and click the Create Key button. Configure the key in the following way:
  • Key type: Asymmetric
  • Key usage: Sign and verify
  • Key spec: ECC_SECG_P256K1
  • Advanced options: External (Import Key material)
  1. Click the Next button to go through the configuration of the labels, administrative and usage permissions, to finally click the Finish button at the end of the process.

  2. Select your Key spec and Wrapping algorithm or leave the default settings and click the Download wrapping public key and import token button. It will download a zip file with ImportToken.bin, README.txt and WrappingPublicKey.bin files in it.

FROM alpine:3.16 as build
ARG openssl_version=1.1.1d
WORKDIR /local/build
RUN apk add --no-cache make gcc curl perl musl-dev linux-headers
RUN curl -O https://www.openssl.org/source/openssl-${openssl_version}.tar.gz
RUN tar -zxf openssl-${openssl_version}.tar.gz && rm openssl-${openssl_version}.tar.gz
RUN sed -i 's/BIO_get_cipher_ctx(benc, \&ctx);/BIO_get_cipher_ctx(benc, \&ctx);\nEVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);/' openssl-${openssl_version}/apps/enc.c
RUN mkdir /local/ssl && \
@BonneVoyager
BonneVoyager / makeRequest.js
Created May 21, 2020 14:16
Make a Node.js request without any external dependencies (useful for Firebase/Lambda functions or such).
const makeRequest = (url, method, headers, data) =>
new Promise((resolve, reject) => {
const parsedUrl = require('url').parse(url);
const isHttps = parsedUrl.protocol === 'https:';
const lib = isHttps ? require('https') : require('http');
const request = lib.request({
headers,
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: isHttps ? 443 : 80,
@BonneVoyager
BonneVoyager / replaceEnvNginx.sh
Created February 17, 2020 21:40
Replace all the environment variables in a file (eg: nginx config file) via SH.
sh -c "envsubst \"`env | awk -F = '{printf \" \\\\$%s\", $1}'`\" \
< /etc/nginx/conf.d/nginx.template \
> /etc/nginx/conf.d/default.conf"
@BonneVoyager
BonneVoyager / restoreAccountFromWeb3SignedMessage.js
Last active November 16, 2022 15:46
Sign a message within web3 and then verify the signed message on the backend as a proof that the user doesn't impersonate for someone.
// First sign a 'message' on the frontend:
const web3 = new Web3(Web3.givenProvider)
const __message__ = 'abc'
web3.eth.requestAccounts()
.then((accounts) =>
web3.eth.personal.sign(__message__, accounts[0]) // this will return a 'signature'
)
// ... and then pass the message and the signature to the backend to recover public address of the signer:
const ethUtil = require('ethereumjs-util')
@BonneVoyager
BonneVoyager / ipTestLamda.js
Last active December 20, 2019 13:27
Get Public IP of AWS Lambda function
exports.handler = async (event) =>
await new Promise((resolve) => {
let ipAddress = ''
require('https').request({
hostname: 'api.ipify.org',
path: '/?format=text',
agent: false
}, function(res) {
if (res.statusCode != 200) {
throw new Error('non-OK status: ' + res.statusCode);
@BonneVoyager
BonneVoyager / brew-install.sh
Last active April 20, 2020 13:57
brew installs
brew install git git-extras
# Utilities
brew cask install 1password alfred dropbox libreoffice moom the-unarchiver transmission vlc
# Development
brew cask install cyberduck db-browser-for-sqlite imageoptim insomnia iterm2 mysqlworkbench poedit robo-3t shimo
# Other
brew install Lykegenes/tap/spotifyd spotify-tui
@BonneVoyager
BonneVoyager / vscode.json
Last active September 22, 2021 18:04
VSCode Settings
{
"editor.fontSize": 14,
"editor.tabSize": 2,
"editor.lineHeight": 25,
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"editor.insertSpaces": true,
"editor.renderWhitespace": "none",
"editor.cursorStyle": "block",
"editor.cursorBlinking": "solid",
function getFormattedDate(date) {
const d = date || new Date()
const formattedDate = d.getFullYear() + "-" + ('0' + (d.getMonth() + 1)).slice(-2) +
"-" + ('0' + d.getDate()).slice(-2) + " " + ('0' + d.getHours()).slice(-2) + ":" +
('0' + d.getMinutes()).slice(-2) + ":" + ('0' + d.getSeconds()).slice(-2) + "." +
(d.getTime() % 1000 + '000').substr(0, 3)
return formattedDate
}