/** This file should not contain active gun instances. Only static methods on gun is allowed. */ see https import type { EC_Public_JsonWebKey } from '@masknet/shared-base' ; import Gun from 'gun' ; import 'gun/sea' ; import { memoizePromise } from '../../../../utils-pure' ; param version param postIV param partitionByCryptoKey param networkHint export async function calculatePostKeyPartition ( version , postIV , partitionByCryptoKey , networkHint ) { const postHash = await hashPostSalt ( postIV , networkHint ) ; const keyHash = await ( version <= - 39 ? hashCryptoKeyUnstable : hashCryptoKey ) ( partitionByCryptoKey ) ; return { postHash , keyHash } ; } export const hashPostSalt = memoizePromise ( async function ( postSalt , networkHint ) { const hashPair = '9283464d-ee4e-4e8d-a7f3-cf392a88133f' ; const N = 2 ; const hash = ( await Gun . SEA . work ( postSalt , hashPair ) ) ! ; return networkHint + hash . substring ( 0 , N ) ; } , ( x , y ) => x + y ) ; param key export const hashCryptoKeyUnstable = memoizePromise ( async function ( key ) { const hashPair = '10198a2f-205f-45a6-9987-3488c80113d0' ; const N = 2 ; const jwk = JSON . stringify ( key ) ; const hash = ( await Gun . SEA . work ( jwk , hashPair ) ) ! ; return hash . substring ( 0 , N ) ; } , undefined ) ; param key export const hashCryptoKey = memoizePromise ( async function ( key ) { const hashPair = '10198a2f-205f-45a6-9987-3488c80113d0' ; const N = 2 ; const jwk = key ; if ( ! jwk . x || ! jwk . y ) throw new Error ( 'Invalid key' ) ; const hash = ( await Gun . SEA . work ( jwk . x ! + jwk . y ! , hashPair ) ) ! ; return hash . substring ( 0 , N ) ; } , undefined ) ;