Socket
Socket
Sign inDemoInstall

@musakui/fedi

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

activitypub.d.ts

2

lib/activitypub/types.d.ts

@@ -7,3 +7,3 @@ import type {

Collection,
} from '../types'
} from '../activitystreams/types'

@@ -10,0 +10,0 @@ /** @see https://www.w3.org/TR/activitypub/#actor-objects */

@@ -6,3 +6,3 @@ import {

INTRANSITIVE_ACTIVTY_TYPES,
} from './core'
} from './core.js'

@@ -9,0 +9,0 @@ /** @see https://www.w3.org/ns/activitystreams#Object */

@@ -61,2 +61,2 @@ import * as core from './core.js'

useAlgorithm,
} from './core.js'
} from './core.js'

@@ -76,2 +76,3 @@ import { createSign, createVerify, createHash } from 'crypto'

* @param {string} accept `Accept` headers
* @return {Partial<import('../activitypub/types').Actor>}
*/

@@ -78,0 +79,0 @@ export const getKey = async (id, accept = appJSON) => {

@@ -1,2 +0,1 @@

import * as Keys from './keys/index.js'
import * as WellKnown from './well-known/index.js'

@@ -7,3 +6,2 @@ import * as ActivityPub from './activitypub/index.js'

export {
Keys,
WellKnown,

@@ -10,0 +8,0 @@ ActivityPub,

@@ -0,1 +1,5 @@

const CS = window.crypto.subtle
const SIGN = ['sign']
const VERIFY = ['verify']
const KEY_ALGO = {

@@ -8,2 +12,23 @@ name: 'RSASSA-PKCS1-v1_5',

/**
* @param {ArrayBuffer} buf
*/
const bufToB64 = (buf) => {
const arr = new Uint8Array(buf)
return window.btoa(arr.reduce((c, s) => c + String.fromCharCode(s), ''))
}
/**
* @param {string} str
*/
const b64ToBuf = (str) => {
const binStr = window.atob(str)
const binlen = binStr.length
const buf = new Uint8Array(binlen)
for (let i = 0; i < binlen; i++) {
buf[i] = binStr.charCodeAt(i)
}
return buf.buffer
}
/**
* Generates an RSA private key

@@ -14,8 +39,21 @@ * @param {number} modulusLength bit length of the RSA modulus

export const generatePrivateKey = async (modulusLength = 2048) => {
const { privateKey } = await crypto.subtle.generateKey({
const { privateKey } = await CS.generateKey({
...KEY_ALGO,
modulusLength,
}, true, ['sign'])
const arr = new Uint8Array(await crypto.subtle.exportKey('pkcs8', privateKey))
return window.btoa(arr.reduce((c, s) => c + String.fromCharCode(s), ''))
}, true, SIGN)
return bufToB64(await CS.exportKey('pkcs8', privateKey))
}
/**
* Derives the public key from an RSA private key
* @param {string} key
* @return PEM (SPKI) of private key
*/
export const fromPrivate = async (key) => {
const privateKey = await CS.importKey('pkcs8', b64ToBuf(key), KEY_ALGO, true, SIGN)
const { d, key_ops, ...jwk } = await CS.exportKey('jwk', privateKey)
const publicKey = await CS.importKey('jwk', jwk, KEY_ALGO, true, VERIFY)
return bufToB64(await CS.exportKey('spki', publicKey))
}
export * from './core.js'
import { createPublicKey } from 'crypto'
const format = 'pem'
/**
* Derives the public key from an RSA private key
* @param {string} key private key
*/
export const fromPrivate = (key) => createPublicKey({ key }).export({ format: 'pem', type: 'spki' })
export const fromPrivate = (key) => createPublicKey({ format, key }).export({ format, type: 'spki' })
export * from './core.js'

@@ -1,5 +0,2 @@

export * as Keys from './keys'
export * as WellKnown from './well-known'
export * as ActivityPub from './activitypub'
export * as ActivityStreams from './activitystreams'
export * from './index.js'

@@ -6,0 +3,0 @@ export * from './well-known/types'

@@ -1,3 +0,3 @@

import * as NodeInfo from './nodeinfo.js'
import * as WebFinger from './webfinger.js'
import * as NI from './nodeinfo.js'
import * as WF from './webfinger.js'

@@ -16,4 +16,4 @@ /**

export {
WebFinger,
NodeInfo,
NI,
WF,
}

@@ -10,5 +10,6 @@ {

"repository": "github:musakui/fedi",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"files": [
"*.d.ts",
"lib"

@@ -15,0 +16,0 @@ ],

@@ -1,3 +0,5 @@

# Fediverse Tools
# fedi
> tools for the fediverse
[![npm](https://img.shields.io/npm/v/@musakui/fedi.svg)](https://www.npmjs.com/package/@musakui/fedi)

@@ -11,23 +13,4 @@

## Usage
## Used by
### HTTP Signatures
```js
import * as HS from '@musakui/fedi/hs'
import { readFileSync } from 'fs'
HS.useKey('[keyId]', readFileSync('./private.pem'))
const resp = await HS.sendRequest({
url: 'https://mastodon.social/inbox',
headers: {
'content-type': 'application/activity+json',
},
body: JSON.stringify({
// some ActivityPub object
}),
})
console.log(await resp.text())
```
[`kotori`](https://github.com/musakui/kotori) - minimal [ActivityPub](https://activitypub.rocks/) instance
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc