Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not implemented: crypto.generateKeyPairSync error with mineflayer #17849

Closed
link-discord opened this issue Nov 16, 2022 · 2 comments
Closed

Not implemented: crypto.generateKeyPairSync error with mineflayer #17849

link-discord opened this issue Nov 16, 2022 · 2 comments
Labels
bug Something isn't working correctly node compat

Comments

@link-discord
Copy link

Describe the bug

Using mineflayer from npm causes a "not implemented" error with the crypto module from the node compatibility layer

Steps to Reproduce

Running the code in this index.ts file

import mineflayer from 'npm:mineflayer'

const bot = mineflayer.createBot({
    username: 'use any value here',
    host: 'localhost',
    auth: 'microsoft'
})

bot.on('login', () => {
    console.log('Succesfully logged in!')
})

Results in this error

% deno run --allow-all index.ts
Error: Not implemented: crypto.generateKeyPairSync
    at notImplemented (https://deno.land/std@0.164.0/node/_utils.ts:23:9)
    at Object.generateKeyPairSync (https://deno.land/std@0.164.0/node/internal/crypto/keygen.ts:662:3)
    at MicrosoftAuthFlow.initTokenManagers (file:///C:/Users/Link/AppData/Local/deno/npm/registry.npmjs.org/prismarine-auth/1.7.0/src/MicrosoftAuthFlow.js:66:28)
    at new MicrosoftAuthFlow (file:///C:/Users/Link/AppData/Local/deno/npm/registry.npmjs.org/prismarine-auth/1.7.0/src/MicrosoftAuthFlow.js:33:10)
    at Object.authenticate (file:///C:/Users/Link/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.36.1/src/client/microsoftAuth.js:16:20)
    at Object.createClient (file:///C:/Users/Link/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.36.1/src/createClient.js:46:23)
    at Object.createBot (file:///C:/Users/Link/AppData/Local/deno/npm/registry.npmjs.org/mineflayer/4.5.1/lib/loader.js:94:35)
    at file:///C:/Users/Link/OneDrive/Documents/minecraft/bots/deno/index.ts:3:12

Cause of this bug is this line that is used inside a dependency of the package

const keyPair = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' })

The error triggers when the createBot method has this option

auth: 'microsoft'

Expected behavior

% node index.ts
Succesfully logged in!

Environment

  • OS: Windows 11
  • deno version: 1.28.0
  • std version: 0.164.0
@link-discord link-discord added bug Something isn't working correctly needs triage labels Nov 16, 2022
@kt3k kt3k removed the needs triage label Dec 22, 2022
@kt3k kt3k mentioned this issue Feb 21, 2023
14 tasks
@ghost
Copy link

ghost commented Feb 7, 2023

It returns a promise but it seems like we can use 'crypto.subtle.generateKey' here from crypto/crypto.ts.

The resulting type needed for this non implemented function and the result type from crypto.subtle.generateKey are as follows.

export interface KeyPairKeyObjectResult {
  publicKey: KeyObject;
  privateKey: KeyObject;
}

export interface KeyPairSyncResult<
  T1 extends string | Buffer,
  T2 extends string | Buffer,
> {
  publicKey: T1;
  privateKey: T2;
}
interface CryptoKeyPair {
  privateKey: CryptoKey;
  publicKey: CryptoKey;
}

@kt3k kt3k transferred this issue from denoland/std Feb 21, 2023
@littledivy
Copy link
Member

We're tracking all missing APIs from node:crypto in #18455. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

4 participants