Skip to content

Instantly share code, notes, and snippets.

View irzhywau's full-sized avatar

Irzhy Ranaivoarivony irzhywau

View GitHub Profile
@irzhywau
irzhywau / decrypt.js
Created August 21, 2025 19:13
Lit - Decryption process (frontend)
const litAction0 = async () => {
console.log('Decrypting CEK...', { kid, ciphertext, dataToEncryptHash, publicKey });
// 1. Decrypt the CEK using Lit's access control
const cek = await Lit.Actions.decryptAndCombine({
accessControlConditions: [
{
conditionType: "evmContract",
chain: "arbitrumSepolia",
contractAddress: "0x4Ba1151B5bc5B39500ff8D3B277eC6d217cB33ee",
functionName: "hasAccessByContentId",
@irzhywau
irzhywau / lit-encrypt.js
Created August 21, 2025 19:12
Lit - Encryption process (backend)
// KID and CEK are parameters
const { ciphertext, dataToEncryptHash, ...rest } = await lit.encrypt({
unifiedAccessControlConditions: [
{
conditionType: "evmContract",
chain: 'arbitrumSepolia',
contractAddress: '0x4Ba1151B5bc5B39500ff8D3B277eC6d217cB33ee',
functionName: 'hasAccessByContentId',
functionParams: [':userAddress', KID],
functionAbi: {
@irzhywau
irzhywau / HiveUploaderContext.js
Created August 9, 2022 08:29
Sandboxing hive and did authentication flow in a backend context
const { Logger, VerifiablePresentation, JWTHeader, JWTParserBuilder, Issuer, DIDURL } = require('@elastosfoundation/did-js-sdk')
const { AppContext, Vault, HiveException } = require('@elastosfoundation/hive-js-sdk')
const didConfig = require("../../config/elastos.did");
const hiveConfig = require("../../config/elastos.hive");
const { AppDID, UserDID } = require("./entities");
class ElacityHiveContext {
constructor(subFolder = null) {
this.localDataDir = `${didConfig.FOLDER.METADATA}/${(didConfig.APP.DID).split(':').pop()}` + (subFolder ? `/${subFolder}` : '');
@irzhywau
irzhywau / ERC20WrappableSupport.sol
Last active March 27, 2022 18:18
wrap/unwrap token inside of a contract
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IERC20Wrappable.sol";
contract ERC20WrappableSupport {
modifier withWrap(address payable wToken) {
@irzhywau
irzhywau / ConnectorSelect.tsx
Created January 5, 2022 13:09
dapps browser connect attempts
// we are in an create-react-app context
export default () => {
const [mm, setSupport] = React.useState<MetamaskSupport | null>(null);
React.useEffect(() => {
let alreadyHandled = false;
// as the provider may be not available all the time on mobile, we need this side-effect implementation
// see https://docs.metamask.io/guide/mobile-best-practices.html#the-provider-window-ethereum
// also see https://github.com/MetaMask/detect-provider

Keybase proof

I hereby claim:

  • I am irzhywau on github.
  • I am irzhy (https://keybase.io/irzhy) on keybase.
  • I have a public key ASDIWYDt8qwr77P6AfGveU0kR2IQTiUymnu8aGoFNIRtqwo

To claim this, I am signing this object:

@irzhywau
irzhywau / appview.ts
Last active June 21, 2019 16:21
Fetch complete dataset
parallelLimit(_map(offsets, o => (callback: Function) => {
if (cancelRequest) {
callback(new Error(`Request canceled by client`), null);
}
// we implemented retry pattern which focus on RateLimitError only
retry({
times: retries
, interval: function (retryCount) {
console.log(`retry... #${retryCount}, last client: ${podio.clientId}`);
@irzhywau
irzhywau / PodioItem.ts
Created June 21, 2019 16:15
Formatting data
// inside the formatter method
parallel(_map(item.fields, (field: any) => {
return (callback: Function) => {
let value: any = null;
switch (field.type) {
case 'category':
value = _map(field.values, (val: any) => { return { id: val.value.id, text: val.value.text } });
break;
case 'image':
@irzhywau
irzhywau / appview.jsx
Created June 21, 2019 16:08
Rendering table on front
render() {
//change to let
let {columns, fields, cache, element_id} = this.props;
let {data, pages, loading, error} = this.state;
// get user session, unique for each browser
let sessionId = getPHPSessId();
const Error = ({error}) => (
<span style={{fontSize: "120%", color:"#ff0000", width:"100%", textAlign:"center", display:"inline-block"}}>Oops!! {error}</span>
@irzhywau
irzhywau / CacheDrivenCollection.php
Last active June 21, 2019 16:09
Retrieving data from cache
<?php
// this piece is wrapped in a method of the class in charge of handling data to / from cache
$this->bootCollection();
$dataset = $this->fetch($this->appViewStoragePath."{$app_id}-{$this->table->key}.json", true);
// --- Filter data (settings-based filters)
$dataset = $this->applyFilterAndSearch($dataset, $this->searchFilter);
// --- Filter data (user filters)