1.0.11 • Published 10 months ago

custody-wallet-common v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Custody Wallet Common 모듈

  • Common Database(Entity)
    • network
    • asset
  • JWT
  • OTP
  • Logging

설치

npm install custody-wallet-common

모듈 구성

  1. JWT 모듈

    • JWT 토큰 생성, 검증, 추출 기능 제공
    • JwtService를 통한 토큰 관리
  2. OTP 모듈

    • 일회용 비밀번호 생성 및 검증
    • OTP 인증 URL 생성
    • OtpService를 통한 OTP 관리
  3. Loggin 모듈

    -

JWT 모듈

사용법

import { JwtModule } from 'custody-wallet-common';

@Module({
  imports: [
    JwtModule.forRoot({
      secret: 'your-secret-key',
      signOptions: { expiresIn: '1h' },
    }),
    // 또는 비동기 구성을 위해
    JwtModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get('JWT_SECRET'),
        signOptions: { expiresIn: configService.get('JWT_EXPIRES_IN') },
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

서비스에서 JwtService를 주입 후 사용:

constructor(private jwtService: JwtService) {}

async someMethod() {
  const token = await this.jwtService.generateToken({ userId: 1 });
  const payload = await this.jwtService.verifyToken(token);
}

OTP 모듈

OTP 모듈은 일회용 비밀번호 생성 및 검증, OTP 인증 URL 생성 기능을 제공합니다.

사용법

import { OtpModule } from 'custody-wallet-common';

@Module({
  imports: [
    OtpModule.forRoot({
      issuer: '귀하의 회사',
      appName: '귀하의 앱',
    }),
    // 또는 비동기 구성을 위해
    OtpModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        issuer: configService.get('OTP_ISSUER'),
        appName: configService.get('OTP_APP_NAME'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

서비스에서 OtpService를 주입 후 사용:

constructor(private otpService: OtpService) {}

async setupOtp(email: string) {
  const { secret, otpAuthUrl } = this.otpService.setupOtp(email);
  // secret을 안전하게 저장하고 otpAuthUrl을 클라이언트에 반환
}

verifyOtp(token: string, secret: string) {
  return this.otpService.verifyToken(token, secret);
}

API 참조

JwtService

  • generateToken(payload: Buffer | object): Promise<string>
    • JWT 토큰을 생성합니다.
  • verifyToken(token: string): Promise<JwtPayload>
    • JWT 토큰을 검증하고 페이로드를 반환합니다.
  • extractToken(request: Request): string | undefined
    • 요청 헤더에서 JWT 토큰을 추출합니다.

OtpService

  • generateSecret(): string
    • OTP 비밀키를 생성합니다.
  • generateToken(secret: string): string
    • OTP 토큰을 생성합니다.
  • verifyToken(token: string, secret: string): boolean
    • OTP 토큰을 검증합니다.
  • generateOtpAuthUrl(email: string, secret: string): string
    • OTP 인증 URL을 생성합니다.
  • setupOtp(email: string): { secret: string; otpAuthUrl: string }
    • OTP 설정에 필요한 비밀키와 인증 URL을 생성합니다.
1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago