Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@ssc-half-light/util

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ssc-half-light/util

Utility functions related to the webcrypto API

latest
Source
npmnpm
Version
0.11.5
Version published
Weekly downloads
4
-75%
Maintainers
1
Weekly downloads
 
Created
Source

util

tests Socket Badge types module license

Utility functions

Depends on uint8arrays and @oddjs/odd.

install

npm i @ssc-half-light/util

API

verify

Works in node or browsers.

async (did:string, sig:string, msg:string):Promise<boolean>

example — verify

import { verify } from '@ssc-half-light/util'

const DID = 'did:key:z13V3Sog2Ya...'
const sig = 'X8iGF4Lz4erw4UE...'

const isValid = await verify(DID, sig, 'my message')

sign

(keystore:KeyStore, msg:string):Promise<Uint8Array>

example — sign

This depends on a keystore instance.

import { sign, toString } from '@ssc-half-light/util'
import * as odd from '@oddjs/odd'

const program = await odd.program({
    namespace: { creator: 'test', name: 'testing' },
    debug: true
})
const { keystore } = program.components.crypto
const sig = toString(await sign(keystore, 'my message'))

toString

Return a 'base64url' string. Good for getting a string version of a signature.

function toString (arr:Uint8Array):string

example — toString

test('toString', t => {
    const myString = toString(myUint8Array)
    t.equal(typeof myString, 'string', 'should conver a Uint8Array to string')
})

writeKeyToDid

Convert a given public key to a DID string.

async function writeKeyToDid (crypto:Crypto.Implementation):Promise<DID>

example

import { writeKeyToDid } from '@ssc-half-light/util'

test('writeKeyToDid', async t => {
    const crypto = program.components.crypto
    const did = await writeKeyToDid(crypto)
    console.log('**did**', did)
    t.equal(typeof did, 'string', 'should create string')
    t.ok(did.includes('did:key:'), 'should return the right format string')
})

didToPublicKey

Convert a DID string to a Uint8Array and type string.

function didToPublicKey (did:string):({
    publicKey:Uint8Array,
    type: 'rsa' | 'ed25519' | 'bls12-381'
})

example — didToPublicKey

Get the DID version of the key used to sign messages.

test('didToPublicKey', t => {
    const did = 'did:key:z13...'
    const pubKey = didToPublicKey(did)

    t.equal(pubKey.type, 'rsa', 'should return the right key type')
    t.ok(pubKey.publicKey instanceof Uint8Array,
        'should return the public key as a Uint8Array')
})

Keywords

template

FAQs

Package last updated on 16 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts