skyware-js / labeler

A lightweight alternative to Ozone for operating an atproto labeler.
Mozilla Public License 2.0
22 stars 5 forks source link

"Incorrect prefix for did:key" in verifyJwt #1

Closed CodePanter closed 3 weeks ago

CodePanter commented 3 weeks ago

Hello! I've worked through the 'getting started' and 'automated labeling' documentation pages, and am stuck on this error. I feel it might have something to do with the reverse proxy step; as I had some issues getting Caddy to work, but it appears to be running, so don't know where to go from here.

As soon as anyone likes a role post, I get the following error saying the event can't be emited due to XRPC not being supported. I'd appreciate any help I can get 👍

file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1047
            throw new Error(`Failed to label record ${"did" in reference ? reference.did : reference.uri}.`, { cause: e });

Error: Failed to label record did:plc:5j665tk4m7ajssszrzxchste.
    at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1047:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:35:13) {
  [cause]: Error: Failed to emit label event.
      at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1081:19
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:35:13) {
    [cause]: XRPCError: XRPCNotSupported > XRPCNotSupported
        at RateLimitedAgent.request (/codepanter/osrslabeler/node_modules/@atcute/client/lib/rpc.ts:174:10)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:35:13) {
      status: 404,
      kind: 'XRPCNotSupported',
      description: 'XRPCNotSupported',
      headers: {
        'access-control-allow-origin': '*',
        'cache-control': 'private',
        'content-length': '57',
        'content-type': 'application/json; charset=utf-8',
        date: 'Sun, 27 Oct 2024 13:56:50 GMT',
        etag: 'W/"39-WI+yvBMnUIXHN9mmjmhFBSzX9h4"',
        'keep-alive': 'timeout=90',
        'ratelimit-limit': '3000',
        'ratelimit-policy': '3000;w=300',
        'ratelimit-remaining': '2993',
        'ratelimit-reset': '1730037690',
        'strict-transport-security': 'max-age=63072000',
        vary: 'Authorization, Accept-Encoding',
        'x-powered-by': 'Express'
      },
      [cause]: undefined
    }
  }
}
futurGH commented 3 weeks ago

You seem to have a catch-all on your labeler domain — see for example https://osrslabeler.pant.re/xrpc/com.atproto.label.queryLabels?uripatterns=* vs. the same route for mod.bsky.app

CodePanter commented 3 weeks ago

You are right, that was an easy fix. I am once again stuck though; the 'XRPCError: InternalServerError > Internal Server Error' isnt telling me much, and I can't quite figure out what "Incorrect prefix for did:key:zQ3shpqC5YncxbXYQRusDfdSqbSgbc1nxGntrirz5K2b1tioy'" means either. My apologies if I'm doing something silly; but your help is very much appreciated!

(node:2947750) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Listening on port 14831
Error: Incorrect prefix for did:key: zQ3shpqC5YncxbXYQRusDfdSqbSgbc1nxGntrirz5K2b1tioy
    at extractMultikey (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:295:15)
    at parseMultikey (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:276:22)
    at parseKeyFromDidDocument (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:168:24)
    at resolveDidToSigningKey (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:38:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async verifyJwt (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:91:24)
    at async LabelerServer.parseAuthHeaderDid (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/LabelerServer.js:175:25)
    at async Object.emitEventHandler (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/LabelerServer.js:299:26)
file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1045
            throw new Error(`Failed to label record ${"did" in reference ? reference.did : reference.uri}.`, { cause: e });
                  ^

Error: Failed to label record did:plc:5j665tk4m7ajssszrzxchste.
    at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1045:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
  [cause]: Error: Failed to emit label event.
      at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1079:19
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
    [cause]: XRPCError: InternalServerError > Internal Server Error
        at RateLimitedAgent.request (/codepanter/osrslabeler/node_modules/@atcute/client/lib/rpc.ts:174:10)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
      status: 500,
      kind: 'InternalServerError',
      description: 'Internal Server Error',
      headers: {
        'access-control-allow-origin': '*',
        'cache-control': 'private',
        'content-length': '65',
        'content-type': 'application/json; charset=utf-8',
        date: 'Sun, 27 Oct 2024 20:58:46 GMT',
        etag: 'W/"41-PDrLQG9BpCN547AVB5jtYl3RBt8"',
        'keep-alive': 'timeout=90',
        'ratelimit-limit': '3000',
        'ratelimit-policy': '3000;w=300',
        'ratelimit-remaining': '2985',
        'ratelimit-reset': '1730062758',
        'strict-transport-security': 'max-age=63072000',
        vary: 'Authorization, Accept-Encoding',
        'x-powered-by': 'Express'
      },
      [cause]: undefined
    }
  }
}
futurGH commented 3 weeks ago

Weird, I'll see if I can reproduce.

CodePanter commented 3 weeks ago

Thank you! I've tried different versions of your package, including the newest beta. You can find the code as my most recent repository on my profile.

mmattbtw commented 3 weeks ago

i'm also getting a similar error:

290 |  * @param did The did:key to extract the key from.
291 |  * @returns A compressed pubkey, without the did:key prefix.
292 |  */
293 | const extractMultikey = (did) => {
294 |     if (!did.startsWith(DID_KEY_PREFIX))
295 |         throw new Error("Incorrect prefix for did:key: " + did);
                    ^
error: Incorrect prefix for did:key: zQ3shNKq7jiZqh5tK29ZkJWc1jWihQuUUwKMeovkHUfW5gRhC
      at extractMultikey (/root/vs-labeler/node_modules/@skyware/labeler/dist/util/crypto.js:295:15)
      at parseMultikey (/root/vs-labeler/node_modules/@skyware/labeler/dist/util/crypto.js:276:22)
      at parseKeyFromDidDocument (/root/vs-labeler/node_modules/@skyware/labeler/dist/util/crypto.js:168:24)
      at /root/vs-labeler/node_modules/@skyware/labeler/dist/util/crypto.js:38:18

1042 |         return this.emitLabelEvent(reference, {
1043 |             createLabelVals: labels,
1044 |             negateLabelVals: [],
1045 |             ...(comment ? { comment } : {}),
1046 |         }, blobCids).catch((e) => {
1047 |             throw new Error(`Failed to label record ${"did" in reference ? reference.did : reference.uri}.`, { cause: e });
                         ^
error: Failed to label record did:plc:i2z6xnjlsjvpnijtfhh5xunc.
      at /root/vs-labeler/node_modules/@skyware/bot/dist/bot/Bot.js:1047:19

1076 |                 subject,
1077 |                 createdBy: this.profile.did,
1078 |                 subjectBlobCids,
1079 |             },
1080 |         }).then((res) => res.data).catch((e) => {
1081 |             throw new Error("Failed to emit label event.", { cause: e });
                         ^
error: Failed to emit label event.
 cause: {
  "name": "XRPCError",
  "status": 502,
  "kind": "InternalServerError",
  "description": "An unknown error occurred",
  "headers": {
    "access-control-allow-origin": "*",
    "cache-control": "private",
    "content-length": "69",
    "content-type": "application/json; charset=utf-8",
    "date": "Wed, 30 Oct 2024 20:47:45 GMT",
    "etag": "W/\"45-2pyG22qpiEeLQh9p+Y+C+g11QWM\"",
    "keep-alive": "timeout=90",
    "ratelimit-limit": "3000",
    "ratelimit-policy": "3000;w=300",
    "ratelimit-remaining": "2995",
    "ratelimit-reset": "1730321554",
    "strict-transport-security": "max-age=63072000",
    "vary": "Authorization, Accept-Encoding",
    "x-powered-by": "Express"
  }
}

      at /root/vs-labeler/node_modules/@skyware/bot/dist/bot/Bot.js:1081:19
futurGH commented 3 weeks ago

Fixed in 0.1.12!

CodePanter commented 3 weeks ago

Thank you! The incorrect prefix error is indeed fixed now, however now I get a 'invalid curve for multikey' error:


Error: Invalid curve for multikey: zQ3shpqC5YncxbXYQRusDfdSqbSgbc1nxGntrirz5K2b1tioy
    at parseDidMultikey (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:283:15)
    at parseKeyFromDidDocument (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:167:24)
    at resolveDidToSigningKey (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:38:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async verifyJwt (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/util/crypto.js:91:24)
    at async LabelerServer.parseAuthHeaderDid (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/LabelerServer.js:175:25)
    at async Object.emitEventHandler (file:///codepanter/osrslabeler/node_modules/@skyware/labeler/dist/LabelerServer.js:299:26)
file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1045
            throw new Error(`Failed to label record ${"did" in reference ? reference.did : reference.uri}.`, { cause: e });
                  ^

Error: Failed to label record did:plc:5j665tk4m7ajssszrzxchste.
    at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1045:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
  [cause]: Error: Failed to emit label event.
      at file:///codepanter/osrslabeler/node_modules/@skyware/bot/dist/bot/Bot.js:1079:19
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
    [cause]: XRPCError: InternalServerError > An unknown error occurred
        at RateLimitedAgent.request (/codepanter/osrslabeler/node_modules/@atcute/client/lib/rpc.ts:174:10)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at Bot.<anonymous> (/codepanter/osrslabeler/src/labeler.ts:34:13) {
      status: 502,
      kind: 'InternalServerError',
      description: 'An unknown error occurred',
      headers: {
        'access-control-allow-origin': '*',
        'cache-control': 'private',
        'content-length': '69',
        'content-type': 'application/json; charset=utf-8',
        date: 'Thu, 31 Oct 2024 15:20:47 GMT',
        etag: 'W/"45-2pyG22qpiEeLQh9p+Y+C+g11QWM"',
        'keep-alive': 'timeout=90',
        'ratelimit-limit': '3000',
        'ratelimit-policy': '3000;w=300',
        'ratelimit-remaining': '2988',
        'ratelimit-reset': '1730388246',
        'strict-transport-security': 'max-age=63072000',
        vary: 'Authorization, Accept-Encoding',
        'x-powered-by': 'Express'
      },
      [cause]: undefined
    }
  }
}
futurGH commented 3 weeks ago

Whoops, sorry about that! Fixed for real this time in 0.1.13.

CodePanter commented 3 weeks ago

I was in the middle of debugging this. I had gotten as far as spotting this typo, but I was nowhere near fixing everything else! https://github.com/skyware-js/labeler/blob/a9ce6c9855dcde242a690e1756d52fe1ce0643d0/src/util/crypto.ts#L316