@evanp/activitypub-bot 0.38.1 → 0.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -321,14 +321,32 @@ export class ActivityPubClient {
321
321
  }
322
322
  }
323
323
 
324
- #resolveObject (obj, url, visited = new Set()) {
324
+ #resolveObject (obj, url) {
325
+ const objects = this.#resolveAllObjects(obj, url)
326
+ assert.ok(objects)
327
+ switch (objects.length) {
328
+ case 0:
329
+ return null
330
+ case 1:
331
+ return objects[0]
332
+ default: {
333
+ // hack to prefer `CryptographicKey` if available
334
+ const key = objects.find(
335
+ obj => obj.type === 'https://w3id.org/security#Key'
336
+ )
337
+ return (key) || objects[0]
338
+ }
339
+ }
340
+ }
341
+
342
+ #resolveAllObjects (obj, url, visited = new Set(), results = []) {
325
343
  if (obj.id && obj.id === url) {
326
- return obj
344
+ results.push(obj)
327
345
  }
328
346
 
329
347
  if (obj.id) {
330
348
  if (visited.has(obj.id)) {
331
- return null
349
+ return results
332
350
  }
333
351
  visited.add(obj.id)
334
352
  }
@@ -344,13 +362,10 @@ export class ActivityPubClient {
344
362
 
345
363
  for (const item of val) {
346
364
  if (item instanceof as2.models.Base) {
347
- const found = this.#resolveObject(item, url, visited)
348
- if (found) {
349
- return found
350
- }
365
+ this.#resolveAllObjects(item, url, visited, results)
351
366
  }
352
367
  }
353
368
  }
354
- return null
369
+ return results
355
370
  }
356
371
  }
@@ -40,18 +40,52 @@ as2.registerContext('https://w3id.org/fep/5711', {
40
40
 
41
41
  as2.registerContext('https://w3id.org/security/v1', {
42
42
  '@context': {
43
- sec: 'https://w3id.org/security#',
44
43
  id: '@id',
45
44
  type: '@type',
46
- owner: {
47
- '@id': 'sec:owner',
48
- '@type': '@id'
49
- },
50
- publicKey: {
51
- '@id': 'sec:publicKey',
52
- '@type': '@id'
53
- },
54
- publicKeyPem: 'sec:publicKeyPem'
45
+
46
+ dc: 'http://purl.org/dc/terms/',
47
+ sec: 'https://w3id.org/security#',
48
+ xsd: 'http://www.w3.org/2001/XMLSchema#',
49
+
50
+ EcdsaKoblitzSignature2016: 'sec:EcdsaKoblitzSignature2016',
51
+ Ed25519Signature2018: 'sec:Ed25519Signature2018',
52
+ EncryptedMessage: 'sec:EncryptedMessage',
53
+ GraphSignature2012: 'sec:GraphSignature2012',
54
+ LinkedDataSignature2015: 'sec:LinkedDataSignature2015',
55
+ LinkedDataSignature2016: 'sec:LinkedDataSignature2016',
56
+ CryptographicKey: 'sec:Key',
57
+
58
+ authenticationTag: 'sec:authenticationTag',
59
+ canonicalizationAlgorithm: 'sec:canonicalizationAlgorithm',
60
+ cipherAlgorithm: 'sec:cipherAlgorithm',
61
+ cipherData: 'sec:cipherData',
62
+ cipherKey: 'sec:cipherKey',
63
+ created: { '@id': 'dc:created', '@type': 'xsd:dateTime' },
64
+ creator: { '@id': 'dc:creator', '@type': '@id' },
65
+ digestAlgorithm: 'sec:digestAlgorithm',
66
+ digestValue: 'sec:digestValue',
67
+ domain: 'sec:domain',
68
+ encryptionKey: 'sec:encryptionKey',
69
+ expiration: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
70
+ expires: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
71
+ initializationVector: 'sec:initializationVector',
72
+ iterationCount: 'sec:iterationCount',
73
+ nonce: 'sec:nonce',
74
+ normalizationAlgorithm: 'sec:normalizationAlgorithm',
75
+ owner: { '@id': 'sec:owner', '@type': '@id' },
76
+ password: 'sec:password',
77
+ privateKey: { '@id': 'sec:privateKey', '@type': '@id' },
78
+ privateKeyPem: 'sec:privateKeyPem',
79
+ publicKey: { '@id': 'sec:publicKey', '@type': '@id' },
80
+ publicKeyBase58: 'sec:publicKeyBase58',
81
+ publicKeyPem: 'sec:publicKeyPem',
82
+ publicKeyWif: 'sec:publicKeyWif',
83
+ publicKeyService: { '@id': 'sec:publicKeyService', '@type': '@id' },
84
+ revoked: { '@id': 'sec:revoked', '@type': 'xsd:dateTime' },
85
+ salt: 'sec:salt',
86
+ signature: 'sec:signature',
87
+ signatureAlgorithm: 'sec:signingAlgorithm',
88
+ signatureValue: 'sec:signatureValue'
55
89
  }
56
90
  })
57
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.38.1",
3
+ "version": "0.38.2",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",